Curry (programming language): Difference between revisions

Content deleted Content added
m Cut needless carriage return whitespace characters in sections: standardize, aid work via small screens.
Template:Infobox programming language, WP:REFerence WP:CITation parameters: reorders, update-standardizes, underscores > spaces, adds, fills, respaces, conform to master templates. MOS:BADEMPHASIS MOS:FONTSIZE MOS:SMALLFONT cuts. WP:LINKs: update-standardizes, needless: WP:PIPEs > WP:NOPIPEs, adds. Small WP:COPYEDITs WP:EoS: WP:TERSE, clarify.
Line 6:
|logo =
|paradigm = [[functional programming|functional]], [[logic programming|logic]], non-strict, modular
|year =
|designer = Michael Hanus, Sergio Antoy, et al.
|developer =
|released =
|latest_release_version = {{wikidata|property|reference|edit|P348|P548=Q2804309}}
|latest_release_datelatest release version = <small>({{wikidata|qualifierproperty|reference|edit|P348|P577P548=Q2804309}})</small>
|latest release date = ({{wikidata|qualifier|P348|P577}})
|latest_test_version =
|latest preview version =
|latest_test_date =
|latest preview date =
|typing = [[static typing|static]], [[strongStrong and weak typing|strong]], [[type inference|inferred]]
|implementations = [https://www.informatik.uni-kiel.de/~pakcs PAKCS] (with [[Prolog (programming language)|Prolog]] as the target), [http://danae.uni-muenster.de/curry/ mcc] (with [[C (programming language)|C]] as the target), [http://www-ps.informatik.uni-kiel.de/kics2/ KiCS2] (with [[Haskell (programming language)|Haskell]] as the target)
|dialects =
|influenced =
|influenced by = [[Haskell (programming language)|Haskell]] and, [[Prolog (programming language)|Prolog]]
|operating_system = portable[[Cross-platform software|Cross-platform]]
|license =
|website = [https://curry.pages.ps.informatik.uni-kiel.de/curry-lang.org/ Curry]
}}
 
