Skip to content

Instantly share code, notes, and snippets.

@sshine
Created October 31, 2011 22:17
Show Gist options
  • Save sshine/1329208 to your computer and use it in GitHub Desktop.
Save sshine/1329208 to your computer and use it in GitHub Desktop.
Standard ML functor example
signature FOO =
sig
type 'a foo
val f : 'a -> 'a foo
end
signature BAR =
sig
structure Foo : FOO
val p : 'a -> bool
end
functor F (B : BAR) : FOO =
struct
type 'a foo = 'a B.Foo.foo
fun f x = if B.p x
then B.Foo.f x
else raise Domain
end
structure SomeFoo =
struct
type 'a foo = 'a * 'a
fun f x = (x, x)
end
structure SomeFooP = F (struct structure Foo = SomeFoo
fun p x = x <> 42 end)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment