Quantcast
Channel: Active questions tagged ocaml - Stack Overflow
Viewing all articles
Browse latest Browse all 529

OCaml online: List.sort compare is not working

$
0
0

I am testing the following OCaml's online environment: https://try.ocamlpro.com/

However, my algorithms are failing because of the use of List.sort compare x, where x is a list of integers. I have tested the following basic code List.sort compare [2; 3; 1];; and seen it throws an error:

Error: This expression has type ('a -> 'a -> int) -> 'a list -> 'a list -> intbut an expression was expected of type  ('a -> 'a -> int) -> ('a -> 'a -> int) -> intType 'a list is not compatible with type 'a -> 'a -> int 

The online environment specifies it is OCaml 4.13.1, so does this mean compare is deprecated? In that case, how can I substitute it?


EDIT:

I have seen the following:

If you just write List.sort compare [2; 3; 1];; in the online environment, then it returns the correct output - : int list = [1; 2; 3].

However, if you load the List module with open List, then the error above is thrown.


Viewing all articles
Browse latest Browse all 529

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>