# Monomorphic comparison operator of Janestreet Base library

**URL:** https://discuss.ocaml.org/t/monomorphic-comparison-operator-of-janestreet-base-library/1585
**Category:** Learning
**Tags:** base
**Created:** [February 17, 2018, 1:49pm UTC](https://discuss.ocaml.org/t/monomorphic-comparison-operator-of-janestreet-base-library/1585 "2018-02-17T13:49:44Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![cwyang](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/cwyang/32/831_2.png) [@cwyang](https://discuss.ocaml.org/u/cwyang)
#### Post date: [February 17, 2018, 1:49pm UTC](https://discuss.ocaml.org/t/monomorphic-comparison-operator-of-janestreet-base-library/1585/1 "2018-02-17T13:49:44Z")

</div>

Hi, all.

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](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
```

---

<div class="post-metadata">

### Author: ![Yaron\_Minsky](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/yaron_minsky/32/11_2.png) [@Yaron\_Minsky](https://discuss.ocaml.org/u/Yaron_Minsky)
#### Post date: [February 17, 2018, 2:07pm UTC](https://discuss.ocaml.org/t/monomorphic-comparison-operator-of-janestreet-base-library/1585/2 "2018-02-17T14:07:14Z")

</div>

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:

```ocaml
open Base
open Poly

let bigger_float = max 1.1 1.0
let bigger_int = max 1 2

```

Or, you can just use it in a small context:

```ocaml
open Base

let bigger_float = Poly.(max 3.3 4.5)

```

---

<div class="post-metadata">

### Author: ![cwyang](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/cwyang/32/831_2.png) [@cwyang](https://discuss.ocaml.org/u/cwyang)
#### Post date: [February 17, 2018, 2:34pm UTC](https://discuss.ocaml.org/t/monomorphic-comparison-operator-of-janestreet-base-library/1585/3 "2018-02-17T14:34:32Z")

</div>

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
```
