![]() |
![]() |
|
home—info—lectures—exams—hws—archive
Review:
We saw re-writing OO as static methods, adding implicit param `this`.
We saw types as sets;
Cf. n : int
f : String, double -> int
with
n ∈ Z
f ∈ Σ* ✗ R → Z
objects/structs are cross-product of types
Today: union types
e.g., LibItem = Book U CD
CDs: have titles, and a time (in minutes)
Let's write a functions for any LibItem.
How to write:
pass-time : LibItem -> number
(What is the template?)
Updating The Design Recipe
(Adapted from How to Design Programs)
For each type of data involved:
1. Data Definition (how will you represent an age, a gender, a book, etc.)
2. Examples of the Data (trivial first)
Then, for each function involving that data:
3. description, signature, and header/stub
4. test cases
5a.
case analysis
5b. selectors (what is the type of each?)
5c. add any natural/pertinent function calls on these pieces
5d. assemble the parts of 5b.
6. Run tests.
Coming up:
- grammars (context-free):
sentence3
parsing; showing a derivation.
grammar w/ a loop: 'sentence*'
grammar for scheme we've seen
home—info—lectures—exams—hws—archive
| ©2009, Ian Barland, Radford University Last modified 2009.Sep.16 (Wed) |
Please mail any suggestions (incl. typos, broken links) to ibarland |
![]() |