Created
October 31, 2011 22:17
-
-
Save sshine/1329208 to your computer and use it in GitHub Desktop.
Standard ML functor example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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