Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regular Expressions in OCaml

Tags:

I want to use regexps in OCaml and it seems that Str module provides these functionalities.

So I tried with a simple program:

open Str let regx = regexp "." 

but it gives me the following error

File "lol.ml", line 1, characters 0-1: Error: Error while linking lol.cmo: Reference to undefined global `Str'

As if module is not present but if I remove open Str it says that regexp is an unbound value.

I don't get what kind of issue it is, Str should be a standard module (according to http://caml.inria.fr/pub/docs/old-311/libref/Str.html) so I'm clueless.. the only think I thought is that signature (mli) is present but implementation (ml) is not.

I'm running Objective Caml version 3.11.0 according to ocaml tool.

Can anyone help me figuring this out? Thanks in advance

like image 320
Jack Avatar asked Jul 10 '10 22:07

Jack


2 Answers

From the manual:

Programs that use the str library must be linked as follows:

ocamlc other options str.cma other files ocamlopt other options str.cmxa other files 
like image 84
sepp2k Avatar answered Oct 11 '22 12:10

sepp2k


Or you can put

#load "str.cma";; 

if you are doing it in the interpreter

like image 37
newacct Avatar answered Oct 11 '22 14:10

newacct