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

Uniqueness type

In computing, a unique type guarantees that an object is used in a single-threaded way, with at most a single reference to it. If a value has a unique type, a function applied to it can be optimized to update the value in-place in the object code. Such in-place updates improve the efficiency of functional languages while maintaining referential transparency. Unique types can also be used to integrate functional and imperative programming.

Introduction

Uniqueness typing is best explained using an example. Consider a function readLine that reads the next line of text from a given file:

function readLine(File f) returns String
    return line where
        String line = doImperativeReadLineSystemCall(f)
    end
end

Now doImperativeReadLineSystemCall reads the next line from the file using an OS-level system call which has the side effect of changing the current position in the file. But this violates referential transparency because calling it multiple times with the same argument will return different results each time as the current position in the file gets moved. This in turn makes readLine violate referential transparency because it calls doImperativeReadLineSystemCall.

However, using uniqueness typing, we can construct a new version of readLine that is referentially transparent even though it's built on top of a function that's not referentially transparent:

function readLine2(unique File f) returns (unique File, String)
    return (differentF, line) where
        String line = doImperativeReadLineSystemCall(f)
        File differentF = newFileFromExistingFile(f)
    end
end

The unique declaration specifies that the type of f is unique; that is to say that f may never be referred to again by the caller of readLine2 after readLine2 returns, and this restriction is enforced by the type system. And since readLine2 does not return f itself but rather a new, different file object differentF, this means that it's impossible for readLine2 to be called with f as an argument ever again, thus preserving referential transparency while allowing for side effects to occur.

Programming languages

Uniqueness types are implemented in functional programming languages such as Clean, Mercury, SAC and Idris. They are sometimes used for doing I/O operations in functional languages in lieu of monads.

A compiler extension has been developed for the Scala programming language which uses annotations to handle uniqueness in the context of message passing between actors.[1]

Relationship to linear typing

A unique type is very similar to a linear type, to the point that the terms are often used interchangeably, but there is in fact a distinction: actual linear typing allows a non-linear value to be typecast to a linear form, while still retaining multiple references to it. Uniqueness guarantees that a value has no other references to it, while linearity guarantees that no more references can be made to a value.[2]

Linearity and uniqueness can be seen as particularly distinct when in relation to non-linearity and non-uniqueness modalities, but can then also be unified in a single type system. [3]

See also

