Question About OCaml Function Signatures in UTop

Viewed 23

I am trying to import the following OCaml code in to utop:

let rec insert (x : 'a) (l : 'a list) : 'a list =   
    match l with 
    | [] -> [ x ] 
    | hd :: tl ->
            if x = hd then l
            else if is_sorted (x :: l) then x :: l
            else hd :: insert x tl

When I import it though its signature is

val insert : int -> int list -> int list = <fun>

I am confused why its signature is in terms of int rather than 'a. Could someone explain to me why this is?

1 Answers

Most likely you are using Jane Street modules. They redefine polymorphic comparisons to work on int, because polymorphic comparisons have a few tricky spots that tend to trip up beginning OCaml programmers.

I have trouble navigating Jane Street documentation, but I believe there is a Polymorphic_compare module where you can find the built-in polymorphic comparison operators of OCaml.

Related