lec10 - (* Signature for simple set data type *) module...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
(* Signature for simple set data type *) ( module type SETSIG = sig type set type elt val empty : set val mem : elt -> set -> bool val add: elt -> set -> set val find: elt -> set -> elt end e (* Signature for equality test on an abstract data type *) ( module type EQUALSIG = sig type t val equal : t -> t -> bool end e (* Functor for creating module for set of elements of some type with a * specified equality test. * * Represents a set as a list with no duplicates. *) module MakeSet (Equal : EQUALSIG) : SETSIG with type elt = Equal.t = struct open Equal type elt = t type set = elt list let empty = [] let mem x s = List.exists (equal x) s let add x s = if mem x s then s else x :: s let find x s = List.find (equal x) s end e (* Module for case independent string equality *) ( module StringNoCase = struct type t = string let equal s1 s2 = String.lowercase s1 = String.lowercase s2 end e (* Module for sets of strings with case independent equality test. *) ( module SSet = MakeSet (StringNoCase)
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 10/25/2009 for the course PHYS 2214 at Cornell University (Engineering School).

Page1 / 2

lec10 - (* Signature for simple set data type *) module...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online