Curry (programming language)

Curry
Paradigmfunctional, logic, non-strict, modular
Designed byMichael Hanus, Sergio Antoy, et al.
DeveloperKiel University
Ludwig Maximilian University of Munich
University of Münster
Portland State University
Complutense University of Madrid
Technical University of Madrid
First appeared1995; 29 years ago (1995)
Stable release
3.6.0[1] Edit this on Wikidata / (10 November 2023)
Typing disciplinestatic, strong, inferred
Platformx86-64
OSCross-platform: Linux
LicenseBSD 3-clause
Websitecurry.pages.ps.informatik.uni-kiel.de/curry-lang.org
Major implementations
PAKCS (Prolog target), mcc (C target), KiCS2 (Haskell target)
Influenced by
Haskell, Prolog

Curry is a declarative programming language, an implementation of the functional logic programming paradigm,[2][3] and based on the Haskell language. It merges elements of functional and logic programming,[4] including constraint programming integration.

It is nearly a superset of Haskell but does not support all language extensions of Haskell. In contrast to Haskell, Curry has built-in support for non-deterministic computations involving search.

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

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 subexpressions 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, a property known as 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 reasoning about, and maintaining, pure functional programs.

As many 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

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 a), is either the empty list “[]” or the non-empty list “x:xs” consisting of a first element x and a list xs:

 data List a = [] | a : List a

The type “List a” is usually written as [a] and finite lists x1:x2:...:xn:[] are written as [x1,x2,...,xn]. We can define operations on recursive types by inductive definitions where pattern matching supports the convenient separation of the different cases. For instance, the concatenation operation “++” on polymorphic lists can be defined as follows (the optional type declaration in the first line specifies that “++” takes two lists as input and produces an output list, where all list elements are of the same unspecified type):

 (++) :: [a] -> [a] -> [a] 
 [] ++ ys = ys 
 (x:xs) ++ ys = x : xs++ys

Beyond its application for various programming tasks, the operation “++” is also useful to specify the behavior of other functions on lists. For instance, the behavior of a function last that yields the last element of a list can be specified as follows: for all lists xs and elements e, last xs = e if ∃ys:ys++[e] = xs.

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++[e] = [1,2,3] is solved by instantiating ys to the list [1,2] and e to the value 3. In Curry one can define the operation last as follows:

 last xs | ys++[e] =:= xs = e where ys,e free

Here, the symbol “=:=” is used for equational constraints in order to provide a syntactic distinction from defining equations. Similarly, extra variables (i.e., variables not occurring in the left-hand side of the defining equation) are explicitly declared by “where...free” in order to provide some opportunities to detect bugs caused by typos. A conditional equation of the form l | c = r is applicable for reduction if its condition c has been solved. In contrast to purely functional languages where conditions are only evaluated to a Boolean value, functional logic languages support the solving of conditions by guessing values for the unknowns in the condition. Narrowing as discussed in the next section is used to solve this kind of conditions.

Narrowing

Narrowing is a mechanism whereby a variable is 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 prior 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.[5] 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 strategy of Prolog.

Functional patterns

The rule defining last shown above expresses the fact that the actual argument must match the result of narrowing the expression ys++[e]. Curry can express this property also in the following more concise way:

 last (ys++[e]) = e

Haskell does not allow such a declaration since the pattern in the left-hand side contains a defined function (++). Such a pattern is also called functional pattern.[6] 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

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 ?, called choice operator, that returns one of its arguments. This operator is defined by the following rules:

 x ? y = x
 x ? y = y

Thus, the evaluation of the expression 0 ? 1 returns 0 as well as 1. Computing with non-deterministic operations and computing with free variables by narrowing has the same expressive power.[7]

The rules defining ? show an important feature of Curry: all rules are tried in order to evaluate some operation. Hence, one can define by

 insert x ys     = x : ys
 insert x (y:ys) = y : insert x ys

an operation to insert an element into a list at an indeterminate position so that the operation perm defined by

 perm []     = []
 perm (x:xs) = insert x (perm xs)

returns any permutation of a given input list.

Strategies

Due to the absence of side effects, a functional logic program can be executed with different strategies. To evaluate expressions, Curry uses a variant of the needed narrowing strategy which combines lazy evaluation with non-deterministic search strategies. In contrast to Prolog, which uses backtracking to search for solutions, Curry does not fix a particular search strategy. Hence, there are implementations of Curry, like KiCS2, where the user can easily select a search strategy, like depth-first search (backtracking), breadth-first search, iterative deepening, or parallel search.

References

  1. ^ "Current release:PAKCS Version 3.6.0 (10/11/23)". 10 November 2023. Retrieved 14 November 2023.
  2. ^ Hanus, Michael (ed.). "Curry: A Truly Integrated Functional Logic Language".
  3. ^ Sergio, Antoy; Hanus, Michael (2010). "Functional Logic Programming". Communications of the ACM. 53 (4). ACM: 74–85. doi:10.1145/1721654.1721675. S2CID 14578759.
  4. ^ "Curry experimental programming language". MVPS.net. Retrieved 2 September 2021.
  5. ^ Sergio, Antoy; Echahed, Rachid; Hanus, Michael (2007). "A Needed Narrowing Strategy". Journal of the ACM. 47 (4). ACM: 776–822. doi:10.1145/347476.347484. ISSN 0004-5411. S2CID 47275506.
  6. ^ Sergio, Antoy; Hanus, Michael (2006). "Declarative Programming with Function Patterns". Logic Based Program Synthesis and Transformation. Lecture Notes in Computer Science. Vol. 3901. pp. 6–22. doi:10.1007/11680093_2. ISBN 978-3-540-32654-0.
  7. ^ Sergio, Antoy; Hanus, Michael (2006). "Overlapping Rules and Logic Variables in Functional Logic Programs". Logic Programming. Lecture Notes in Computer Science. Vol. 4079. pp. 87–101. doi:10.1007/11799573_9. ISBN 978-3-540-36635-5.

Read other articles:

Bank Hapoalim B.M.Bank Hapoalim, Ra'ananaJenisPerusahaan PublikIndustriKeuangan, Jasa KeuanganDidirikan1921; 103 tahun lalu (1921)KantorpusatTel Aviv, IsraelTokohkunciDov Kotler, CEO Oded Eran, Ketua DewanProdukKartu kredit, perbankan konsumen, perbankan perusahaan, keuangan dan asuransi, perbankan investasi, pinjaman hipotek , perbankan swasta, ekuitas swasta, tabungan, surat berharga, manajemen asetPendapatanUS$$10.8 miliar (2021)[1]Laba bersihUS$684.6 miliar (2016)Total asetUS...

 

Santo Aleksander dari BergamoAleksander dari Bergamo, Bernardino Luini, pada sekitar tahun 1525.Meninggal~303 MDihormati diGereja Katolik RomaGereja Ortodoks TimurTempat ziarahRelik disimpan di kapel di kastil PescolancianoPesta26 Agustus (Katolik), 22 September (Ortodoks)AtributDigambarkan sebagai seorang prajurit; lambang militer menampilkan lili putihPelindungBergamo; Capriate San Gervasio; Cervignano d'Adda; Keuskupan Bergamo Wikimedia Commons memiliki media mengenai Alexander of Bergamo....

 

NenaLahirGabriele Susanne KernerTahun aktif1983PasanganBenedict Freitag (putus) Philipp PalmAnakChristopher Daniel Freitag (1988 - 1989) (kembar) Larissa Freitag dan Sakias Freitag (1990) Samuel Vincent Palm (1995) Simeon Joel Palm (1997)Orang tuaAlfons dan Ursula Kerner Untuk artis Indonesia dengan nama yang mirip, lihat: Nena Rosier. Nena (lahir 24 Maret 1960 di Hagen) merupakan seorang penyanyi berkebangsaan Jerman. Dia merupakan yang terkenal di grup musik Neue Deutsche Welle dengan...

العلاقات المجرية المالطية المجر مالطا   المجر   مالطا تعديل مصدري - تعديل   العلاقات المجرية المالطية هي العلاقات الثنائية التي تجمع بين المجر ومالطا.[1][2][3][4][5] مقارنة بين البلدين هذه مقارنة عامة ومرجعية للدولتين: وجه المقارنة المجر مالطا �...

 

