CS 6520 HW 5

Given the following:

; map : (X -> Y) list-of-X -> list-of-Y
(define (map f l)
  (foldr (uncurry (compose (curry cons) f)) 
         empty l))

; uncurry : (X -> (Y -> Z)) -> (X Y -> Z)
(define (uncurry f)
  (lambda (v1 v2)
    ((f v1) v2)))

; compose (Y -> Z) (X ->Y) -> (X -> Z))
(define (compose f g)
  (lambda (x) (f (g x))))

; curry : (X Y -> Z) -> (X -> (Y -> Z))
(define (curry f)
  (lambda (v1)
    (lambda (v2)
      (f v1 v2))))

; foldr : (X Y -> Y) list-of-X -> Y
(define (foldr COMB base l)
 (cond
  [(empty? l) base]
  [(cons? l) 
   (COMB (first l)
	 (foldr COMB base (rest l)))]))
show evaluations steps for
(map add1 (cons 1 empty))
to produce
(cons 2 empty)


Last update: Friday, February 6th, 2004
mflatt@cs.utah.edu