prolog2curry - Transforming Prolog programs to Curry programs

This package contains an implementation of a tool (pl2curry) to transform Prolog programs to Curry programs. The tool has various options to influence the kind of transformation, e.g.:

Note that this is always possible since non-linear left-hand sides are allowed in Curry (in contrast to Haskell).

For instance, if p/3 is a function and the last argument is the result, then a goal p(X,Y,Z) is transformed into z =:= p x y.

Note that it is necessary to define function as an operator in Prolog in order to read Prolog programs with such directives. This can be done by adding the following directives at the beginning of the Prolog program:

  :- op(1150,fx,function).
  function(_).

Since adding function directives to specify result argument positions is tedious, the tool also contains an analysis to derive automatic function directives (if not already explicitly provided and if the option --noanalysis is not set) for standard functions (i.e., where only the last argument is a result position). It is based on the following principle:

The information about the inferred sets of inductively sequential argument and result arguments of functions is printed if the verbosity is larger than 1.

A special case of the previous criterion are predicates defined by a single rule, e.g., predicate which define constants, as

two(s(s(o))).

This will be translated into

two = S (S O)

Although this is correct, it is sometimes unintended, e.g., if p is defined by the single clause

p(X,Y) :- q(X,Z), r(Z,Y).

In order to keep such predicates as predicates on the Curry level, the following heuristic is used. A predicate defined by a single rule is transformed as a function only if the last argument in the left-hand side is not a variable or a variable which occurs in a result argument position in the rule's body.

Although these heuristics provide expected transformations in most case, one can always override them using an explicit function directive.

Technical remarks:

This behavior can be changed by setting the option --anyresult. In this case, a maximum argument will be selected. If this is not the last one, the index of the result argument position is added to indicate that the order of arguments has been changed in the transformed function. See examples/demand.pl for such examples.