signature INTSTACK = sig type stack exception Empty val empty : stack val push : stack -> (int -> stack) val pop : stack -> int * stack end signature STACK = sig type 'a stack exception Empty val empty : 'a stack val push : 'a stack -> ('a -> 'a stack) val pop : 'a stack -> 'a * 'a stack end (* type ('k,'v) dictionary = ... *) (* structure A = struct type t = ... val x = ... end type A.t = ... val A.x = ... *) structure Stack :> STACK = struct (* type stack('a) = ... *) type 'a stack = 'a list exception Empty val e = [] val empty : 'a stack = e val push : 'a stack -> ('a -> 'a stack) = fn (s: 'a list) => fn x => x :: s fun pop (nil) = raise Empty | pop (h::t) = (h, t) end (*val x = Stack.e;*) val s : int Stack.stack = Stack.empty; val t = Stack.push s 3; val t = Stack.push t 4; val u = List.map (fn x => x + 1) t; Stack.pop t; structure Stack2 :> STACK = struct (* representation invariant: 'a stack can only Blah or Node *) datatype 'a stack = Emp | Node of 'a * 'a stack | Blah exception Empty val empty : 'a stack = Blah fun push s x = Node (x, s) fun pop (Blah) = raise Empty | pop (Node (x, s)) = (x, s) end val s : int Stack2.stack = Stack2.empty; val t = Stack2.push s 3; val t = Stack2.push t 4;