頭等物件

頭等物件(英語:First-class object),在電腦科學中,指称支持其他实体通常能获得的所有运算的实体。这些运算典型的包括:在執行期創造,作為參數傳遞給其他函數,或存入一個變數[1]。將一個實體變為頭等物件的過程叫做「实化」(Reification)[2]

「頭等物件」這一名稱最早由克里斯托弗·斯特雷奇在1960年代發明,原稱「頭等公民」(First-class citizen),意指函數可作為電腦語言中的頭等公民。英文中也稱「First-class entity」或「First-class value」。

历史

头等对象和二等对象的概念,在1960年由克里斯托弗·斯特雷奇引入。[3][4] 实际上他并没有给出严格的术语定义,而是给出了ALGOL语言中实数和过程的对比:

头等对象和二等对象。在Algol程序语言中,一个“实数”可能会出现在一个表达式中或被赋给一个变量,并可能在过程调用中作为实际参数出现。而“过程”只可能会出现在另一个过程调用中,最常见的是作为操作符,有时候也作为实参。除此之外,没有表达式会涉及到过程,或者将过程作为计算结果。因此在某种意义上,在Algol程序语言中的过程是二等公民,它们总是会单独出现,不可能被一个表达式或一个变量表示(形式参数除外)…[5]

在1990年代,拉斐尔·芬克尔提出了二等值和三等值的定义[6],但这些定义尚未被广泛采用。[7]

定義

頭等物件不一定是物件導向程式設計所指的物件,而可以指任何程式中的實體。Robin Popplestone英语Robin Popplestone给出如下定义:

  1. 所有项目都有特定的基本权力。
  2. 所有项目都可以作为函数的实际参数。
  3. 所有项目都可以作为函数的结果返回。
  4. 所有项目都可以是赋值语句的主体。
  5. 所有项目都可以等式测试。[8]

範例

最简单的标量数据类型,比如整数和浮点数,几乎总是头等的。在很多较早的语言中,数组和字符串不是头等的:它们不能被作为赋值的对象,或作为形式参数传递给子例程。例如,FORTRAN IVC都不支持数组赋值,并且它们在作为形式参数传递的时候,实际上只有它们的第一个元素的位置被传递了,它们的大小失去了。C看起来支持数组指针的复制,但实际上它们只是到数组的第一个元素的指针,仍然不承载这个数组的大小。

不同語言中對函數的區別很大,例如C語言C++中的函數不是頭等物件,因為在這些語言中函數不能在執行期創造,而必須在設計時全部寫好。相比之下,Scheme中的函數是頭等物件,因為可以用lambda表达式來創造匿名函數並作為頭等物件來操作。

概念 描述 语言
头等函数 闭包匿名函数 Dart, Scheme, ML, Haskell, F#, Kotlin, Scala, Swift, Perl, PHP, Python, Raku, JavaScript, Delphi, Rust
头等控制 续体 Scheme, ML, F#
头等类型 依赖类型 Coq, Idris, Agda
头等数据类型 Generic Haskell, C++11
头等多态 非直谓多态
头等消息英语first-class message 动态消息(方法调用) Smalltalk[9], Objective-C[9], Common Lisp
头等类 元类 Smalltalk, Objective-C, Ruby, Python, Delphi, Common Lisp
头等证明 证明对象[10] Coq, Agda

参考文献

  1. ^ Scott, Michael. Programming Language Pragmatics. San Francisco, CA: Morgan Kaufmann Publishers. 2006: 140. 
  2. ^ J. Malenfant, M. Jacques and F.-N. Demers. A Tutorial on Behavioral Reflection and its Implementation. parc.com. [2010-10-09]. (原始内容存档于2010-05-28). 
  3. ^ Rod Burstall, "Christopher Strachey—Understanding Programming Languages", Higher-Order and Symbolic Computation 13:52 (2000)
  4. ^ Harold Abelson; Gerald Jay Sussman. 章节1.3.4 脚注64. Structure and Interpretation of Computer Programs [计算机程序的构造和解释] 2. [2015-03-03]. (原始内容存档于2015-03-09) (英语). 
  5. ^ Christopher Strachey, "Fundamental Concepts in Programming Languages" in Higher-Order and Symbolic Computation 13:11 (2000); though published in 2000, these are notes from lectures Strachey delivered in August, 1967
  6. ^ R. Finkel. Advanced Programming language Design. : 73 (英语). 
  7. ^ Norman Ramsey. About first-,second- and third-class value. Stackoverflow. [14 September 2013] (英语). 
  8. ^ R. J. Popplestone: The Design Philosophy of POP-2. in: D. Michie: Machine Intelligence 3, Edinburgh at the University Press, 1968
  9. ^ 9.0 9.1 Paritosh Shroff, Scott F. Smith. Type Inference for First-Class Messages with Match-Functions页面存档备份,存于互联网档案馆
  10. ^ Bove, Ana; Dybjer, Peter. Dependent Types at Work (PDF). Language Engineering and Rigorous Software Development. 2009, 5520: 57–99 [8 June 2015]. doi:10.1007/978-3-642-03153-3_2. (原始内容存档 (PDF)于April 2, 2014).  (also archived页面存档备份,存于互联网档案馆))


Read other articles:

Dan Hampton Hampton nel maggio 2008 Nazionalità  Stati Uniti Altezza 196 cm Peso 120 kg Football americano Ruolo Defensive tackle Squadra Ritirato Hall of fame Pro Football Hall of Fame (2002) Termine carriera 1990 Carriera Giovanili 1975 - 1978 Arkansas Razorbacks Squadre di club 1979-1990 Chicago Bears Statistiche Partite 157 Sack 82,0   Modifica dati su Wikidata · Manuale Daniel Oliver Hampton (Oklahoma City, 19 settembre 1957) è un ex giocatore di footbal...

 

KoboldIlustrasi koboldMakhluk dalam legendaNama lainCoboldKelompokMakhluk mitologis PeriAsalNegaraJermanHabitatrumah, tambang Kobold (kadang-kadang cobold) adalah makhluk legendaris supranatural dalam mitologi Jerman dan menjadi bagian dari folklor Jerman. Meskipun biasanya tidak terlihat, kobold dapat berwujud hewan, api, manusia, dan lilin. Penggambaran kobold paling umum adalah berwujud seperti manusia seukuran anak kecil. Kobold yang hidup di rumah manusia mengenakan pakaian petani, yang ...

 

Wikipedia bahasa DenmarkURLhttp://da.wikipedia.org/TipeProyek ensiklopedia internetPerdagangan ?BukanRegistration (en)OpsionalLangueBahasa DenmarkLisensiCreative Commons Atribusi-BerbagiSerupa 3.0 Tanpa Adaptasi dan Lisensi Dokumentasi Bebas GNU PemilikYayasan WikimediaService entry (en)1r Februari 2002 Wikipedia bahasa Denmark adalah wikipedia edisi bahasa Denmark. Pada tanggal 6 Juli 2011, wikipedia ini memiliki lebih dari 152.000 artikel. Di wikipedia ini, tidak terdapat ketentuan pe...

