Created
May 30, 2013 11:38
-
-
Save xjia1/5677283 to your computer and use it in GitHub Desktop.
Standard ML Signature Usage
This file contains hidden or 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
$ sml | |
Standard ML of New Jersey v110.67 [built: Wed Apr 10 22:39:58 2013] | |
- use "sigtest.sml"; | |
[opening sigtest.sml] | |
[autoloading] | |
[library $SMLNJ-BASIS/basis.cm is stable] | |
[autoloading done] | |
signature MYLIST = | |
sig | |
type 'a T | |
val new : 'a -> 'a T | |
val add : 'a T -> 'a -> 'a T | |
val len : 'a T -> int | |
end | |
functor Test(L: sig | |
type 'a T | |
val new : 'a -> 'a T | |
val add : 'a T -> 'a -> 'a T | |
val len : 'a T -> int | |
end) : | |
sig val test : int L.T -> int L.T end | |
structure MyList : | |
sig | |
type 'a T = 'a list | |
val new : 'a -> 'a list | |
val add : 'a list -> 'a -> 'a list | |
val len : 'a list -> int | |
end | |
val it = () : unit | |
- structure T = Test (MyList); | |
structure T : sig val test : int L.T -> int L.T end | |
- T.test (MyList.new 100); | |
2 | |
3 | |
val it = [2,1,100] : int MyList.T | |
- |
This file contains hidden or 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 MYLIST = | |
sig | |
type 'a T | |
val new : 'a -> 'a T | |
val add : 'a T -> 'a -> 'a T | |
val len : 'a T -> int | |
end | |
functor Test (L : MYLIST) = | |
struct | |
fun test l = | |
let | |
val l = L.add l 1 | |
val _ = print (Int.toString (L.len l) ^ "\n") | |
val l = L.add l 2 | |
val _ = print (Int.toString (L.len l) ^ "\n") | |
in | |
l | |
end | |
end | |
structure MyList = | |
struct | |
type 'a T = 'a list | |
fun new x = [x] | |
fun add xs x = x::xs | |
fun len xs = length xs | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment