Skip to content

Instantly share code, notes, and snippets.

@Eckankar
Last active December 26, 2015 12:49
Show Gist options
  • Select an option

  • Save Eckankar/7154312 to your computer and use it in GitHub Desktop.

Select an option

Save Eckankar/7154312 to your computer and use it in GitHub Desktop.
signature LIST =
sig
type t
val toList : t list
val head : t option
(* structure Tail : LIST *)
val empty : bool
end
functor Nil(E : sig type e end) =
struct
type t = E.e
val toList = []
val head = NONE
structure Tail = struct type e = E.e end
val empty = true
end
functor Cons(E : sig structure Tail : LIST
val x : Tail.t end) =
struct
type t = E.Tail.t
val toList = E.x :: E.Tail.toList
val head = SOME E.x
structure Tail = E.Tail
val empty = false
end
structure Xs = Cons(struct val x = 5
structure Tail =
Cons(struct val x = 19
structure Tail =
Cons(struct val x = 27
structure Tail =
Nil(struct
type e = int
end)
end)
end)
end)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment