Skip to content

Instantly share code, notes, and snippets.

@Chouser
Last active August 29, 2015 14:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Chouser/15bb2a380520c6b46fc7 to your computer and use it in GitHub Desktop.
Save Chouser/15bb2a380520c6b46fc7 to your computer and use it in GitHub Desktop.
Attempt at recursive map type in OCaml
module rec VariantMod
: sig
type t = Int of int | Map of t OrderedValMap.t
end = VariantMod
and OrderedVal
: sig
type t = VariantMod.t
val compare : t -> t -> int
end
= struct
type t = VariantMod.t
let compare = Pervasives.compare
end
and OrderedValMap
: Map.S with type key = OrderedVal.t
= Map.Make(OrderedVal)
let example_int = VariantMod.Int 42
let example_map_val = OrderedValMap.add example_int example_int OrderedValMap.empty
let example_map = VariantMod.Map example_map_val
let example_map2 = VariantMod.Map (OrderedValMap.add example_map example_map OrderedValMap.empty)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment