signature restricted = sig type 'a set val equal_sets : ''a set -> ''a set -> bool val intersection : ''a set -> ''a set -> ''a set val make_set : ''a list -> ''a set val member : ''a -> ''a set -> bool val remove : ''a -> ''a set -> ''a set val subset : ''a set -> ''a set -> bool val superset : ''a set -> ''a set -> bool val union : ''a set -> ''a set -> ''a set end; (*sets*) structure sets:restricted = struct datatype 'a set = Set of 'a list; val empty_set = Set []; fun member e (Set []) = false |member e (Set (a::x)) = e=a orelse member e (Set x); fun add e S = if member e S then S else let val Set(x) = S in Set(e::x) end; fun subset (Set []) s2 = true |subset (Set (e::x)) s2 = member e s2 andalso subset (Set x) s2; fun superset s1 s2 = subset s2 s1; fun equal_sets s1 s2 = subset s1 s2 andalso subset s2 s1; fun union (Set []) s2 = s2 |union (Set (e::x)) s2 = if not(member e s2) then union (Set x) (add e s2) else union (Set x) s2; fun intersection (Set []) s2 = empty_set |intersection (Set (e::x)) s2 = if member e s2 then add e (intersection (Set x) s2) else intersection (Set x) s2; fun difference (Set []) s2 = empty_set |difference (Set (e::x)) s2 = if not(member e s2) then add e (difference (Set x) s2) else difference (Set x) s2; fun remove e (Set []) = empty_set |remove e (Set (a::x)) = if e=a then (Set x) else add a (remove e (Set x)); fun show (Set []) = [] |show (Set (e::x)) = e::show (Set x); fun make_set [] = empty_set |make_set (e::x) = add e (make_set x); fun map_set f (Set s) = make_set (map f s) end; Script started on Wed Nov 6 14:54:25 1991 hunter-01% sml Standard ML of New Jersey, Version 0.66, 15 September 1990 val it = () : unit - use "sets-sig"; [opening sets-sig] signature restricted = sig type 'a set val equal_sets : ''a set -> ''a set -> bool val intersection : ''a set -> ''a set -> ''a set val make_set : ''a list -> ''a set val member : ''a -> ''a set -> bool val remove : ''a -> ''a set -> ''a set val subset : ''a set -> ''a set -> bool val superset : ''a set -> ''a set -> bool val union : ''a set -> ''a set -> ''a set end [closing sets-sig] val it = () : unit - use "sets-struct"; [opening sets-struct] structure sets : sig eqtype 'a set val equal_sets : ''a set -> ''a set -> bool val intersection : ''a set -> ''a set -> ''a set val make_set : ''a list -> ''a set val member : ''a -> ''a set -> bool val remove : ''a -> ''a set -> ''a set val subset : ''a set -> ''a set -> bool val superset : ''a set -> ''a set -> bool val union : ''a set -> ''a set -> ''a set end [closing sets-struct] val it = () : unit - member; std_in:4.1-4.6 Error: unbound variable member - sets.member; val it = fn : ''a -> ''a sets.set -> bool - val s = sets.make_set [1,2,3]; val s = Set [1,2,3] : int sets.set - s; val it = Set [1,2,3] : int sets.set - val s2 = (sets.Set [3,9,99]); std_in:1.11-1.18 Error: unbound variable or constructor in structure: Set - open sets; open sets - val s2 = (Set [1,2,3,4]); std_in:2.11-2.13 Error: unbound variable Set std_in:2.10-2.24 Error: operator is not a function operator: undef in expression: Set 1 :: 2 :: 3 :: :: - val s2 = make_set ["ted","alice","poppy","nelson"]; val s2 = Set ["ted","alice","poppy","nelson"] : string set - member "alice" s2; val it = true : bool - show s2; std_in:3.1-3.4 Error: unbound variable show std_in:3.1-3.7 Error: operator is not a function operator: undef in expression: show s2 - add "spit" s2; std_in:1.1-1.3 Error: unbound variable add std_in:1.1-1.13 Error: operator is not a function operator: undef in expression: add "spit" hunter-01% script done on Wed Nov 6 14:58:12 1991