Sorting a list in OCaml
Posted
by darkie15
on Stack Overflow
See other posts from Stack Overflow
or by darkie15
Published on 2010-05-03T06:42:40Z
Indexed on
2010/05/03
6:58 UTC
Read the original article
Hit count: 525
ocaml
Hi All,
Here is the code on sorting any given list:
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;;
[Source: Code
However, I am getting an Unbound error:
Unbound value tail
# 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;;
Characters 28-29:
| head :: tail -> if elt <= head then elt :: lst else head :: insert elt tail;;
^
Error: Syntax error
Can anyone please help me understand the issue here?? I did not find head
or tail
to be predefined anywhere nor in the code
© Stack Overflow or respective owner