A list-of-XYZs is either - empty or - (cons N L) where N is a XYZ and L is a list-of-XYZs.We write (listof XYZ) from now on. XYZ is a placeholder, but unlike those in programs it stands for entire collections of data, not just individual pieces of data.
Examples:
(list (make-personnel-record 'Man 100000) (make-personnel-record 'Kiddo 1000))
(define (blah alon num sign) (cond ((empty? alon) num) (else (sign (first alon) (blah (rest alon))))))
To answer this question, we must step back and ask:
Function names and primitive operations are values. That is, if Scheme provides prim-op and we define (define (f ... ) ...) in our program (scope), then prim-op and f are values just like 5, 'eve, #t.
What is the data definition of such a value?
When we say number, we know we are talking about
5, -5, 3/4 or #i1.789 etc.
When we say symbol, we know we are talking about
'eve, 'adam etc.
When we say (listof symbol), we know we are talking about
(cons 'eve (cons 'adam empty)) etc.
But what about things like +? Or not? To what data
collection to they belong?
+ is an operation that consumes two numbers and produces their sum:
(number number -> number)
How about
(define (f x y) (/ (+ x y) 2))f is a function that consumes two numbers and produces their sum: (number number -> number)
(define (g x) x)g is a function that consumes a number and returns it: (number -> number)
In general, a function/an operation belongs to a class of data that is best described with our arrow notation:
(listof number) number (number number -> number) -> number
(listof number) (listof PR) (number (listof number) -> (listof number)) -> (listof number)
(listof PR) (listof PR) (PR (listof PR) -> (listof PR)) -> (listof PR)
Here we go: we need placeholder in contracts, too:
(listof X) Y (X Y -> Y) -> Y
What do X and Y stand for in the above sample contracts? Data collections again. If we want a "concrete" contract, we must replace all X with some "specific" collection and all Y with another one (or the same).
This is called parametric polymorphism
Matthias Felleisen | This page was generated on Fri Apr 9 09:17:38 CDT 1999. |