某些([])被解释为' z - > ' z选项而不是' z列表选项

时间:2014-10-27 22:42:07

标签: smlnj

您好我正在尝试使用标准库编写一个简单的函数

它应该采用以下参数

try = fn: 'a -> 'b list option
a_list = 'a list

,定义如下:

fun all_answers try a_list = 
  let fun acc(SOME(a), SOME(b)) = SOME(b@a)
        | acc(_,_)              = NONE
  in
    List.foldl (fn(x,y) => acc(try(x), y)) SOME([]) a_list
  end

我收到以下错误:

hw3provided.sml:70.3-70.60 Error: operator and operand don't agree [tycon mismatch]
  operator domain: 'Z list option
  operand:         'Y -> 'Y option
  in expression:
    (List.foldl (fn (<pat>,<pat>) => acc <exp>)) SOME
C:\Program Files (x86)\SMLNJ\\bin\.run\run.x86-win32.exe: Fatal error -- Uncaught exception Error         with 0
 raised at ../compiler/TopLevel/interact/evalloop.sml:66.19-66.27

我已经尝试过分解函数,错误似乎对应于SOME([])的使用,如果我使用NONE而不是完美地检查它

我在这里完全失去了

只是使用sublime repl来运行脚本

1 个答案:

答案 0 :(得分:0)

找出解决方案但不是真正的问题

用括号(SOME([]))

包围SOME([])

以防万一其他人遇到同样的问题