[Haskell-cafe] Re: The Worker/Wrapper Transformation

Achim Schneider barsoap at web.de
Thu Jan 3 08:21:09 EST 2008


Achim Schneider <barsoap at web.de> wrote:

> (define (cons x y)
>    (lambda (m) (m x y)))
>  
> (define (car z)
>    (z (lambda (p q) p)))
> 
> (define (cdr z)
>    (z (lambda (p q) q)))
> 
, which, just for completeness, can be of course also be done in
Haskell:

cons :: a -> b -> (a -> b -> c) -> c
cons x y m = m x y

car :: ((a -> b -> a) -> c) -> c 
car z = z $ \p q -> p

cdr :: ((a -> b -> b) -> c) -> c
cdr z = z $ \p q -> q

Prelude> car $ cdr $ cdr $ cons 1 $ cons 2 $ cons 3 ()
3


-- 
(c) this sig last receiving data processing entity. Inspect headers for
past copyright information. All rights reserved. Unauthorised copying,
hiring, renting, public performance and/or broadcasting of this
signature prohibited. 



More information about the Haskell-Cafe mailing list