GADTs are not (Even partial) functors

IF 0.4 4区 计算机科学 Q4 COMPUTER SCIENCE, THEORY & METHODS Mathematical Structures in Computer Science Pub Date : 2024-08-27 DOI:10.1017/s0960129524000161
Pierre Cagne, Enrico Ghiorzi, Patricia Johann
{"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":null,"pages":null},"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.
查看原文
分享 分享
微信好友 朋友圈 QQ好友 复制链接
本刊更多论文
GADT 不是(甚至不是部分)函数
广义代数数据类型(GADT)是通常代数数据类型(ADT)(如列表、树等)的语法广义化。ADTs 在集合类别 $\mathit{Set}$ 中的标准初始代数语义(IAS)证明了使用它们编程的关键语法结构--如递归、模式匹配和折叠--的合理性。在本文中,我们证明了专门针对 ADT 的 IAS 的 GADT 语义必然不能令人满意。首先,我们证明了$\mathit{Set}$中GADT的这种语义的函数性质会引入幽灵元素,即语法中不可写的元素。接下来,我们将展示这些幽灵元素是如何破坏参数性的。我们观察到,GADTs 的情况与 ADTs 形成了鲜明对比,后者的 IAS 与通过系统 F 中的 Church 编码构建的参数模型相吻合。我们的分析揭示出,为 GADTs 提供函数式 IAS 的根本障碍在于其映射函数的固有部分性。我们的分析表明,将 $\mathit{Set}$ 替换为其他考虑到这种片面性的范畴是无法克服这一障碍的。
本文章由计算机程序翻译,如有差异,请以英文原文为准。
求助全文
约1分钟内获得全文 去求助
来源期刊
Mathematical Structures in Computer Science
Mathematical Structures in Computer Science 工程技术-计算机:理论方法
CiteScore
1.50
自引率
0.00%
发文量
30
审稿时长
12 months
期刊介绍: 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.
期刊最新文献
On Hofmann–Streicher universes T0-spaces and the lower topology GADTs are not (Even partial) functors A linear linear lambda-calculus Countability constraints in order-theoretic approaches to computability
×
引用
GB/T 7714-2015
复制
MLA
复制
APA
复制
导出至
BibTeX EndNote RefMan NoteFirst NoteExpress
×
×
提示
您的信息不完整,为了账户安全,请先补充。
现在去补充
×
提示
您因"违规操作"
具体请查看互助需知
我知道了
×
提示
现在去查看 取消
×
提示
确定
0
微信
客服QQ
Book学术公众号 扫码关注我们
反馈
×
意见反馈
请填写您的意见或建议
请填写您的手机或邮箱
已复制链接
已复制链接
快去分享给好友吧!
我知道了
×
扫码分享
扫码分享
Book学术官方微信
Book学术文献互助
Book学术文献互助群
群 号:481959085
Book学术
文献互助 智能选刊 最新文献 互助须知 联系我们:info@booksci.cn
Book学术提供免费学术资源搜索服务,方便国内外学者检索中英文文献。致力于提供最便捷和优质的服务体验。
Copyright © 2023 Book学术 All rights reserved.
ghs 京公网安备 11010802042870号 京ICP备2023020795号-1