Chemical compound 3-BenzhydrylmorpholineIdentifiers IUPAC name 3-(Diphenylmethyl)morpholine CAS Number93406-27-0 YPubChem CID57466051ChemSpider27289065CompTox Dashboard (EPA)DTXSID60726714 Chemical and physical dataFormulaC17H19NOMolar mass253.345 g·mol−13D model (JSmol)Interactive image SMILES C1(C(C2=CC=CC=C2)C3NCCOC3)=CC=CC=C1 InChI InChI=1S/C17H19NO/c1-3-7-14(8-4-1)17(15-9-5-2-6-10-15)16-13-19-12-11-18-16/h1-10,16-18H,11-13H2Key:OVLYYUBKZWEOEQ-UHFFFAOYSA-N   (verify...

 

Abu Hudzaifah bin UtbahLahirHusyaim42 SHMeninggal12 H (usia 53-54 tahun)Sebab meninggalPertempuran YamamahOrang tuaUtbah bin Rabi'ah (bapak) Abu Hudzaifah bin Utbah (Arab: أبو حذيفة بن عتبةcode: ar is deprecated , lahir tahun 42 sebelum hijrah (578) - wafat 12 H (633)) adalah sahabat Nabi Muhammad.[1] Nama asli Abu Hudzaifah adalah Husyaim.[2] Ia adalah anak dari Utbah bin Rabi'ah, salah satu pemimpin Quraisy dan saudara laki-laki Hindun bin Utbah, istri da...

 

  لمعانٍ أخرى، طالع كوريا (توضيح).   هذه المقالة عن كوريا. لشبه الجزيرة، طالع شبه جزيرة كوريا. كوريا 한국 الأرض والسكان إحداثيات 38°19′00″N 127°14′00″E / 38.316666666667°N 127.23333333333°E / 38.316666666667; 127.23333333333  [1] المساحة 219،140 كم² نسبة المياه (%) 2.8 المركز الإداري بيو...

Election 1960 Massachusetts gubernatorial election ← 1958 November 8, 1960 1962 →   Nominee John A. Volpe Joseph D. Ward Party Republican Democratic Popular vote 1,269,295 1,130,810 Percentage 52.51% 46.79% County results Municipality resultsVolpe:      50–60%      60–70%      70–80%      80–90%Ward:      50–60%   ...

 

密西西比州 哥伦布城市綽號:Possum Town哥伦布位于密西西比州的位置坐标:33°30′06″N 88°24′54″W / 33.501666666667°N 88.415°W / 33.501666666667; -88.415国家 美國州密西西比州县朗兹县始建于1821年政府 • 市长罗伯特·史密斯 (民主党)面积 • 总计22.3 平方英里(57.8 平方公里) • 陸地21.4 平方英里(55.5 平方公里) • ...

 

United States historic placeJewell BuildingU.S. National Register of Historic PlacesOmaha Landmark LocationOmaha, NECoordinates41°16′46.56″N 95°56′48.59″W / 41.2796000°N 95.9468306°W / 41.2796000; -95.9468306Built1923[2]Built byLof, John & Sons, BuilderArchitectHenninger, F.A.Architectural styleColonial RevivalNRHP reference No.83001091[1]Significant datesAdded to NRHPJuly 21, 1983Designated OMALSeptember 9, 1980[...

Not to be confused with Bayview, Washington (disambiguation). CDP in Washington, United StatesBay View, WashingtonCDPLocation of Bay View, WashingtonCoordinates: 48°28′58″N 122°28′32″W / 48.48278°N 122.47556°W / 48.48278; -122.47556CountryUnited StatesStateWashingtonCountySkagitArea • Total1.6 sq mi (4.3 km2) • Land1.6 sq mi (4.3 km2) • Water0.0 sq mi (0.0 km2)Elevation23 ...

 

Artikel ini membutuhkan rujukan tambahan agar kualitasnya dapat dipastikan. Mohon bantu kami mengembangkan artikel ini dengan cara menambahkan rujukan ke sumber tepercaya. Pernyataan tak bersumber bisa saja dipertentangkan dan dihapus.Cari sumber: Lempeng Filipina – berita · surat kabar · buku · cendekiawan · JSTOR (Maret 2022) Lempeng FilipinaJenisMinorPerkiraan luas wilayah5.500.000 km2[1]Pergerakan1barat lautKecepatan148–84mm/tahunWilayahP...

 

Sejarah teori grup, sebuah domain matematika yang mempelajari grup dalam berbagai bentuknya, telah berevolusi dalam berbagai utas paralel. Ada tiga akar sejarah teori grup: teori persamaan aljabar, teori bilangan dan geometri.[1][2][3] Joseph Louis Lagrange, Niels Henrik Abel dan Évariste Galois adalah peneliti awal di bidang teori grup. Awal abad ke-19 Studi paling awal tentang kelompok seperti itu mungkin kembali ke karya Lagrange pada akhir abad ke-18. Namun, peker...

American college basketball season 2014–15 Indiana Hoosiers men's basketballNCAA tournament, round of 64ConferenceBig Ten ConferenceRecord20–14 (9–9 Big Ten)Head coachTom Crean (7th season)Assistant coaches Tim Buckley (7th season) Steve McClain (5th season) Chuck Martin (1st season) Home arenaAssembly HallSeasons← 2013–142015–16 → 2014–15 Big Ten Conference men's basketball standings vte Conf Overall Team W   L   PCT W   L   PCT...

 

Andrew Jackson Following is a list of all Article III United States federal judges appointed by President Andrew Jackson during his term of office.[1] In total Jackson appointed 23 Article III federal judges: 5 Justices to the Supreme Court of the United States and 18 judges to the United States district courts. John Catron was nominated to the United States Supreme Court by President Jackson on the final day of his presidency, March 3, 1837. The United States Senate confirmed the no...

 

American media conglomerate TKO Group Holdings, Inc.Trade nameTKOCompany typePublicTraded asNYSE: TKO (Class A)S&P 400 componentIndustryProfessional wrestlingMixed martial artsStreaming mediaPredecessorsWorld Wrestling Entertainment, Inc.ZuffaFoundedSeptember 12, 2023; 10 months ago (2023-09-12)FoundersAri Emanuel Vince McMahonHeadquarters707 Washington Blvd., Stamford, Connecticut, U.S.Area servedWorldwideKey peopleAri Emanuel (CEO & Executive Chairman)Mark Sha...

Location of Palau in the western Pacific The National Register of Historic Places in Palau contains six listed sites located in only four of the sixteen states of Palau.          This National Park Service list is complete through NPS recent listings posted July 19, 2024.[1] Listings Map all coordinates using OpenStreetMap Download coordinates as: KML GPX (all coordinates) GPX (primary coordinates) GPX (secondary coordinates) [2] Name on the Reg...

 

Canadian politician Libby DaviesCMDavies at the 2006 New Democratic Party federal convention in Quebec CityDeputy Leader of the New Democratic PartyIn office2007 – August 4, 2015Serving with Thomas Mulcair until 2012, then Megan Leslie and David Christopherson from 2012 to 2015LeaderJack LaytonThomas MulcairPreceded byBill BlaikieSucceeded byDavid ChristophersonShadow Minister for HealthIn officeMay 26, 2011 – January 22, 2015LeaderJack LaytonNycole TurmelThomas ...

 

New Zealand state-owned enterprise AsureQuality LimitedNative nameKaitiaki KaiCompany typePublic CompanyIndustryFood Quality AssurancePredecessorASURE New Zealand LimitedAgriQuality LimitedFoundedAuckland, New Zealand (2007 (2007))HeadquartersAuckland, New ZealandNumber of locations100Area servedNew ZealandAustraliaMalaysiaSingaporeIndonesiaThailandServicesFood AssuranceLaboratory TestingAnimal WelfareApicultureOwnerNew Zealand GovernmentNumber of employees1800Websitewww.asurequality.com...

Questa voce sull'argomento calciatori jugoslavi è solo un abbozzo. Contribuisci a migliorarla secondo le convenzioni di Wikipedia. Segui i suggerimenti del progetto di riferimento. Ratko ČolićNazionalità Jugoslavia Calcio RuoloDifensore Termine carriera1956 CarrieraSquadre di club1 1946-1956 Partizan110 (0) Nazionale 1949-1951 Jugoslavia14 (0) Palmarès  Olimpiadi ArgentoHelsinki 1952 1 I due numeri indicano le presenze e le reti segnate, per le sole partite di campio...

 

Intentional accumulation of items for later use This article is about the general gathering and storing of goods. For other uses, see Hoarding (disambiguation). Tape Hoarding Hoarding is the act of engaging in excessive acquisition of items that are not needed or for which no space is available.[1] Human hoarding An anti-hoarding, pro-rationing poster from the United States in World War II Civil unrest or the threat of natural disasters may lead people to hoard foodstuffs, water, gaso...