我在 base 以及 f 和 l 函数中遇到了几个错误,我错了什么?
该函数应该做什么的例子是。
# sepConcat ", " ["foo";"bar";"baz"];;
- : string = "foo, bar, baz"
# sepConcat "---" [];;
- : string = ""
# sepConcat "" ["a";"b";"c";"d";"e"];;
- : string = "abcde"
# sepConcat "X" ["hello"];;
- : string = "hello"
老师给了我这个我应该填写的代码。
let rec sepConcat sep s1 = match s1 with
|[] -> ""
|h::t ->
let f a x = failwith "to be implemented" in
let base = failwith "to be implemented" in
let l = failwith "to be implemented" in
List.fold_left f base l
我到目前为止
let rec sepConcat sep s1 = match s1 with
|[] -> ""
|h::t ->
let f a x = a^sep^x in
let base = 0 in
let l = sepConcat sep t in
List.fold_left f base l