Hostname: page-component-89b8bd64d-9prln Total loading time: 0 Render date: 2026-05-09T13:01:23.801Z Has data issue: false hasContentIssue false

GADTs are not (Even partial) functors

Published online by Cambridge University Press:  27 August 2024

Pierre Cagne
Affiliation:
Department of Computer Science, Appalachian State University, Boone, NC, USA, Email: cagnep@appstate.edu
Enrico Ghiorzi
Affiliation:
Università degli Studi di Genova, Genova, Italy, Email: enrico.ghiorzi@edu.unige.it
Patricia Johann*
Affiliation:
Department of Computer Science, Appalachian State University, Boone, NC, USA, Email: cagnep@appstate.edu
*
Corresponding author: Patricia Johann; Email: johannp@appstate.edu
Rights & Permissions [Opens in a new window]

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.

Information

Type
Special Issue: LSFA 2021 and LSFA 2022
Creative Commons
Creative Common License - CCCreative Common License - BY
This is an Open Access article, distributed under the terms of the Creative Commons Attribution licence (http://creativecommons.org/licenses/by/4.0/), which permits unrestricted re-use, distribution and reproduction, provided the original article is properly cited.
Copyright
© The Author(s), 2024. Published by Cambridge University Press