References

  1. ^ Haller, P.; Odersky, M. (2010), "Capabilities for uniqueness and borrowing", ECOOP 2010—Object-Oriented Programming (PDF), pp. 354–378
  2. ^ Wadler, Philip (17–19 June 1991). Is there a use for linear logic?. ACM SIGPLAN symposium on partial evaluation and semantics-based program manipulation (PEPM '91). pp. 255–273. CiteSeerX 10.1.1.26.4202. doi:10.1145/115865.115894. ISBN 0-89791-433-3.
  3. ^ Marshall, Daniel; Vollmer, Michael; Orchard, Dominic (7 April 2022). Linearity and Uniqueness: An Entente Cordiale. ESOP'22. doi:10.1007/978-3-030-99336-8_13.

External links

Read other articles:

В Википедии есть статьи о других людях с такой фамилией, см. Дьяконов. Евгений Георгиевич Дьяконов Дата рождения 2 июля 1935(1935-07-02) Место рождения Невель, Великолукский округ, Калининская область, РСФСР, СССР Дата смерти 11 августа 2006(2006-08-11) (71 год) Место смерти Москва, Россия Ст

Keuskupan Agung Santiago de CompostelaArchidioecesis CompostellanaArquidiocese de Santiago de Compostela (Galisia)Archidiócesis de Santiago de Compostela (Spanyol)Katolik Katedral Santiago de CompostelaLokasiNegaraSpanyolProvinsi gerejawiSantiago de CompostelaStatistikLuas8.545 km2 (3.299 sq mi)Populasi- Total- Katolik(per 2010)1.301.1471,192,508 (91.7%)InformasiDenominasiKatolik RomaGereja sui iurisGereja LatinRitusRitus RomaPendirian5 Desember 1095 (sebagai …

Edificio Thomas Jefferson de la Biblioteca del Congreso de los Estados Unidos Una biblioteca legislativa o también llamada biblioteca parlamentaria o biblioteca del Congreso es un tipo de biblioteca especializada en la labor del poder legislativo de una entidad político-administrativa donde existe una legislatura, la cual puede ser de alcance nacional, subnacional o supranacional.[1]​ Su función en primera línea es apoyar en el desempeño de la institución de la cual depende, sea un c…

2007 summer concert tour American Idols Live! Tour 2007Tour by American IdolJordin Sparks, Chris Sligh, Blake Lewis, LaKisha JonesPhil Stacey, Sanjaya Malakar, Chris Richardson, Haley ScarnatoMelinda Doolittle, Gina GlocksenStart dateJuly 6, 2007End dateSeptember 23, 2007No. of shows59Box officeUS$23 million from 55 showsAmerican Idol concert chronology American Idols Live! Tour 2006 (2006) American Idols Live! Tour 2007 (2007) American Idols Live! Tour 2008 (2008) American Idols Live! Tour 2007…

Bengt Ingemar Samuelsson (1964) Bengt Ingemar Samuelsson (lahir 21 Mei 1934) ialah seorang biokimiawan Swedia. Ia lahir di Halmstad, Swedia selatan dan belajar di Universitas Stockholm, di mana ia menjadi profesor tahun 1967. Bersama Sune K. Bergström dan John Vane ia menerima Penghargaan Nobel dalam Fisiologi atau Kedokteran 1982 untuk penemuan prostaglandin dan zat terkait. Tentang peran prostaglandin dalam tubuh, Samuelsson menjelaskan, Prostaglandin merupakan sistem kontrol untuk sel yang i…

Calendar of saints in the Episcopal Church The veneration of saints in the Episcopal Church (United States) is a continuation of an ancient tradition from the early Church which honors important and influential people of the Christian faith. The usage of the term saint is similar to Roman Catholic and Orthodox traditions. Episcopalians believe in the communion of saints in prayer[1][2][3] and as such the Episcopal liturgical calendar accommodates feasts for saints.[4&…

У Вікіпедії є статті про інших людей із прізвищем Кроулі. Алістер Кровліангл. Aleister Crowley Ім'я при народженні Едуард Александр КровліПрізвисько the Beast 666[1]Псевдо H. D. Carr[2]Народився 12 жовтня 1875(1875-10-12)Лемінґтон,  Велика БританіяПомер 1 грудня 1947(1947-12-01) (72 роки)Гастінґс, &#…

Цзоганг Офіційна назва спр. китайська: 左贡县тиб. མཛོ་སྒང་རྫོང Країна  КНР Адміністративна одиниця Чамдо Кількість населення 44 320 осіб Адміністративно-територіально поділяється на Q11087286?, Q14290562?, Q11075840?, Q10869822?, Q10875699?, Meiyud, Zhalingkhad, Q14290749?, Q10883846?, R…

My Girl 2poster filmSutradara Howard Zieff Produser Brian Grazer Joseph M. Caracciolo David T. Friendly Ditulis oleh Laurice Elehwany PemeranDan AykroydJamie Lee CurtisAnna ChlumskyAustin O'BrienPenata musikCliff EidelmanSinematograferPaul ElliottDistributorColumbia PicturesTanggal rilis11 Februari 1994 (AS)Durasi99 menitNegara Amerika SerikatBahasa Inggris Anggarantidak diketahuiPendapatankotor$17,359,799 (AS)PrekuelMy Girl My Girl 2 adalah film Amerika Serikat tahun 1994 menampilkan…

Ghanaian food This article is an orphan, as no other articles link to it. Please introduce links to this page from related articles; try the Find link tool for suggestions. (June 2019) A picture of Gari and beans served with ripe plantain. Gari and beans is a type of dish made of staple foods in Ghana. It is usually common in the southern parts of Ghana popularly called bober, borbor[1] or gobɛ,[2] yo ke gari and even red red.[3] Ingredients beans (black eyed )[3]…

Fictional character from the BBC sitcom Fictional character ManuelFawlty Towers characterFirst appearance'A Touch of Class' (1975)Last appearanceWe Are Most Amused (2008)Created byJohn CleeseConnie BoothPortrayed byAndrew SachsIn-universe informationGenderMaleOccupationWaiterOriginBarcelona, SpainNationalitySpanish Manuel is a fictional character from the BBC sitcom Fawlty Towers, played by Andrew Sachs. He reappeared for a small sketch with John Cleese in We Are Most Amused in November 2008. Ma…

Video game series Monkey Ball redirects here. For other uses, see Monkey ball. Video game seriesSuper Monkey BallGenre(s) Platformer Party Developer(s)Amusement Vision (2000-2004)Sega (2005-2012)Marvelous AQL (2012-2018)Ryu Ga Gotoku Studio (2019-present)Publisher(s)SegaCreator(s)Toshihiro NagoshiPlatform(s)AndroidArcadeGameCubeGame Boy AdvanceiOSMicrosoft WindowsNintendo 3DSNintendo DSNintendo SwitchN-GagePlayStation 2PlayStation 4PlayStation 5PlayStation PortablePlayStation VitaWiiXboxXbox One…

Erica heliophila Klasifikasi ilmiah Kerajaan: Plantae Divisi: Tracheophyta Kelas: Magnoliopsida Ordo: Ericales Famili: Ericaceae Genus: Erica Spesies: Erica heliophila Nama binomial Erica heliophilaGuthrie & Bolus Erica heliophila adalah spesies tumbuhan yang tergolong ke dalam famili Ericaceae. Spesies ini juga merupakan bagian dari ordo Ericales. Spesies Erica heliophila sendiri merupakan bagian dari genus Erica.[1] Nama ilmiah dari spesies ini pertama kali diterbitkan oleh Guthrie…

مدار المريخ (النطاق الأصفر؛ يتراوح بين 1.381 و 1.666 وحدة فلكية) مع 6 مدارات ممكنة نظريا لكويكب (الخط الأحمر). مدار الكواكب الصغيرة العابرة لمدار المريخ في الصف السفلي على اليمين. من الناحية العامة فإن الكواكب الصغيرة العابرة لمدار المريخ لها حضيض أصغر وأكبر حجما مقارنة بالمريخ.وت

JinyeaLahirBae Jin Ye (배진예)9 Juni 1994 (umur 29)Bucheon, Gyeonggi-do, Korea SelatanPekerjaanPenyanyiTinggi169 cm (5 ft 7 in)Berat47 kg (104 pon) Jinyea (진예, lahir 9 Juni 1994) adalah seorang penyanyi Korea Selatan. Ia adalah anggota grup vokal perempuan LABOUM. Pada 2017, ia tampil sebagai perta dalam acara The Unit, dimana ia meraih peringkat #8, sehingga ia menjadi anggota grup proyek UNI.T.[1] Ia tampil dalam MV LC9 'Mama Beat' pada 2013 bersama…

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: The Aristos – news · newspapers · books · scholar · JSTOR (July 2017) (Learn how and when to remove this template message) First edition (Little Brown, 1964) The Aristos: A Self-Portrait in Ideas is a 1964 collection of several hundred philosophical aphorisms by E…

Municipal building in Stockport, Greater Manchester, England Stockport Town HallStockport town hallGeneral informationArchitectural styleEnglish Baroque styleClassification Listed Building – Grade II*Designated10 March 1975Reference no.1067166 Town or cityStockportCountryUnited KingdomCoordinates53°24′21″N 2°9′31″W / 53.40583°N 2.15861°W / 53.40583; -2.15861Inaugurated1908OwnerStockport councilHeight40 m (130 ft)Design and constructionArchitec…

American singer This article contains too many or overly lengthy quotations. Please help summarize the quotations. Consider transferring direct quotations to Wikiquote or excerpts to Wikisource. (July 2014) Silas Field Leachman (20 August 1859 – 28 April 1936) was an American pioneer recording artist, possibly the first person to make recordings in Chicago and known for making hundreds of thousands of phonograph cylinder recordings in the 1890s. Silas Leachman, ca. 1895, from Chicago Talki…

Samuel L. JacksonSamuel L. Jackson in Hollywood California - June 2019LahirSamuel Leroy Jackson21 Desember 1948 (umur 74)Washington, D.C., ASWarga negaraAmerika SerikatGabonAlmamaterMorehouse College (BA)PekerjaanAktorproduserTahun aktif1972–sekarangSuami/istriLaTanya Richardson ​(m. 1980)​Anak1 Samuel Leroy Jackson (lahir 21 Desember 1948) adalah Aktor dan produser Amerika. Salah satu aktor yang paling dikenal di generasinya, the film di mana dia telah m…

1955 British filmStolen TimeDirected byCharles DeaneWritten byCharles DeaneProduced byCharles DeaneStarringRichard ArlenSusan ShawVincent BallCinematographyGeoffrey FaithfullEdited byAdam DawsonProductioncompanyCharles Deane ProductionsDistributed byBritish Lion FilmsAllied Artists (US)Release dateOctober 1955Running time69 minutesCountryUnited KingdomLanguageEnglish Stolen Time is a 1955 British crime drama film directed by Charles Deane and starring Richard Arlen, Susan Shaw and Vincent Ball. …

Kembali kehalaman sebelumnya

Lokasi Pengunjung: 18.218.90.172