Feb 26, 2008

Lazy Evaluation of Haskell.

From Exercise 1.5 of SICP.

What the result is this Scheme code.

(define (p) (p))

(define (test x y)
(if (= x 0)
0
y))

(test 0 (p))

It's an infinite loop.

The case of Haskell.

p = p

test x y = case x of
0 -> 0
_ -> y

test 0 p

The result is zero.
This is Lazy Evaluation of Haskell.

No comments: