Search code examples
ocaml

OCaml analogue to Python's String join method


Given a list of string elements in Python, I can concatenate these elements with specified glue. For example:

' '.join(["phd", "in", "everything"])

evaluates to the string "phd in everything".

What analogue in OCaml is considered most idiomatic? That is, how may string elements of a list be joined with some specified string in OCaml?


Solution

  • The equivalent in Ocaml is :

    #String.concat " " ["phd"; "in"; "everything"]
    

    There is no restriction vs the length of the list.