ocaml compiler is really punishing me by giving me a very unhelpful error message. All it says is
54 | let x = AbstractStringSet.(add "foo" AbstractStringSet.empty) in
^^
Error: Syntax error
Here is my code. I am compiling it using “ocamlc foo.ml -o foo”
It is taken from Ocaml manual
type comparision = Less | Equal | Greater
module type ORDERED_TYPE = sig
type t
val compare : t -> t -> comparision
end
module OrderedString = struct
type t = string
let compare a b =
if a = b then
Equal
else
if a < b then
Less
else
Greater
end
module type SETFUNCTOR =
functor (Elt: ORDERED_TYPE) -> sig
type element = Elt.t
type set
val empty : set
val add : element -> set -> set
val member : element -> set -> bool
end
module Set = functor (Elt: ORDERED_TYPE) ->
struct
type element = Elt.t
type set = element list
let empty = []
let rec add x s =
match s with
[] -> [x]
| hd :: tl ->
match Elt.compare hd x with
Equal -> s
| Less -> x :: s
| Greater -> hd :: add x tl
let rec member x s =
match s with
[] -> false
| hd :: tl ->
match Elt.compare hd x with
Equal -> true
| Less -> false
| Greater -> member x tl
end
module AbstractSet = (Set: SETFUNCTOR)
module AbstractStringSet = AbstractSet(OrderedString)
let x = AbstractStringSet.add "foo" AbstractStringSet.empty in
match AbstractStringSet.member "foo" x with
| true -> print_endline "foo is found"
| false -> print_endline "foo not found"