1. Higher-order functions
Here are the signatures of some of the higher-order functions provided by DrRacket.
;; map : [X -> Y] List<X> -> List<Y>
;; andmap: [X -> Boolean] List<X> -> Boolean
;; ormap: [X -> Boolean] List<X> -> Boolean
;; foldr: [X Y -> Y] Y List<X> -> Y
;; foldl: [X Y -> Y] Y List<X> -> Y
When we use a one of this functions are providing concrete data definitions (i.e., non-abstract). For example
> (map add1 (list 1 2 3 4))
(list 2 3 4 5)
we are using map
with the following concrete signature
> (map add1 (list 1 2 3 4)) ;; [Number -> Number] List<Number> -> List<Number>
(list 2 3 4 5)
2. Managing a class of students
One of the professors in the department is asking for your help in developing programs to help them manage their class.
The would like to keep a list of all students in their class. For each student we would like to capture
-
the student’s name
-
the student’s id
-
a list of all the students homework grades
3. Generic Binary Trees
A friend is working on an assignment that asks them to generalize over binary trees. They already have examples of binary tree data definitions
;; An SBT is one of
;; - empty
;; - (make-snode String SBT SBT)
(define-struct snode (val left right))
;; An IBT is one of
;; - empty
;; - (make-snode Integer IBT IBT)
(define-struct inode (val left right))
Your friend is having problems generalizing over these data definitions.
Now your friend is asked to generalize over functions of SBT
and IBT
.