When Base
is added to the following code, why does the OCaml compiler expect h
and w
to be int
s? tup
is supposed to be a tuple - is there a syntactic issue? What is it about Base that causes this error?
open Base
let () =
let tup = ("hello", "world") in
let h, w = tup in
if h = w then print_endline "equal" else print_endline "not equal"
Error:
91 | if h = w then print_endline "equal" else print_endline "not equal"
^
Error: This expression has type string but an expression was expected of type
int
Base
, along other Janestreet libraries, discourages polymorphic comparison function and hide compare
, (=)
and other operators, with their monomorphic equivalents. More or less arbitrary they chose functions that compare integers (following the SML tradition).
You still can get your polymorphic comparison functions, using
open Poly
or, locally,
let true = Poly.((1,2) = (1,2))