SE 3M04 SE 3M04 Fall 2003 Consider the following declarations type date = int*int*int type name = string type bday = name*date type bdayset = bday set val s : bdayset from a ”system” that stores names and birthdays. Jacques Carette, 09/2003 –1–
SE 3M04 SE 3M04 Fall 2003 Consider the following declarations type date = int*int*int type name = string type bday = name*date type bdayset = bday set val s : bdayset from a ”system” that stores names and birthdays. • Each person can only have one birthday ∀ ( a, b ) : bday . ∀ ( c, d ) : bday . ( a, b ) ∈ s ∧ ( c, d ) ∈ s ∧ ( a = c → b = d ) Jacques Carette, 09/2003 –1-a–
SE 3M04 SE 3M04 Fall 2003 • There is no one with name “n” in s We can define a predicate P : string*bdayset → bool which expresses this: fun P ( n, s ) = ∀ ( a, b ) : bday. ( a, b ) ∈ s ∧ a � = n fun P ( n, s ) = ∀ ( a, b ) ∈ s.a � = n We would then use P ( Jacques , s ) to verify if Jacques is (or is not) in s . Jacques Carette, 09/2003 –2–
SE 3M04 SE 3M04 Fall 2003 • There is no one with name “n” in s We can define a predicate P : string*bdayset → bool which expresses this: fun P ( n, s ) = ∀ ( a, b ) : bday. ( a, b ) ∈ s ∧ a � = n fun P ( n, s ) = ∀ ( a, b ) ∈ s.a � = n We would then use P ( Jacques , s ) to verify if Jacques is (or is not) in s . • The set of names of people born on date “d” Define a function LN : date*bdayset → name set , fun LN ( d, s ) = { a | (( a, d ) ∈ s ) } Jacques Carette, 09/2003 –2-a–
SE 3M04 SE 3M04 Fall 2003 • There is no one with name “n” in s We can define a predicate P : string*bdayset → bool which expresses this: fun P ( n, s ) = ∀ ( a, b ) : bday. ( a, b ) ∈ s ∧ a � = n fun P ( n, s ) = ∀ ( a, b ) ∈ s.a � = n We would then use P ( Jacques , s ) to verify if Jacques is (or is not) in s . • The set of names of people born on date “d” Define a function LN : date*bdayset → name set , fun LN ( d, s ) = { a | (( a, d ) ∈ s ) } • There is a person born on date “d” ∃ n : name . ( n, d ) ∈ s Jacques Carette, 09/2003 –2-b–
Recommend
More recommend