【发布时间】:2019-03-27 06:09:41
【问题描述】:
我有一个问题,OCaml 认为我函数的a 和s 参数是unit lists,但它们必须分别是'a list 和string。该函数必须输出由给定分隔符分隔的列表元素。
结果必须是一个字符串,输入如下:“This-is-label”
附:我知道match,但我不能用它
let rec function1 a s =
if a = [] then failwith "Empty list" else
if List.tl a = [] then List.hd a else
if List.tl a != [] then List.hd a; s; function1 List.tl a s
;;
function1 ["This"; "is"; "label"] "-";;
【问题讨论】:
-
我建议你试试pattern matching。
-
ocaml 如何从中获得
unit list?我预计会出现This expression has type 'a list -> 'a list but an expression was expected of type 'b list的错误。是不是因为;期望第一个表达式返回单位?