I am trying to sort a list (i.e 'a') in Ocaml but I cannot. I concretely use the built-in function sort (https://caml.inria.fr/pub/docs/manual-ocaml/libref/List.html) and the used variable is of the type 'int list', so there should not be any problem with the 'compare module' that the function uses inside.
My example:
When trying:
sort a
The thrown error is:
This expression has type int list but an expression was expected of type 'a -> 'a -> int
Other attempts:
When trying:
sort [1]
The thrown error is:
This expression has type 'a List.t = 'a list but an expression was expected of type 'b -> 'b
-> int List.t is abstract because no corresponding cmi file was found in path.
I do not understand what happens.
Thanks in advance.
'a -> 'a -> int). - Marthcomparefunction from pervasives, using it asList.sort compare [2; 3; 1];;. For more complicated/custom types you're probably better off using acmpfunction (that is, a function'a -> 'a -> intwhere the result is greater than 0 if the first is greater that the second one, less than 0 if it's the other way around and 0 if both values are equals (or "considered equals" in this comparison)). Note thatcomparewill work on most types, but I wouldn't use it for anything but primitives. - Marth