Content deleted Content added
m Dating maintenance tags: {{Cleanup HTML}} |
Changed HTML to WikiMarkup. |
||
Line 1:
{{About|the programming language Curry (named in honour of a mathematician and logician)|the mathematician and logician|Haskell Curry|the computer science technique|Currying}}
{{Infobox programming language
Line 48 ⟶ 47:
double x = x+x
The expression “
'double (1+2)' → '(1+2)'+(1+2) → 3+'(1+2)' → '3+3' → 6
Line 58 ⟶ 57:
In this case, both derivations lead to the same result, a property known as [[Confluence (term rewriting)|confluence]]. This follows from a fundamental property of pure functional languages, 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 pure functional programs.
As many functional languages like [[haskell (programming language)|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
<source lang="haskell">
data Bool = True | False
Line 72 ⟶ 71:
More complex data structures can be obtained by recursive data types. For instance, a list of elements, where the type of elements is arbitrary (denoted by
the type variable
<source lang="haskell">
data List a = [] | a : List a
</source>
The type “
<source lang="haskell">
(++) :: [a] -> [a] -> [a]
Line 82 ⟶ 81:
(x:xs) ++ ys = x : xs++ys
</source>
Beyond its application for various programming tasks, the operation “
Based on this specification, one can define a function that satisfies this specification by employing logic programming features. Similarly to logic languages, functional logic languages provide search for solutions for existentially quantified variables. In contrast to pure logic languages, they support equation solving over nested functional expressions so that an equation like ys
<source lang="haskell">
last xs | ys++[e] =:= xs = e where ys,e free
</source>
Here, the symbol “
===Narrowing===
Line 112 ⟶ 111:
===Functional Patterns===
The rule defining
<source lang="haskell">
last (ys++[e]) = e
</source>
Haskell does not allow such a declaration since the pattern in the left-hand side contains a defined function (
===Non-determinism===
Since Curry is able to solve equations containing function calls with unknown values, its execution mechanism is based on non-deterministic computations, similarly to logic programming. This mechanism supports also the definition of ''non-deterministic operations'', i.e., operations that delivers more than one result for a given input. The archetype of non-deterministic operations is the predefined infix operation
x ? y = x
x ? y = y
Thus, the evaluation of the expression
The rules defining
<source lang="haskell">
insert x ys = x : ys
insert x (y:ys) = y : insert x ys
</source>
an operation to insert an element into a list at an indeterminate position so that the operation
<source lang="haskell">
perm [] = []
|