【发布时间】:2020-06-25 22:34:36
【问题描述】:
我正在创建一个反转列表的函数。 我认为一切都很好,但编译器的意见不一样...... 这是代码:
let reverse list_ =
let rec support list_ =
match list_ with
| [] -> []
| hd :: tl -> support tl :: hd in
let return = support list_ in return
错误是:
| hd :: tl -> support tl :: hd in
Error: This expression has type 'a list
but an expression was expected of type 'a
The type variable 'a occurs inside 'a list`
我的想法是到达列表的末尾,而不是从[] 构建一个新列表,添加最新的元素。
【问题讨论】:
标签: functional-programming ocaml