The Base Module and Polymorphic Functions

As @mc10 said, this is due to Base redefining (=) to hide the standard (=) function.

Here is what you can do:

  1. Do not actually open Base. This way you keep the standard polymorphic operator. Note that there are reasons to not do that, as mentioned in the discussion @mc10 linked. If you want to call functions from Base without opening it, you can use their qualified names; for instance Base.List.map.

  2. If you do open Base, you can still refer to the polymorphic operator as Poly.(=) (and there is also Poly.equal). So for instance in your function you could have : if Poly.equal x y then ...
    Or: if Poly.(x = y) then ... (this is called a local open)

  3. One way to not use polymorphic comparison at all is to parametrise your code over the equality function. The simplest way to go about it is to have any function that has to be polymorphic and do equality tests take the equality function as an argument. For instance your function becomes :

let rec delDuplicates equal = function
   ...
       if equal x y then ...

Then your function has type:

val delDuplicates : ('a -> 'a -> bool) -> 'a list -> 'a list

And you call it as:

delDuplicates Int.equal [1; 1; 1; 2; 3; 3]
1 Like