Share to: share facebook share twitter share wa share telegram print page

Polymorphic recursion

In computer science, polymorphic recursion (also referred to as MilnerMycroft typability or the Milner–Mycroft calculus) refers to a recursive parametrically polymorphic function where the type parameter changes with each recursive invocation made, instead of staying constant. Type inference for polymorphic recursion is equivalent to semi-unification and therefore undecidable and requires the use of a semi-algorithm or programmer-supplied type annotations.[1]

Example

Nested datatypes

Consider the following nested datatype in Haskell:

data Nested a = a :<: (Nested [a]) | Epsilon
infixr 5 :<:

nested = 1 :<: [2,3,4] :<: [[5,6],[7],[8,9]] :<: Epsilon

A length function defined over this datatype will be polymorphically recursive, as the type of the argument changes from Nested a to Nested [a] in the recursive call:

length :: Nested a -> Int
length Epsilon    = 0
length (_ :<: xs) = 1 + length xs

Note that Haskell normally infers the type signature for a function as simple-looking as this, but here it cannot be omitted without triggering a type error.

Higher-ranked types

Applications

Program analysis

In type-based program analysis polymorphic recursion is often essential in gaining high precision of the analysis. Notable examples of systems employing polymorphic recursion include Dussart, Henglein and Mossin's binding-time analysis[2] and the Tofte–Talpin region-based memory management system.[3] As these systems assume the expressions have already been typed in an underlying type system (not necessary employing polymorphic recursion), inference can be made decidable again.

Data structures, error detection, graph solutions

Functional programming data structures often use polymorphic recursion to simplify type error checks and solve problems with nasty "middle" temporary solutions that devour memory in more traditional data structures such as trees. In the two citations that follow, Okasaki (pp. 144–146) gives a CONS example in Haskell wherein the polymorphic type system automatically flags programmer errors.[4] The recursive aspect is that the type definition assures that the outermost constructor has a single element, the second a pair, the third a pair of pairs, etc. recursively, setting an automatic error finding pattern in the data type. Roberts (p. 171) gives a related example in Java, using a Class to represent a stack frame. The example given is a solution to the Tower of Hanoi problem wherein a stack simulates polymorphic recursion with a beginning, temporary and ending nested stack substitution structure.[5]

See also

Notes

  1. ^ Henglein 1993.
  2. ^ Dussart, Dirk; Henglein, Fritz; Mossin, Christian. "Polymorphic Recursion and Subtype Qualifications: Polymorphic Binding-Time Analysis in Polynomial Time". Proceedings of the 2nd International Static Analysis Symposium (SAS). CiteSeerX 10.1.1.646.5884.
  3. ^ Tofte, Mads; Talpin, Jean-Pierre (1994). "Implementation of the Typed Call-by-Value λ-calculus using a Stack of Regions". POPL '94: Proceedings of the 21st ACM SIGPLAN-SIGACT symposium on Principles of programming languages. New York, NY, USA: ACM. pp. 188–201. doi:10.1145/174675.177855. ISBN 0-89791-636-0.
  4. ^ Chris Okasaki (1999). Purely Functional Data Structures. New York: Cambridge. p. 144. ISBN 978-0521663502.
  5. ^ Eric Roberts (2006). Thinking Recursively with Java. New York: Wiley. p. 171. ISBN 978-0471701460.

Further reading

Polymorphic recursion
Polymorphic recursion

Read other articles:

Type of microphone design 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: Electret microphone – news · newspapers · books · scholar · JSTOR (September 2012) (Learn how and when to remove this template message) Electret condenser microphone capsules A typical electret microphone preamp circuit uses an FET in a c…

