Working from utop. What is going on here?!
#(1>2);;
- : bool = false
#require "re2";;
open Re2;;
(1>2);;
Error: This expression has type int but an expression was expected of type t
Working from utop. What is going on here?!
#(1>2);;
- : bool = false
#require "re2";;
open Re2;;
(1>2);;
Error: This expression has type int but an expression was expected of type t
The Re2
module redefines the (>)
operator as Re2.t -> Re2.t -> bool
. You probably want to avoid opening globally this module.
Thank you, that’s useful to know. As a beginner these random things are so off putting. I’m staring at the terminal wondering why 1 > 2 doesn’t return false … Ahh that’s because a regular expression package has overridden the > operator? Meanwhile, the compiler is telling me not to use stdin from Base in favour off something from a third party package. I just don’t know what to make of that.
The Base
library also override the >
operator. In general, Base
is not really a library that you can use without reading its documentation. In particular, it replaces several OCaml idioms by advanced versions that work better at Janestreet scale but are harder to understand for a beginner.
Like most learners it seems I’m just following along in the “Real World Ocaml” which includes open Base at the top of everything. Seems like one has to know an awful lot just to make sense of 1>2.
Real World OCaml is rather JaneStreet World OCaml. If you are interested in learning the OCaml system other texts are more suitable like:
Thank you that’s very useful. I’ll switch to these instead.
Note that if at some point you want to understand more about the implementation of the OCaml runtime system chapter 22 and 23 of Real World OCaml are worth perusing. They offer a good update to the corresponding chapter of the old oreilly book.
Just fyi, in OCaml you usually have to be very circumspect about opening modules as they can contain things that potentially override your current scope in confusing ways, as you found out. That’s why we have two different ways of locally opening modules. Globally opening modules should be carefully thought out and should not be done without understanding the consequences.