Skip to content

Instantly share code, notes, and snippets.

@Huxpro
Last active October 13, 2018 00:23
Show Gist options
  • Save Huxpro/87c7029013c1bd3a27fca1ed15b84db7 to your computer and use it in GitHub Desktop.
Save Huxpro/87c7029013c1bd3a27fca1ed15b84db7 to your computer and use it in GitHub Desktop.
module type Set = sig
type 'a t
val empty : 'a t
val isEmpty : 'a t -> bool
end
module ListSet : Set = struct
type 'a t = 'a list
let empty = []
let isEmpty l = l == []
end
module ListSetExt = struct
include ListSet
(* `len` should not type check if ListSet.t is still abstract *)
let len l = if isEmpty l then 0 else List.length l
let elts = function
| [] -> []
| h::t -> h::t
end
(* this should not type check as well *)
let _ = ListSetExt.elts (ListSetExt.empty)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment