type comparison = Less | Equal | Greater module type ORDERED_TYPE = sig type t val compare: t -> t -> comparison end module Set = functor (Element : ORDERED_TYPE) -> struct type element = Element.t type set = element list let empty = [] let rec adjoin element set = match set with [] -> [element] | head::tail -> match Element.compare element head with Equal -> set | Less -> element :: set | Greater -> head :: (adjoin element tail) let rec is_member element set = match set with [] -> false | head::tail -> match Element.compare element head with Equal -> true | Less -> false | Greater -> is_member element tail end module OrderedString = struct type t = string let compare x y = if x = y then Equal else if x < y then Less else Greater end module StringSet = Set(OrderedString)