Sml 错误:字符串列表而不是字符串列表

Sml 错误:字符串列表而不是字符串列表,sml,Sml,我有一个生成字符串列表的函数: fun get_substitutions1 ([],_) = [] | get_substitutions1 (x::xs,s) = case all_except_option(s,x) of NONE => [] @get_substitutions1(xs,s) | SOME lst => lst @get_substitutions1(xs,s) 此函数接受字符串列表和类型: fun similar_names(sli

我有一个生成字符串列表的函数:

fun get_substitutions1 ([],_) = []
| get_substitutions1 (x::xs,s) = case all_except_option(s,x) of
    NONE     => []  @get_substitutions1(xs,s)
  | SOME lst => lst @get_substitutions1(xs,s)
此函数接受字符串列表和类型:

fun similar_names(slist,full_name:{first:string,middle:string,last:string})=
let
fun aux(slist,acc)=
case full_name of
{first=a,middle=b,last=c} => case get_substitutions1(slist,a) of
[] => full_name::acc
| x::xs'  => full_name::  aux(xs',{first=x,middle=b,last=c}::acc)

in aux(slist,[])
end
我得到一个错误:

Error: operator and operand don't agree. operator domain: string list list * {first:string, last:string, middle:string} list operand: string list * {first:string, last:string, middle:string} list in expression: aux (xs',{first=x,middle=b,last=c} :: acc)
还有其他方法吗?

首先,您可能不想缩进代码以使其可读

很明显,你为什么会犯这样的错误。功能

fun get_substitutions1 ([],_) = []
  | get_substitutions1 (x::xs,s) =
    case all_except_option(s,x) of
      NONE => []@get_substitutions1(xs,s)
    | SOME lst => lst @get_substitutions1(xs,s)
有那种

val get_substitutions1 = fn : ''a list list * ''a -> ''a list
您正试图在内部case表达式中使用此函数的结果,其中获取返回的列表类型“a list”的尾部,并在递归函数调用中使用它们

fun similar_names(slist,full_name:{first:string,middle:string,last:string})=
    let
      fun aux(slist,acc)=
          case full_name of
            {first=a,middle=b,last=c} =>
            case get_substitutions1(slist,a) of
              [] => full_name::acc
            | x::xs'  => full_name::  aux(xs',{first=x,middle=b,last=c}::acc)
    in aux(slist,[])
    end

但是,由于aux的第一个参数用于get_substitutions1,因此该参数必须为“列表”类型,但递归调用中使用的xs“仅为”列表类型。

首先,您可能不想缩进代码以使其可读

很明显,你为什么会犯这样的错误。功能

fun get_substitutions1 ([],_) = []
  | get_substitutions1 (x::xs,s) =
    case all_except_option(s,x) of
      NONE => []@get_substitutions1(xs,s)
    | SOME lst => lst @get_substitutions1(xs,s)
有那种

val get_substitutions1 = fn : ''a list list * ''a -> ''a list
您正试图在内部case表达式中使用此函数的结果,其中获取返回的列表类型“a list”的尾部,并在递归函数调用中使用它们

fun similar_names(slist,full_name:{first:string,middle:string,last:string})=
    let
      fun aux(slist,acc)=
          case full_name of
            {first=a,middle=b,last=c} =>
            case get_substitutions1(slist,a) of
              [] => full_name::acc
            | x::xs'  => full_name::  aux(xs',{first=x,middle=b,last=c}::acc)
    in aux(slist,[])
    end

但是,由于aux的第一个参数用于get_substitutions1,因此该参数必须是“列表”类型,但是在递归调用中使用的xs只属于“列表”类型。

我知道get_substitution1将结果转换为字符串列表。但是我的helper函数使用字符串列表。我很困惑,因为我想要递归和字符串列表结果。你能帮我吗?如果你知道,为什么你还没有修复它?也许你应该把你的问题再说清楚一点,至于你到底不明白什么,我唯一能说的是,你似乎用了错误的方式使用了get_替换的输入或结果1。我找不到另一种方式来做我想做的事。我认为我的逻辑是正确的,但我正在失去一些东西。至少,这是显而易见的吗?我知道get_substitution1结果是字符串列表。但是我的helper函数接受字符串列表。我很困惑,因为我想用字符串列表结果进行递归。你能帮我吗?如果你知道,那你为什么不修复它?也许你应该把你的问题再说清楚一点,至于你到底不明白什么,我唯一能说的是,你似乎用了错误的方式使用了get_替换1的输入或结果。我找不到另一种方式来做我想做的事。我认为我的逻辑是正确的,但我正在失去一些东西。至少,这是显而易见的吗?