Curry is an experimental functional logic programming language, based on the Haskell language. It merges elements of functional and logic programming, including constraint programming integration.
Curry | |
---|---|
Paradigm | functional, logic, non-strict, modular |
Designed by | Michael Hanus, et al |
Typing discipline | static, strong, inferred |
OS | portable |
Website | Curry |
Major implementations | |
PAKCS, mcc |
It is nearly a superset of Haskell, lacking support mostly for overloading using type classes, which some implementations provide anyway as a language extension, such as the Münster Curry Compiler.
Foundations of Functional Logic Programming
Basic Concepts
A functional program is a set of functions defined by equations or rules. A functional computation consists of replacing subexpressions by equal (w.r.t. the function definitions) subexpressions until no more replacements (or reductions) are possible and a value or normal form is obtained. For instance, consider the function double defined by
double x = x+x
The expression “double 1” is replaced by 1+1. The latter can be replaced by 2 if we interpret the operator “+” to be defined by an infinite set of equations, e.g.,1+1 = 2, 1+2 = 3, etc. In a similar way, one can evaluate nested expressions (where the subexpression to be replaced are quoted):
'double (1+2)' → '(1+2)'+(1+2) → 3+'(1+2)' → '3+3' → 6
There is also another order of evaluation if we replace the arguments of operators from right to left:
'double (1+2)' → (1+2)+'(1+2)' → '(1+2)'+3 → '3+3' → 6
In this case, both derivations lead to the same result. This indicates a fundamental property of declarative languages, also termed referential transparency: the value of a computed result does not depend on the order or time of evaluation due to the absence of side effects. This simplifies the reasoning about and maintenance of declarative programs.
Obviously, these are not all possible evaluation orders since one can also evaluate the argument of double before applying its defining equation:
double '(1+2)' → 'double 3' → '3+3' → 6
In this case, we obtain the same result with less evaluation steps. ...
As functional languages like Haskell do, Curry supports the definition of algebraic data types by enumerating their constructors. For instance, the type of Boolean values consists of the constructors True and False that are declared as follows:
data Bool = True | False
Functions on Booleans can be defined by pattern matching, i.e., by providing several equations for different argument values:
not True = False not False = True
The principle of replacing equals by equals is still valid provided that the actual arguments have the required form, e.g.:
not '(not False)' → 'not True' → False