Jane Street Base changes the semantics of String.concat on my MacOS system

Hello,

I am trying to learn OCaml and I have installed the binary OCaml-5.3.0 distribution on my MacOS where “uname -a” gives

Darwin Kernel Version 20.6.0: Thu Sep 29 20:15:11 PDT 2022; root:xnu-7195.141.42~1/RELEASE_X86_64

I have also installed Jane Street’s Core library using “opam”.
When I try to compile and run this program (“dune exec bad”)

open Base
let lines = ["aa"; "bb"; "cc"]
let text = String.concat "\n" lines;;
print_endline text

with the following Dune file

(executable
 (public_name bad)
 (name main)
 (libraries base))

then I get the error message

File "bin/main.ml", line 3, characters 30-35:
3 | let text = String.concat "\n" lines;;
                                  ^^^^^
Error: The function applied to this argument has type ?sep:string -> string/2
This argument cannot be applied without label

“dune exec bad” succeeds after changing “open Base” to “(* open Base *)”

Trying to change lines into an array of strings and using Jane Street’s String.concat_array leads to a similar error message.

Thanks

Well if you open Base in your code then your String module is Base.String instead of Stdlib.String and the signature of Base.String.concat is different from Stdlib.String.concat.

Jane street libraries make heavy use of labeled arguments: Labelled and Optional Arguments · OCaml Documentation

So the API isn’t exactly the same when comparing to the “pervasive” standard library.

Basically just add a tilde in front of your list variable :slight_smile:

When I add a tile in front of the “lines” list variable, I get

File "bin/main.ml", line 3, characters 31-36:
3 | let text = String.concat "\n" ~lines;;
                                   ^^^^^
Error: The function applied to this argument has type ?sep:string -> string/2
This argument cannot be applied with label ~lines

He mixed up, he meant in front of the separator:

let text = String.concat ~sep:"\n" lines 
1 Like

Thanks a lot, it works now after adding “open Stdio” to ensure the use of Jane Street’s version of “print_endline”.