Standard library "Str"

Hi guys !

I’m trying to resolve the “Temperatures” problem and I’d like to split the given string into a list, using the SPACE delimiter. So in Ocaml, I was thinking of something like that:

let l = Str.split (Str.regexp " ") temps

But when compiling that, I get the following error:

File “/tmp/”, line 1:
Error: Error while linking /tmp/Answer.cmo:
Reference to undefined global `Str’

Obviously, I can’t write ‘Open Str’ at the beginning neither. Does this means I can’t use the Str library ?

Thanks for reading :slight_smile:



isn’t that String??

String reference

I don’t see a “split” function in the String library whereas I know for sure that it exists in Str.

I was hoping to be able to use all the standard functions from here:

Ask @SaiksyApo via PM

I don’t know Ocaml, but it’s seems Str is an additional library so it’s not supported.

Sorry to join this conversation a bit late, but i’d like to react to the last message:
the Str module is from OCaml standard library.
that means that it’s bundled with any standard ocaml installation, and is automatically linked by the compiler.

to sum it up, Str is no more an additional library than List or String (which, on their side, are corretly supported)

@SaiksyApo Ocaml has a three tiered classification for libraries shipping with the compiler.
The ocaml core and standard libraries are linked by default.
The compiler also comes with extension libraries : num, str, threads, graphics, dynlink, bigarray. While they are part of the standard distribution, you have to pass a flag to the compiler to use them. While they are not sensu stricto part of the standard library, ocaml programmers tend to expect them to be here.

Would the team be open to adding at least srt and num ?
str contains operations on strings and regular expressions and num contains arbitrary precision numbers.
While I don’t think they are required, they bring nicer performance than ad hock solutions as parts of both are actually written in C.


I really would like to solve examples in OCaml as well in another languages I study. But it looks too hard to use local ocaml environment. Please, add Str library! And it would be really nice if you add Core.Std library, since it’ll make my codingame experience more joyful!


Seems no update to this have occurred after so many months since raising the issue. Sad.

I’d also like to see the Str module included by default, there is no way currently (as far as I know) to use regular expressions in OCaml.

1 Like

@rniboucha @shtartora you could use bash to compile the OCaml code with the Str module, so it’s not totally impossible.

And furthermore with this trick you can also execute the native code instead of the bytcode used by CodinGame.

For instance, this code works on the CG IDE:

#/usr/bin/env bash
set -e && cat > <<EOF # just a simple test
let str = "test" in
let _a = Str.string_match (Str.regexp ".est") str 0 in
print_endline @@ Str.matched_string str

ocamlopt str.cmxa -o native && ./native
exit 0

I feel the same need for Str module

I feel the same need family for “simply knowing what libs are available”. If Haskell’s got the platform, I’d expect there to be Batteries and/or Core, but it doesn’t appear so.

Or at least some kind of “policy” as to what’s welcome in which language. The current disparities are mind-boggling.

Use ocamlfind(1) instead of ocamlc(1) and ocamlopt(1).

ocamlfind ocamlc -verbose -o pgm.byte -package str


ocamlfind ocamlopt -verbose -o pgm.native -package str

How to use ocamlfind(1) from the source

Reminder that this module is in the standard library but needs to be opted in when compiling and would be really useful for some codingame problems.