Display program code

lazyCHR.pl : Some examples of lazy evaluation using CHR
We give an embedding of the Haskell language into CHR. Here you can try how it works in the following program:
plus(0, Y) = Y
plus(s(X), Y) = s(plus(X, Y))
double X = plus(X, X)
head cons(X, _) = X
zeros = cons(0, zeros)
prec(s(X)) = X
take(0, _) = void
take(_, void) = void
take(N, cons(X, Xs)) = cons(x, take(prec(N), Xs)
It has been defined also the well know higher-order funtion map:
map(f, void) = void
map(f, cons(X, Y)) = cons(f(X), map(f,Y))

How to use:
Remembering that a list is defined by means of the void/0 (the empty list) and cons/2 data construction.
In order to run a ground expression *e* you just have to run a query of the form ?- eval(e, Z)., this will bond the result to the *Z* variable.

See also:
'John C. Reynolds. Definitional interpreters for higher-order programming languages. Higher-Order and Symbolic Computation, 11(4):363–397, 1998.'
'David H.D. Warren. Higher-order extensions to prolog: are they needed? In J.E. Hayes, Donald Michie, and Y-H. Pao, editors, Machine Intel ligence 10, pages 441–454. Ellis Horwood Ltd., Chicester, England, 1982.'
S. Narain. A Technique for doing Lazy Evaluation in Logic

Program: Change the code, then submit!

Console: Enter query or select example from below, then submit and wait for answer!

Select example query: 

CHR
WebCHR help - CHR Website - (c) Copyrights Martin Kaeser Uni Ulm 2007