14.11.2012 Views

Curry: An Integrated Functional Logic Language

Curry: An Integrated Functional Logic Language

Curry: An Integrated Functional Logic Language

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

functions must be free of side-effects in order to be compatible with <strong>Curry</strong>’s computation model.<br />

<strong>An</strong> external constraint solver consists of a constraint store which can be accessed and manipulated<br />

via a few primitive operations.<br />

9.1 External Functions<br />

External functions are considered as an implementation of a potentially infinite set of equations<br />

(describing the graph of the functions). In particular, they have no side effects, i.e., identical<br />

function calls at different points of time yield identical results. Since the implementation of an<br />

external function is unknown, a call to an external function is suspended until all arguments are<br />

fully known, i.e., until they are evaluated to ground data terms. This view is compatible with the<br />

residuation principle covered by <strong>Curry</strong>’s computation model and very similar to the connection of<br />

external functions to logic programs [9, 10].<br />

<strong>An</strong> external function is declared by a type declaration followed by external(FName,OF,Lang)<br />

where FName is the name of the external function where its code is contained in the object file OF.<br />

Lang is the implementation language of the external function. For instance, if the addition and<br />

multiplication on integers are defined as C functions named add and mult where the compiled code<br />

is contained in the file “arith.o”, we can connect these functions to a <strong>Curry</strong> program by providing<br />

the declarations<br />

add :: Int -> Int -> Int external("add","arith.o",C)<br />

mult :: Int -> Int -> Int external("mult","arith.o",C)<br />

Implementations of <strong>Curry</strong> might have restrictions on the interface. A reasonable requirement is<br />

that the implementation language is constrained to C and the argument and result types are only<br />

simple types like Bool, Int, Float, Char, or String.<br />

9.2 External Constraint Solvers<br />

A constraint solver can be viewed as an abstract datatype consisting of a constraint store together<br />

with a few operations to check the entailment of a constraint or to add a new constraint. In order<br />

to connect a constraint solver to <strong>Curry</strong>, like a solver for arithmetic or Boolean constraints, the<br />

external solver must provide the following operations (cs denotes the type of the constraint store<br />

and c the type of constraints):<br />

new : → cs (create and initialize a new constraint store)<br />

ask : cs × c → {T rue, F alse, Unknown} (check entailment of a constraint)<br />

tell : cs × c → cs (add a new constraint)<br />

clone : cs → cs × cs (copy the constraint store)<br />

Using these operations, it is relatively easy to extend <strong>Curry</strong>’s computation model to include constraints<br />

by adding the constraint store as a new component to the substitution part in answer<br />

expressions (cf. Section 3). 12<br />

12 This section will be modified or extended in a later version.<br />

35

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!