20th Century Studios, Inc.SebelumnyaTwentieth Century Fox Film Corporation (20th Century Fox)(1935–2020)JenisAnak perusahaanIndustriFilmPendahulu Fox Film Twentieth Century Pictures Didirikan31 Mei 1935; 88 tahun lalu (1935-05-31)Pendiri William Fox Joseph M. Schenck Darryl F. Zanuck KantorpusatFox Studio Lot Building 88, 10201 West Pico Boulevard, Century City, Los Angeles, California, Amerika SerikatWilayah operasiSeluruh duniaProdukFilm, film televisiKaryawan2,300 (2018)IndukTh...

 

Синелобый амазон Научная классификация Домен:ЭукариотыЦарство:ЖивотныеПодцарство:ЭуметазоиБез ранга:Двусторонне-симметричныеБез ранга:ВторичноротыеТип:ХордовыеПодтип:ПозвоночныеИнфратип:ЧелюстноротыеНадкласс:ЧетвероногиеКлада:АмниотыКлада:ЗавропсидыКласс:Пт�...

Tibni (Ibrani: תִּבְנִי Tib-ni manusia jerami[1]) bin Ginat adalah satu dari 2 orang (calon lain: Omri) yang diangkat rakyat Israel untuk menjadi raja Kerajaan Israel (Samaria) menurut Alkitab Ibrani. Meskipun rakyat yang mengikuti Omri lebih kuat daripada rakyat yang mengikuti Tibni, baru setelah Tibni mati 5 tahun kemudian, Omri menjadi raja.[2] Tibni diduga berasal dari Yerahmeel, seperti saingannya, Omri.[3] Perhitungan waktu William F. Albright menulis...

 

Ettore De Michele Ettore De Michele intervistato nel 1990. Nazionalità  Italia Altezza 170 cm Peso 76 kg Calcio Ruolo Allenatore (ex portiere) Termine carriera 1918 - giocatore 19?? - allenatore Carriera Squadre di club1 1908-1918 SC Lecce4 (1, -14)[1] Carriera da allenatore 1908-19?? SC Lecce 1 I due numeri indicano le presenze e le reti segnate, per le sole partite di campionato.Il simbolo → indica un trasferimento in prestito.   Modifica dati su Wikidata...

 

Locale in Connemara, County Galway, Ireland This article needs additional citations for verification. Please help improve this article by adding citations to reliable sources. Unsourced material may be challenged and removed.Find sources: Maam Cross – news · newspapers · books · scholar · JSTOR (June 2020) (Learn how and when to remove this message) Townland in Connacht, IrelandMaam Cross an Teach DóiteTownlandHotel in Maam Cross, County GalwayMaam Cr...

この記事は検証可能な参考文献や出典が全く示されていないか、不十分です。出典を追加して記事の信頼性向上にご協力ください。(このテンプレートの使い方)出典検索?: コルク – ニュース · 書籍 · スカラー · CiNii · J-STAGE · NDL · dlib.jp · ジャパンサーチ · TWL(2017年4月) コルクを打ち抜いて作った瓶の栓 コルク(木栓、�...

 

2021 video game 2021 video gameCall of Duty: VanguardDeveloper(s) Sledgehammer Games[a] Publisher(s)ActivisionDirector(s)Dave SwensonJosh BridgeBen WanatGreg ReisdorfProducer(s)Mike SyrnykTrevor SchackMike MejiaAdam IscoveDesigner(s)Robert PittsZach HodsonEvan HortProgrammer(s)Robert FosterJason BellArtist(s)Joe SaludWriter(s)Stephen RhodesSam MaggsTochi OnyebuchiBrent V. FriedmanComposer(s)Bear McCreary[b]SeriesCall of DutyEngineIW 8.0Platform(s)PlayStation 4PlayStation 5Wind...

 

Atto unico europeoFirma17 febbraio 1986 LuogoLussemburgo (città), Lussemburgo Efficacia1º luglio 1987 Parti Italia Spagna Francia Portogallo Paesi Bassi Lussemburgo Belgio Germania Danimarca Grecia Regno Unito Irlanda FirmatariGermaniaPortogalloSpagnaGreciaRegno UnitoIrlandaDanimarcaRegno dei Paesi BassiLussemburgoFranciaBelgio e Italia DepositarioGoverno italiano voci di trattati presenti su Wikipedia L'Atto unico europeo è il tr...

Pagemaster - L'avventura meravigliosaUna scena del filmTitolo originaleThe Pagemaster Paese di produzioneStati Uniti d'America Anno1994 Durata80 min100 min (edizione argentina) Rapporto1,85:1 Genereanimazione, avventura, fantastico RegiaJoe Johnston (live-action), Pixote Hunt (animazione) SoggettoDavid Casci, David Kirschner SceneggiaturaDavid Casci, David Kirschner, Ernie Contreras ProduttoreDavid Kirschner, Paul Gertz Casa di produzioneTurner Pictures, 20th Century Fox Distribuzione...

 

Federal constituency of Selangor, Malaysia Sepang (P113) Selangor constituencyFederal constituencyLegislatureDewan RakyatMPAiman Athirah SabuPHConstituency created1958First contested1959Last contested2022DemographicsPopulation (2020)[1]384,244Electors (2023)[2]173,518Area (km²)[3]841Pop. density (per km²)456.9 Sepang is a federal constituency in Sepang District and Kuala Langat District, Selangor, Malaysia, that has been represented in the Dewan Rakyat since 1959. Th...

 

Don Toliver discographyToliver in 2017Studio albums3Singles25Mixtapes1Collaborative mixtapes1Music videos17 The discography of American rapper and singer Don Toliver consists of three studio albums, one collaborative album, two mixtapes, and 29 singles (including five as a featured artist). In 2018, Toliver was featured on his Cactus Jack Records label boss, Travis Scott's song, Can't Say, which debuted and peaked at number 38 on the Billboard Hot 100. Toliver released his debut studio album...

Ereck Flowers Flowers nel 2021 Nazionalità  Stati Uniti Altezza 196 cm Peso 149 kg Football americano Ruolo Offensive tackle Squadra Free agent CarrieraGiovanili 2012-2014 Miami HurricanesSquadre di club 2015-2018 New York Giants2018 Jacksonville Jaguars2019 Washington Redskins2020 Miami Dolphins2021 Washington Football Team Statistiche Partite 105 Partite da titolare 101 Statistiche aggiornate all'11 luglio 2023 Modifica dati su Wikidata · Manuale E...

 

Questa voce sull'argomento cestisti statunitensi è solo un abbozzo. Contribuisci a migliorarla secondo le convenzioni di Wikipedia. Segui i suggerimenti del progetto di riferimento. Ruth Riley Ruth Riley con le Detroit Shock Nazionalità  Stati Uniti Altezza 196 cm Peso 90 kg Pallacanestro Ruolo Centro Termine carriera 2014 Hall of fame Women's Basketball Hall of Fame (2019) CarrieraGiovanili North Miami Middle/High School1997-2001 N. Dame F. IrishSquadre di club 2001-20...

 

伊斯兰合作组织Organisation of Islamic Cooperation(英語)Organisation de la Coopération Islamique(法語)منظمة التعاون الإسلامي(阿拉伯語) 旗帜格言:To safeguard the interests and ensure the progress and well-being of Muslims  成员国  观察国  暂停会籍行政总部 沙地阿拉伯吉达 官方语言阿拉伯语英语法语类型宗教成员国57个在籍成员国(英语:Member states of the Organisation ...

For the seventh Lubavitcher Rebbe, see Menachem Mendel Schneerson. For the Tzemach Tzedek of Nikolsburg, see Menachem Mendel Krochmal. Third Chabad Rebbe (1789–1866) Menachem Mendel SchneersohnThe Tzemach TzedekTitleLubavitcher RebbePersonalBornMenachem Mendel SchneersohnSeptember 9, 1789 OSLiozna, Russian EmpireDiedMarch 17, 1866 OSLyubavichi, Russian EmpireReligionJudaismSpouseChaya Mushka Schneersohn (daughter of Dovber Schneuri)ChildrenBaruch ShalomYehudah Leib of KopysChaim Shneur Zalm...

 

Untuk yurisdiksi Kekaisaran Romawi Suci, lihat Kepangeranan-Keuskupan Verdun. Keuskupan VerdunDioecesis VirodunensisDiocèse de VerdunKatolik Katedral VerdunLokasiNegara PrancisProvinsi gerejawiBesançonStatistikLuas6.211 km2 (2.398 sq mi)Populasi- Total- Katolik(per 2014)197.700173,300 (87.7%)InformasiDenominasiKatolik RomaGereja sui iurisGereja LatinRitusRitus RomaPendirianDirestorasi pada 6 Oktober 1822KatedralKatedral Notre Dame de VerdunPelindungMa...