15.08.2013 Views

General Computer Science 320201 GenCS I & II Lecture ... - Kwarc

General Computer Science 320201 GenCS I & II Lecture ... - Kwarc

General Computer Science 320201 GenCS I & II Lecture ... - Kwarc

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Example 127 〈{N}, {[o: N], [s: N → N]}〉<br />

Example 128 〈{N, L(N)}, {[o: N], [s: N → N], [nil: L(N)], [cons: N × L(N) → L(N)]}〉 In particular,<br />

the term cons(s(o), cons(o, nil)) represents the list [1, 0]<br />

Example 129 〈{S}, {[ι: S], [→: S × S → S], [×: S × S → S]}〉<br />

c○: Michael Kohlhase 86<br />

In contrast to SML datatype declarations we allow more than one sort to be declared at one time.<br />

So abstract data types correspond to a group of datatype declarations.<br />

With this definition, we now have a mathematical object for (sequences of) data type declarations<br />

in SML. This is not very useful in itself, but serves as a basis for studying what expressions we<br />

can write down at any given moment in SML. We will cast this in the notion of constructor terms<br />

that we will develop in stages next.<br />

Ground Constructor Terms<br />

Definition 130 Let A := 〈S 0 , D〉 be an abstract data type, then we call a representation t<br />

a ground constructor term of sort T, iff<br />

T ∈ S 0 and [t: T] ∈ D, or<br />

T = A × B and t is of the form 〈a, b〉, where a and b are ground constructor terms of<br />

sorts A and B, or<br />

t is of the form c(a), where a is a ground constructor term of sort A and there is a<br />

constructor declaration [c: A → T] ∈ D.<br />

We denote the set of all ground constructor terms of sort A with T g<br />

<br />

A∈S<br />

T g<br />

A (A).<br />

A (A) and use T g (A) :=<br />

Definition 131 If t = c(t ′ ) then we say that the symbol c is the head of t (write head(t)).<br />

If t = a, then head(t) = a; head(〈t1, t2〉) is undefined.<br />

Notation 132 We will write c(a, b) instead of c(〈a, b〉) (cf. binary function)<br />

c○: Michael Kohlhase 87<br />

The main purpose of ground constructor terms will be to represent data. In the data type from Example<br />

127 the ground constructor term s(s(o)) can be used to represent the unary natural number<br />

2. Similarly, in the abstract data type from Example 128, the term cons(s(s(o)), cons(s(o), nil))<br />

represents the list [2, 1].<br />

Note: that to be a good data representation format for a set S of objects, ground constructor<br />

terms need to<br />

• cover S, i.e. that for every object s ∈ S there should be a ground constructor term that<br />

represents s.<br />

• be unambiguous, i.e. that we can decide equality by just looking at them, i.e. objects s ∈ S<br />

and t ∈ S are equal, iff their representations are.<br />

But this is just what our Peano Axioms are for, so abstract data types come with specialized<br />

Peano axioms, which we can paraphrase as<br />

Peano Axioms for Abstract Data Types<br />

Idea: Sorts represent sets!<br />

Axiom 133 if t is a ground constructor term of sort T, then t ∈ T<br />

48

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!