{"title":"GADTs are not (Even partial) functors","authors":"Pierre Cagne, Enrico Ghiorzi, Patricia Johann","doi":"10.1017/s0960129524000161","DOIUrl":null,"url":null,"abstract":"<jats:italic>Generalized Algebraic Data Types</jats:italic> (GADTs) are a syntactic generalization of the usual algebraic data types (ADTs), such as lists, trees, etc. ADTs’ standard initial algebra semantics (IAS) in the category <jats:inline-formula> <jats:alternatives> <jats:inline-graphic xmlns:xlink=\"http://www.w3.org/1999/xlink\" mime-subtype=\"png\" xlink:href=\"S0960129524000161_inline1.png\"/> <jats:tex-math> $\\mathit{Set}$ </jats:tex-math> </jats:alternatives> </jats:inline-formula> of sets justify critical syntactic constructs – such as recursion, pattern matching, and fold – for programming with them. In this paper, we show that semantics for GADTs that specialize to the IAS for ADTs are necessarily unsatisfactory. First, we show that the functorial nature of such semantics for GADTs in <jats:inline-formula> <jats:alternatives> <jats:inline-graphic xmlns:xlink=\"http://www.w3.org/1999/xlink\" mime-subtype=\"png\" xlink:href=\"S0960129524000161_inline2.png\"/> <jats:tex-math> $\\mathit{Set}$ </jats:tex-math> </jats:alternatives> </jats:inline-formula> introduces <jats:italic>ghost</jats:italic> elements, i.e., elements not writable in syntax. Next, we show how such ghost elements break parametricity. We observe that the situation for GADTs contrasts dramatically with that for ADTs, whose IAS coincides with the parametric model constructed via their Church encodings in System F. Our analysis reveals that the fundamental obstacle to giving a functorial IAS for GADTs is the inherently partial nature of their map functions. We show that this obstacle cannot be overcome by replacing <jats:inline-formula> <jats:alternatives> <jats:inline-graphic xmlns:xlink=\"http://www.w3.org/1999/xlink\" mime-subtype=\"png\" xlink:href=\"S0960129524000161_inline3.png\"/> <jats:tex-math> $\\mathit{Set}$ </jats:tex-math> </jats:alternatives> </jats:inline-formula> with other categories that account for this partiality.","PeriodicalId":49855,"journal":{"name":"Mathematical Structures in Computer Science","volume":"19 1","pages":""},"PeriodicalIF":0.4000,"publicationDate":"2024-08-27","publicationTypes":"Journal Article","fieldsOfStudy":null,"isOpenAccess":false,"openAccessPdf":"","citationCount":"0","resultStr":null,"platform":"Semanticscholar","paperid":null,"PeriodicalName":"Mathematical Structures in Computer Science","FirstCategoryId":"94","ListUrlMain":"https://doi.org/10.1017/s0960129524000161","RegionNum":4,"RegionCategory":"计算机科学","ArticlePicture":[],"TitleCN":null,"AbstractTextCN":null,"PMCID":null,"EPubDate":"","PubModel":"","JCR":"Q4","JCRName":"COMPUTER SCIENCE, THEORY & METHODS","Score":null,"Total":0}
引用次数: 0
Abstract
Generalized Algebraic Data Types (GADTs) are a syntactic generalization of the usual algebraic data types (ADTs), such as lists, trees, etc. ADTs’ standard initial algebra semantics (IAS) in the category $\mathit{Set}$ of sets justify critical syntactic constructs – such as recursion, pattern matching, and fold – for programming with them. In this paper, we show that semantics for GADTs that specialize to the IAS for ADTs are necessarily unsatisfactory. First, we show that the functorial nature of such semantics for GADTs in $\mathit{Set}$ introduces ghost elements, i.e., elements not writable in syntax. Next, we show how such ghost elements break parametricity. We observe that the situation for GADTs contrasts dramatically with that for ADTs, whose IAS coincides with the parametric model constructed via their Church encodings in System F. Our analysis reveals that the fundamental obstacle to giving a functorial IAS for GADTs is the inherently partial nature of their map functions. We show that this obstacle cannot be overcome by replacing $\mathit{Set}$ with other categories that account for this partiality.
期刊介绍:
Mathematical Structures in Computer Science is a journal of theoretical computer science which focuses on the application of ideas from the structural side of mathematics and mathematical logic to computer science. The journal aims to bridge the gap between theoretical contributions and software design, publishing original papers of a high standard and broad surveys with original perspectives in all areas of computing, provided that ideas or results from logic, algebra, geometry, category theory or other areas of logic and mathematics form a basis for the work. The journal welcomes applications to computing based on the use of specific mathematical structures (e.g. topological and order-theoretic structures) as well as on proof-theoretic notions or results.