With Core and Core_kernel, I get : a -> a -> bool for comparison operators.
But with Base, comparison operators gets type int -> int -> bool.
Is this intended behavior?
And if it is intended behaviour, where can I find out that operator definition from https://ocaml.janestreet.com/ocaml-core/v0.9/doc/base/Base/index.html?
Any help will be appreciated deeply.
Chul-Woong
# open Base;;
# 1.1 = 1.1;;
Characters 0-3:
1.1 = 1.1;;
^^^
Error: This expression has type float but an expression was expected of type
int
# #show_module Base;;
...
val ( = ) : int -> int -> bool
val ( < ) : int -> int -> bool
val ( <= ) : int -> int -> bool
val ( <> ) : int -> int -> bool
val ( = ) : int -> int -> bool
val ( > ) : int -> int -> bool
val ( >= ) : int -> int -> bool
It’s intentional; polymorphic compare is shadowed by integer comparison by default in Base. That’s because polymorphic compare, while useful, is error prone, and we think its use should be discouraged. It’s a bigger swing to hide it everywhere in Core, which is used directly in many more places than Base, but I suspect we’ll do that eventually.
You can restore polymorphic comparison if you want to:
open Base
open Poly
let bigger_float = max 1.1 1.0
let bigger_int = max 1 2
Thank you for kind answer.
So, in Base and in general, should we use not =, but compare_char to match character in casual situation? Do you recommend myFind over myFind2?
open Base
let rec myFind (s : char list) c = match s with
| [] -> Error "Not Found"
| c1 :: tl -> if compare_char c1 c = 0 then Ok c
else myFind tl c
let rec myFind2 s c = match s with
| [] -> Error "Not Found"
| c1 :: tl -> if c1 = c then Ok c
else myFind2 tl c