I can not get the following example from the OCaml manual to work:
# let rec sort lst =
match lst with
[] -> []
| head :: tail -> insert head (sort tail)
and insert elt lst =
match lst with
[] -> [elt]
| head :: tail -> if elt <= head then elt :: lst else head :: insert elt tail
;;
^-- this part works so far
# sort l;;
- : string list = ["a"; "etc."; "is"; "tale"; "told"]
^-- this is line from OCaml manual. I can’t run this line because the <
in my case seems to force to int
, whereas in the OCaml manual, somehow the <
is polymorphic.
Question: how do I define sort/insert above so that it is polymorphic ? Thanks!
EDIT: forgot actual link: OCaml - The core language