类型不匹配时出错

时间:2013-02-01 15:55:02

标签: functional-programming pattern-matching sml ml

我在SML上写这个函数。它应该列出可能的名字变体(我的名字是Victoria,所以V,Vic,Vicky等)并创建{altname1,middle,last},{alt2,middle,last}的记录。

所以这是我的代码:

fun similar_names (substits:, name) = 
    let 
    val {first=n1, second=n2, third=n3} = name
    fun name_constructor (altnames:string list, acc) =
        case altnames of 
        [] => acc
         |  a::aa  => {first=a, second=n2, third=n3}::acc
    in 
    name_constructor( get_substitutions2(substits, n1),name)

    end

get_substitutions2将只列出一个名字的所有可能变体(即:字符串列表),并且它可以正常工作。

我得到的错误是:

a02.sml:65.2-65.58 Error: operator and operand don't agree [tycon mismatch]
  operator domain: string list * {first:string, second:'Z, third:'Y} list
  operand:         string list * {first:string, second:'Z, third:'Y}
  in expression:
    name_constructor (get_substitutions2 (substits,n1),name)

我不明白为什么它会单独记录在记录列表和记录之间。你能帮忙吗?

1 个答案:

答案 0 :(得分:5)

name只是一条记录,但name_constructor期望acc成为一个列表(因为您说::acc)。
尝试

name_constructor(get_substitutions2(substits, n1), [name])
相关问题