[SOLVED] Question About OCaml Function Signatures in UTop


This Content is from Stack Overflow. Question asked by Ian Brons

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?


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.

This Question was asked in StackOverflow by Ian Brons and Answered by Jeffrey Scofield It is licensed under the terms of CC BY-SA 2.5. - CC BY-SA 3.0. - CC BY-SA 4.0.

people found this article helpful. What about you?