Sungai MuratEfrat TimurSungai MuratLokasiNegaraTurkiWilayahWilayah Anatolia TimurCiri-ciri fisikHulu sungai  - lokasidekat Gunung Ararat utara Danau Van - elevasi2.720 m (8.920 ft) Muara sungai  - lokasiKarasu dekat Keban, Provinsi Elazığ - elevasi820 m (2.690 ft)Panjang722 km (449 mi)Daerah Aliran SungaiSistem sungaiEfrat SumberMulut Lokasi sumber dan mulut Sungai Murat. Sungai Murat, juga disebut Efrat Timur (bah…

Imatynib Nazewnictwo Nomenklatura systematyczna (IUPAC) N-(4-metylo-3-{[4-(pirydyn-3-ylo)pirymidyn-2-ylo]amino}fenylo)-4-[(4-metylopiperazyn-1-ylo)metylo]benzamid Ogólne informacje Wzór sumaryczny C29H31N7O Masa molowa 493,60 g/mol Identyfikacja Numer CAS 152459-95-5 PubChem 5291 DrugBank DB00619 SMILES CC1=C(C=C(C=C1)NC(=O)C2=CC=C(C=C2)CN3CCN(CC3)C)NC4=NC=CC(=N4)C5=CN=CC=C5 InChI InChI=1S/C29H31N7O/c1-21-5-10-25(18-27(21)34-29-31-13-11-26(33-29)24-4-3-12-30-19-24)32-28(37)23-8-6-22(7…

Brasão de armas da Casa de Beaufort A Casa de Beaufort é uma família nobre britânica[1] , que se originou no século catorze e teve um importante papel na politica da Inglaterra no século seguinte [1] . O nome Beaufort refere-se a um castelo em Champagne, França (agora Montmorency-Beaufort), uma vez propriedade de João de Gaunte, 1.º Duque de Lencastre, terceiro filho deEduardo III. Origem A família é descendente de João Beaufort (1371-1410), filho de João de Gaunte com sua então am…

يفتقر محتوى هذه المقالة إلى الاستشهاد بمصادر. فضلاً، ساهم في تطوير هذه المقالة من خلال إضافة مصادر موثوق بها. أي معلومات غير موثقة يمكن التشكيك بها وإزالتها. (يناير 2022) فحص برادفورد للبروتين (بالإنجليزية: Bradford protein assay)‏ وهو إجراء عملية طيفية تحليلية لقياس تركيز البروتين في ال…

كورتينو     الإحداثيات 42°37′19″N 13°30′28″E / 42.62186°N 13.50774°E / 42.62186; 13.50774  [1] تقسيم إداري  البلد إيطاليا[2]  التقسيم الأعلى مقاطعة تِرامة  خصائص جغرافية  المساحة 62.95 كيلومتر مربع (9 أكتوبر 2011)[3]  ارتفاع 892 متر  عدد السكان  عدد السكان 631 (1…

Manuel PradoPresiden Peru ke-77Masa jabatan8 Desember 1939 – 28 Juli 1945PendahuluOscar R. BenavidesPenggantiJosé BustamantePresiden Peru ke-82Masa jabatan28 Juli 1956 – 18 Juli 1962PendahuluManuel A. OdríaPenggantiRicardo Pérez Godoy Informasi pribadiLahir(1889-04-21)21 April 1889Meninggal15 Agustus 1967(1967-08-15) (umur 78)Partai politikGerakan Demokratik PradistProfesiBankirSunting kotak info • L • B Manuel Prado y Ugarteche (21 April 1889 …

 Nota: Para outros usos, veja Batalha de Faluja. Batalha de Fallujah (2016) Guerra Civil Iraquiana Operações em Faluja em 22-23 de Maio[1][2][3] Data 22 de maio – 28 de junho de 2016 Local Faluja e Al-Karmah, Al-Anbar, Iraque Desfecho Vitória importante do governo iraquiano Mudanças territoriais Forças iraquianas recapturam toda a cidade de Faluja e seus subúrbios Beligerantes  Iraque Apoio:  Irã Coalizão (apoio aéreo)[4]  Estados Unidos  França  Reino U…

Hurfeish חֻרְפֵישׁ, חורפישحرفيشTranskripsi bahasa Ibrani • ISO 259Ḥurp̄eišHurfeishTampilkan peta Israel Barat LautHurfeishTampilkan peta IsraelKoordinat: 33°01′04″N 35°20′46″E / 33.01778°N 35.34611°E / 33.01778; 35.34611Koordinat: 33°01′04″N 35°20′46″E / 33.01778°N 35.34611°E / 33.01778; 35.34611Posisi kisi182/269 PALNegara IsraelDistrikUtaraPemerintahan • JenisD…

Head of state and head of government of Ghana President of theRepublic of GhanaPresidential Seal of GhanaPresidential Standard of GhanaIncumbentNana Akufo-Addosince 7 January 2017StyleHis/Her ExcellencyTypeHead of stateHead of governmentResidenceJubilee HouseTerm lengthFour years, renewable onceInaugural holderKwame NkrumahRepublic establishedJerry RawlingsCurrent ConstitutionFormationRepublic Day1 July 19601992 Constitution15 May 1992DeputyVice-President of GhanaSalary934,800 Ghanaian cedi…

2 Raja-raja 17Kitab Raja-raja (Kitab 1 & 2 Raja-raja) lengkap pada Kodeks Leningrad, dibuat tahun 1008.KitabKitab 2 Raja-rajaKategoriNevi'imBagian Alkitab KristenPerjanjian LamaUrutan dalamKitab Kristen12← pasal 16 pasal 18 → 2 Raja-raja 17 (atau II Raja-raja 17, disingkat 2Raj 17) adalah pasal ketujuh belas Kitab 2 Raja-raja dalam Alkitab Ibrani dan Perjanjian Lama di Alkitab Kristen. Dalam Alkitab Ibrani termasuk Nabi-nabi Awal atau Nevi'im Rishonim [נביאים ראשונים…

Local municipality in Gauteng, South AfricaRand West CityLocal municipality SealLocation of Rand West City Local Municipality within GautengCountrySouth AfricaProvinceGautengDistrictWest RandSeatRandfonteinBoroughs35Government • TypeMunicipal councilArea[1] • Total1,115 km2 (431 sq mi)Population (2011)[1] • Total261,053 • Density230/km2 (610/sq mi)Time zoneUTC+2 (SAST)Municipal codeGT485 Rand West City …

17e arrtPlace du Général-Kœnig Place du Général-Kœnig. Situation Arrondissement 17e Quartier Ternes Début Boulevard Pershing et boulevard d'Aurelle-de-Paladines Fin Avenue de la Porte-des-Ternes et boulevard Gouvion-Saint-Cyr Historique Dénomination 30 août 1978 Ancien nom Rond-point de la Révolte (Neuilly) Place Galliéni (Neuilly) Place de la Porte-des-Ternes Géocodification Ville de Paris 3991 DGI 4050 Géolocalisation sur la carte : Paris Place du Général-Kœnig Géolo…

American sprinter Gerry AshworthPersonal informationFull nameGerald Howard AshworthBornMay 1, 1942 (1942-05) (age 81)Haverhill, Massachusetts, U.S.EducationDartmouth College 1963, Harvard Business SchoolHeight180 cm (5 ft 11 in)Weight75 kg (165 lb)SpouseJeanne Leslie OshryChildren2SportClubSouthern California Striders (Anaheim)[1]Coached byElliot Noyes (Dartmouth)Achievements and titlesPersonal best(s)100y – 9.4 s (1962)100m – 10.3 s (1964) 220…

2002 studio album by Sonic YouthMurray Street2002 standard edition coverStudio album by Sonic YouthReleasedJune 25, 2002RecordedAugust 2001 – March 2002StudioEcho Canyon, New York City, U.S.Genre Alternative rock experimental rock noise rock Length45:37LabelDGCProducerSonic YouthSonic Youth chronology In the Fishtank 9(2001) Murray Street(2002) Sonic Nurse(2004) Sonic Youth studio album chronology NYC Ghosts & Flowers(2000) Murray Street(2002) Sonic Nurse(2004) Murray Street (somet…

1992 film by Albert Pyun 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: Nemesis 1992 film – news · newspapers · books · scholar · JSTOR (October 2010) (Learn how and when to remove this template message) NemesisPromotional film posterDirected byAlbert PyunWritten byRebecca Charles[1]Produced by Ti…

Early Christian era sarcophagus The so-called Sarcophagus of Stilicho is a marble Early Christian sarcophagus used since before the 10th-century as the base for the pulpit of the church of Sant'Ambrogio in Milan, Italy. It appears to have been made between 387 and 390, two decades before the namesake general Stilicho's death,[1] and is thus likely not associated with him. The sarcophagus probably does not contain the body of Stilicho.[2] Description The sarcophagus was carved fro…

Overview of religion within anarchismPart of a series onAnarchism History Outline Schools of thought Feminist Green Primitivist Social ecology Total liberation Individualist Egoist Free-market Naturist Philosophical Mutualism Postcolonial African Black Queer Religious Christian Jewish Social Collectivist Parecon Communist Magonism Without adjectives Methodology Agorism Illegalism Insurrectionary Communization Expropriative Pacifist Platformism Especifismo Relationship Syndicalist Synthesis Theor…

Not to be confused with Standard E1. Standard E-1 Standard E-1 of 1919 displayed in the Virginia Aviation Museum at Richmond, Virginia in USAAS markings Role Military trainerType of aircraft National origin United States of America Manufacturer Standard Aircraft Corporation First flight 1917 Primary user United States Army Air Service Number built 168 The Standard E-1 was an early American Army fighter aircraft, tested in 1917.[1] It was the only pursuit aircraft manufactured by the…

2023 Southampton City Council election ← 2022 4 May 2023 (2023-05-04) 2024 → All 51 seats to Southampton City Council26 seats needed for a majority   First party Second party   Leader Satvir Kaur Daniel Fitzhenry Party Labour Conservative Last election 26 seats, 46.7% 21 seats, 35.7% Seats before 26 20 Seats won 38 9 Seat change 12 12 Popular vote 62,447 45,785 Percentage 45.5% 33.4% Swing 1.2% 2.3%   Third party Fourth…

Kembali kehalaman sebelumnya

Lokasi Pengunjung: 3.142.133.226