val empty : key set val is_empty : key set -> bool val make : key list -> key set val dest : key set -> key list val inter : key set -> key set -> key set val subtract : key set -> key set -> key set(* NOTE: subtracts first from second *) val union : key set -> key set -> key set val union_sets : key setlist -> key set val insert : key -> key set -> key set val contains : key set -> key -> bool val subset : (key set * key set) -> bool val card: key set -> int valmap: (key -> key) -> key set -> key set valfilter: (key -> bool) -> key set -> key set val eq: key set * key set -> bool end;
functor Set(Key: KEY): SET = struct
type key = Key.key;
(* *Wewrapeverythinginaprivatedatatypetoenforcetheusertoonlyusethe *abstractinterface.
*) datatype'a set = S of 'a list;
(* Make a set from a list. *) fun make x = Ord_List.make Key.ord x |> S
(* Convert the set back into a list. *) fun dest (S x) = x
(* Emptiness *) val empty = S [] fun is_empty (S x) = (length x = 0)
(* Set manipulation. *) fun inter (S a) (S b) = Ord_List.inter Key.ord a b |> S fun subtract (S a) (S b) = Ord_List.subtract Key.ord a b |> S fun union (S a) (S b) = Ord_List.union Key.ord a b |> S fun insert a (S b) = Ord_List.insert Key.ord a b |> S fun union_sets l = fold union l empty fun contains (S l) a = Ord_List.member Key.ord l a fun subset (S a, S b) = Ord_List.subset Key.ord (a, b) fun card (S a) = length a funmap f (S a) = make (List.map f a) funfilter f (S a) = S (List.filter f a) fun eq ((S a), (S b)) = is_equal (list_ord Key.ord (a, b)) end;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.