我得到一些錯誤的基地和f和l函數,我錯了什麼錯誤?OCaml concat stringlist使用List.fold_left
函數應該做的例子是。
# 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
我正在編譯我試過「」,0和空格,但沒有任何東西可以解決它。 –
PSA:在考試期間手邊不會有stackoverflow :) –