'''Curry''' is an experimental [[functional logic programming]] language,<ref>{{cite web |editor-last=Hanus |editor-first=Michael |title=Curry: A Truly Integrated Functional Logic Language |url=http://www.curry-lang.org/}}</ref><ref>{{cite journal |last1=Sergio |first1=Antoy |last2=Hanus |first2=Michael |year=2010 |title=Functional Logic Programming |journal=Communications of the ACM |volume=53 |issue=4 |pages=74–85 |publisher=ACM |doi=10.1145/1721654.1721675 |s2cid=14578759}}</ref> based on the [[Haskell]] language. It merges elements of functional and logic programming,<ref name="Curry and Curl programming languages">
'''Curry'''<ref>{{cite web
}}</ref> based on the [[Haskell (programming language)|Haskell]] language. It merges elements of functional and logic programming,<ref name="Curry and Curl programming languages">{{cite web |title=Curry experimental programming language |url=https://www.mvps.net/docs/curry-and-curl-programming-languages |website=MVPS.net |access-date=2 September 2021}}</ref> including [[constraint programming]] integration.
| editor = Michael Hanus
| title = Curry: A Truly Integrated Functional Logic Language
| url = http://www.curry-lang.org/
}}</ref> is an experimental [[functional logic programming]] language,<ref>{{cite journal
| author = Sergio Antoy and Michael Hanus
| title = Functional Logic Programming
| journal = Communications of the ACM
| volume = 53
| issue = 4
| pages = 74–85
| publisher = ACM
| year = 2010
| doi = 10.1145/1721654.1721675
| s2cid = 14578759
}}</ref> based on the [[Haskell (programming language)|Haskell]] language. It merges elements of functional and logic programming,<ref name="Curry and Curl programming languages">{{cite web |title=Curry experimental programming language |url=https://www.mvps.net/docs/curry-and-curl-programming-languages |website=MVPS.net |access-date=2 September 2021}}</ref> including [[constraint programming]] integration.
 
It is nearly a superset of Haskell, lacking support mostly for overloading using [[Polymorphism (computer science)#Subtyping|type classes]], which some implementations provide anyway as a language extension, such as the Münster Curry Compiler.<ref>[http://danae.uni-muenster.de/curry/ The Münster Curry Compiler]</ref>
 
==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 (with regard to 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
Line 56 ⟶ 43:
'double (1+2)' → (1+2)+'(1+2)' → '(1+2)'+3 → '3+3' → 6
 
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 effect (computer science)|side effects]]. This simplifies the reasoning about, and maintenance ofmaintaining, pure functional programs.
 
As many functional languages like [[haskell (programming language)|Haskell]] do, Curry supports the definition of [[algebraic data type]]s by enumerating their constructors. For instance, the type of Boolean values consists of the constructors {{Mono|True}} and {{Mono|False}} that are declared as follows:
<syntaxhighlight lang="haskell">
data Bool = True | False
Line 71 ⟶ 58:
not '(not False)' → 'not True' → False
 
More complex [[data structuresstructure]]s can be obtained by [[recursive data type]]s. For instance, a list of elements, where the type of elements is arbitrary (denoted by
the type variable {{Mono|a}}), is either the empty list “{{Mono|[]}}” or the non-empty list “{{Mono|x:xs}}” consisting of a first element {{Mono|x}} and a list {{Mono|xs}}:
<syntaxhighlight lang="haskell">
Line 91 ⟶ 78:
 
===Narrowing===
Narrowing is a mechanism whereby a variable is [[name binding|bound]] to a value selected from among alternatives imposed by constraints. Each possible value is tried in some order, with the remainder of the program invoked in each case to determine the validity of the binding. Narrowing is an extension of logic programming, in that it performs a similar search, but can actually generate values as part of the search rather than just being limited to testing them.
 
Narrowing is useful because it allows a function to be treated as a relation: its value can be computed "in both directions". The Curry examples of the previous section illustrate this.
 
As noted in the previousprior section, narrowing can be thought of as reduction on a program term graph, and there are often many different ways (''strategies'') to reduce a given term graph. Antoy et al.<ref>{{cite journal
| author last1= Sergio |first1=Antoy, Rachid |last2=Echahed and Michael|first2=Rachid |last3=Hanus |first3=Michael
| title = A Needed Narrowing Strategy
| journal = Journal of the ACM
| volume = 47
| issue = 4
| pages = 776–822
| publisher = ACM
| year = 2007
| issn = 0004-5411
| doi = 10.1145/347476.347484
| s2cid = 47275506
}}</ref> proved in the 1990s that a particular narrowing strategy, ''needed narrowing'', is optimal in the sense of doing a number of reductions to get to a "normal form" corresponding to a solution that is minimal among sound and complete strategies. Needed narrowing corresponds to a lazy strategy, in contrast to the [[SLD resolution|SLD-resolution]] strategy of [[Prolog]].
 
===Functional patterns===
Line 114 ⟶ 101:
last (ys++[e]) = e
</syntaxhighlight>
Haskell does not allow such a declaration since the pattern in the left-hand side contains a defined function ({{Mono|++}}). Such a pattern is also called ''functional pattern''.<ref>{{cite journal |last1=Sergio |first1=Antoy |last2=Hanus |first2=Michael |year=2006 |doi=10.1007/11680093_2 | title=Declarative Programming with Function Patterns | year=2006 | journal=Lecture Notes in Computer Science | volume=3901 | pages=6–22 | author=Antoy Sergio, Hanus Michael| isbn=978-3-540-32654-0 }}</ref> Functional patterns are enabled by the combined functional and logic features of Curry and support concise definitions of tasks requiring deep pattern matching in hierarchical data structures.
 
===Non-determinism===
Line 122 ⟶ 109:
x ? y = y
 
Thus, the evaluation of the expression {{Mono|0 ? 1}} returns {{Mono|0}} as well as {{Mono|1}}. Computing with non-deterministic operations and computing with free variables by narrowing has the same expressive power.<ref>{{cite journal |last1=Sergio |first1=Antoy |last2=Hanus |first2=Michael |year=2006 |doi=10.1007/11799573_9 | title=Overlapping Rules and Logic Variables in Functional Logic Programs | year=2006 | journal=Lecture Notes in Computer Science | volume=4079 | pages=87–101 | author=Antoy Sergio, Hanus Michael| isbn=978-3-540-36635-5 }}</ref>
 
The rules defining {{Mono|?}} show an important feature of Curry: all rules are tried in order to evaluate some operation. Hence, one can define by
Line 140 ⟶ 127:
 
==References==
{{reflistReflist}}
 
==External links==
Line 146 ⟶ 133:
*[http://smap.informatik.uni-kiel.de/ Smap] - A web-based execution environment for Curry and Haskell with various example programs
*[http://danae.uni-muenster.de/curry/ MCC] - The Münster Curry Compiler, which uses [[C (programming language)|C]] as the target
*[http://www.informatik.uni-kiel.de/~pakcs/ PAKCS] A major Curry implementation with a WWW interface, which uses [[Prolog (programming language)|Prolog]] as the target
*[http://www-ps.informatik.uni-kiel.de/kics2/ KiCS2] A Curry implementation, which uses [[Haskell (programming language)|Haskell]] as the target
*[https://www-ps.informatik.uni-kiel.de/currywiki/documentation/mailing Curry Mailing List]
*[http://www.informatik.uni-kiel.de/~mh Michael Hanus's home page]
* ''[http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.148.524 Purely Functional Lazy Non-deterministic Programming]'' (Fischer, Kiselyov, Shan, 2009), ''[http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.157.4578 Transforming Functional Logic Programs into Monadic Functional Programs]'' (Braßel, Fischer, Hanus, Reck, 2010) on modeling lazy non-deterministic (logic) programming (like in Curry) in a purely functional language ([[Haskell (programming language)|Haskell]]); such approach might give the programmer more flexibility in the control over the strategies that—in the case of Curry—are built-in.
 
{{Authority control}}