Is there any difference between an N-ary function in Curry and an N+1-ary relation in Prolog?

146 views Asked by At

Curry, unlike its cousin Haskell, allows you to give multiple values to a function:

foo 1 2 = 3
foo 1 2 = 4

and it does backtracking (or some other search) to explore the implications of such non-determinism.

This makes it similar to Prolog (especially λProlog due to the type system and syntax), where you would instead state

foo 1 2 3.
foo 1 2 4.

Semantically, is there any difference between an N-ary Curry function and an N+1-ary Prolog relation?

2

There are 2 answers

6
Michael Hanus On BEST ANSWER

The difference between Curry and Prolog are the dependencies between arguments and results which are the basis for the optimal evaluation strategy used in Curry. Similarly to Haskell, Curry uses a lazy (needed) evaluation strategy. This has the consequence that the search space is explored in a demand-driven manner.

For instance, the expression

(xs ++ [1]) ++ ys =:= []

has a finite search space in Curry (without any answer), whereas the equivalent Prolog goal

?- append(Xs,[1],Zs), append(Zs,Ys,[]).

has an infinite search space. Similarly, there are examples where Curry computes a solution in contracst to Prolog (e.g., Curry allows computations with infinite structures similarly to Haskell).

Thus, Curry extends the demand-driven evaluation strategy of Haskell to non-deterministic programming, wheras Prolog is based on strict evaluation.

0
MWB On

After thinking about this some more I realized that the main difference is that in Prolog, both

foo 1 2 3.
foo 1 2 4.

can be true at the same time, while in Curry both of

foo 1 2 == 3
foo 1 2 == 4

cannot be true simultaneously. (In PAKCS, == and =:= return Bool)