【发布时间】:2018-11-09 19:42:45
【问题描述】:
我正在尝试在 OCaml 中编写 shuffle 函数,但是类型推断存在问题。 Merlin 告诉我l1 和l2 的类型是'a list list,这不是真的,因为它们只是'a list。为什么这么说?
let shuffle l1 l2 =
let rec scan l1 l2 acc =
match (l1, l2) with
| [],[] -> acc
| ([],h2::t2) -> scan [] t2 h2::acc
| (h1::t1, []) -> scan t1 [] h1::acc
| (h1::t1,h2::t2) -> scan t1 t2 h1::h2::acc
in scan l1 l2 []
;;
【问题讨论】:
标签: compiler-errors ocaml type-inference operator-precedence