0

I am trying this simple code to split a string to a list by a separator:

open String;;
let ss = "/usr/bin/ocaml";;
let sslist = String.split_on_char '/' ss  in
    print_endline sslist;;

It is giving error:

$ ocaml testing.ml

File "testing.ml", line 5, characters 13-33:
Error: Unbound value String.split_on_char

I am sure it is something very basic but I am not able to solve it. Removing open String or using #require "string" also does not work.

Where is the problem and how can it be solved? Thanks for your help.

rnso
  • 23,686
  • 25
  • 112
  • 234
  • What does `ocaml -version` say? `String.split_on_char` is only available since 4.04.0, as per the docs. – glennsl May 05 '19 at 14:13
  • My version is `The OCaml toplevel, version 4.02.3`. So that explains. How can I split a string in my version? – rnso May 05 '19 at 14:22
  • You could use `Str.split`, or something in a stdlib replacement like Base/Core, I'm sure. But you really should upgrade. 4.02.3 is pretty old, we'll soon be on 4.08 now. – glennsl May 05 '19 at 14:30
  • I have installed from Debian Stable repositories. – rnso May 05 '19 at 14:50
  • I would recommend using opam instead to manage both your ocaml installations and third-party packages. [It's also available in the Debian repos](https://opam.ocaml.org/doc/Install.html). – glennsl May 05 '19 at 15:02

1 Answers1

1

String.split_on_char is only available since 4.04.0, as per the docs.

You really should upgrade, but in case you can't, refer to this question for alternatives.

glennsl
  • 28,186
  • 12
  • 57
  • 75