私が現在持っているコードは、stringOfList関数をテストしている場所です
let rec sepConcat sep sl = match sl with
| [] -> ""
| h :: t ->
let f a x = a^sep^x in
let base = h in
let l = t in
List.fold_left f base l
let stringOfList f l = sepConcat "; " (List.map f l)
私が得るはずの出力は
# stringOfList string_of_int [1;2;3;4;5;6];;
- : string = "[1; 2; 3; 4; 5; 6]"
しかし、私は得ています
# stringOfList string_of_int [1;2;3;4;5;6];;
- : string = "1; 2; 3; 4; 5; 6"
私は何を間違っていますか?括弧内に余分な [] を追加するにはどうすればよいですか。Sepconcatはこれを行うことになっています
# sepConcat ", " ["foo";"bar";"baz"];;
- : string = "foo, bar, baz"
# sepConcat "---" [];;
- : string = ""
# sepConcat "" ["a";"b";"c";"d";"e"];;
- : string = "abcde"
# sepConcat "X" ["hello"];;
- : string = "hello"