Exercise 2.6

1 view
Skip to first unread message

Quux Man

unread,
Nov 7, 2007, 2:20:03 PM11/7/07
to seattle-sicp...@googlegroups.com
I don't remember going over this very thoroughly. Here's benny99's (from #haskell) solution:

( define (zero f)
    ( lambda (x) x)
)


( define (one f)
    ( lambda (x) (f x))
)


(define (two f )
  (lambda (x) (f (f x)))
)



( define (add-1 n )
    (lambda (f)
      (lambda (x)
        (f ((n f ) x))
)
)
)


( define (add n m)
    ( lambda (f)
      ( lambda (x)
        ((compose (m f) (n f)) x)
)
)
)


( define (chn->n c) ((c ( lambda (x) ( + x 1))) 0))

This brings up my original problem with the problem: it's not very well defined. Is he asking to define an add that's faster than adding 1 n or m times? Is this possible using Church Numerals? Or is the question asking something simpler?
Reply all
Reply to author
Forward
0 new messages