functional-programmingprologlogic-programmingcurrylambda-prolog

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


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?


Solution

  • 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.