## A framework for extended algebraic data types (2006)

Venue: | In Proc. of FLOPS’06, volume 3945 of LNCS |

Citations: | 22 - 9 self |

### BibTeX

@INPROCEEDINGS{Sulzmann06aframework,

author = {Martin Sulzmann and Jeremy Wazny and Peter J. Stuckey},

title = {A framework for extended algebraic data types},

booktitle = {In Proc. of FLOPS’06, volume 3945 of LNCS},

year = {2006},

pages = {47--64},

publisher = {Springer-Verlag}

}

### OpenURL

### Abstract

Abstract. There are a number of extended forms of algebraic data types such as type classes with existential types and generalized algebraic data types. Such extensions are highly useful but their interaction has not been studied formally so far. Here, we present a unifying framework for these extensions. We show that the combination of type classes and generalized algebraic data types allows us to express a number of interesting properties which are desired by programmers. We support type checking based on a novel constraint solver. Our results show that our system is practical and greatly extends the expressive power of languages such as Haskell and ML. 1

### Citations

354 | How to make ad-hoc polymorphism less ad hoc
- Wadler, Blott
- 1989
(Show Context)
Citation Context ... type. However, we have no knowledge about the actual type of x. Hence, function g1 should be rejected. In some subsequent work, Läufer [Läu96] considers a combination of singleparameter type classes =-=[WB89]-=- and existential types. Consider class Key a where getKey::a->Int data KEY2 = forall a. Key a => Mk2 a g2 (Mk2 x) = getKey x where the class declaration introduces a single-parameter type class Key wi... |

319 | System description: Twelf — a meta-logical framework for deductive systems - Pfenning, Schürmann |

227 |
Unification revisited
- Lassez, Maher, et al.
- 1987
(Show Context)
Citation Context ...) = fv([b/a]o) − {b} where b is a fresh variable and [b/a] a renaming. We generally assume that the reader is familiar with the concepts of substitutions, unifiers, most general unifiers (m.g.u.) etc =-=[LMM87]-=- and first-order logic [Sho67]. We write [t/a] to denote the simultaneous substitution of variables ai by types ti for i = 1, .., n. Sometimes, we write o1 ≡ o2 to denote syntactic equivalence between... |

199 | Constraint handling rules
- Frühwirth
- 1995
(Show Context)
Citation Context ...via CHRs as we will see shortly. Though, we may make use of the functional dependency notation in example programs. Following our earlier work [SS05,DJSS04] we employ Constraint Handling Rules (CHRs) =-=[Frü95]-=- as the internal formalism to describe the valid type class relations. E.g., each declaration instance C ′ ⇒ T C ¯t is described by the simplification rule T C ¯t ⇐⇒ C ′ whereas type improvement condi... |

165 | Simple unification-based type inference for GADTs
- Vytiniotis, Weirich, et al.
(Show Context)
Citation Context ...>[a]->[a] double t l = map (\x-> case t of I -> x+x) l (roughly) elaboration yields data T = (a=Int) => I double::T a->[a]->[a] double t l = map ((\x-> case t of I -> x+x)::a->a) l GHC GADT inference =-=[PDWW05]-=-: Successful for the following variant data T = (a=Int) => I double::T a->[a]->[a] double t l = map (\x::a-> case t of I -> x+x) l A Framework for Extended Algebraic Data Types – p.30sRelated Work (Ty... |

162 | Type classes with functional dependencies
- Jones
- 2000
(Show Context)
Citation Context ...is for type classes with extensions. The consequence is that we cannot fully mimic GADTs via the combination of multi-parameter type classes [JJM97] with existential types and functional dependencies =-=[Jon00]-=-. We elaborate on this issue in more detail. The following program is accepted in GHC. class IsInt a b | ->a instance IsInt Int b class IsPair a b c | b c->a instance IsPair (b,c) b c data Term2 a = f... |

140 | Domain specific embedded compilers
- Leijen, Meijer
- 1999
(Show Context)
Citation Context ...hM x s) x: a Stack s : Stack a s : s StackM s a ⊃ StackM s a A Framework for Extended Algebraic Data Types – p.11sGeneralized Algebraic Data Types Enforce data invariants via types: Leijen and Meijer =-=[LM99]-=- Okasaki [Oka99] Cheney and Hinze [CH02] Baars and Swierstra [BS02] and of course Kiselyov! “Generalized” algebraic data types: Index types (Zenger [Zen99], Xi) Guarded recursive data types (Xi, Chen ... |

135 | Guarded recursive datatype constructors
- Xi, Chen, et al.
- 2003
(Show Context)
Citation Context ...94] consider the addition of (boxed) existential types whereas Läufer [Läu96] was the first to introduce a combination of single-parameter type classes and existential types [LO94]. Xi, Chen and Chen =-=[XCC03]-=- introduced yet another extension of algebraic data types known as guarded recursive data types (GRDTs). GRDTs are largely equivalent to Cheney’s and Hinze’s firstclass phantom types [CH03] and Peyton... |

133 |
Qualified Types: Theory and Practice
- Jones
- 1994
(Show Context)
Citation Context ...pe system has an additional typing rule to change the type of expressions under type equation assumptions (see upcoming rule (Eq) in Figure 2). Such a rule is lacking in the theory of qualified types =-=[Jon92]-=- which provides the basis for type classes with extensions. The consequence is that we cannot fully mimic GADTs via the combination of multi-parameter type classes [JJM97] with existential types and f... |

109 | First-class phantom types
- Cheney, Hinze
- 2003
(Show Context)
Citation Context ... and Chen [XCC03] introduced yet another extension of algebraic data types known as guarded recursive data types (GRDTs). GRDTs are largely equivalent to Cheney’s and Hinze’s firstclass phantom types =-=[CH03]-=- and Peyton Jones’s, Washburns’ and Weirich’s generalized algebraic data types (GADTs) [JWW04]. 4 All these extensions are very interesting but have largely been studied independently. Here, we presen... |

98 | Type classes: exploring the design space
- Jones, Jones, et al.
- 1997
(Show Context)
Citation Context ...he theory of qualified types [Jon92] which provides the basis for type classes with extensions. The consequence is that we cannot fully mimic GADTs via the combination of multi-parameter type classes =-=[JJM97]-=- with existential types and functional dependencies [Jon00]. We elaborate on this issue in more detail. The following program is accepted in GHC. class IsInt a b | ->a instance IsInt Int b class IsPai... |

97 | The Coq proof assistant reference manual : Version 6.1 - Barras, Boutin, et al. - 1997 |

96 | Type inference with constrained types. Theory and Practice of Object Systems - Odersky, Sulzmann, et al. - 1999 |

94 | Operational semantics and confluence of constraint propagation rules
- Abdennadher
(Show Context)
Citation Context ...o C ′ . CHRs are applied exhaustively, being careful not to apply propagation rules twice on the same constraints (to avoid infinite propagation). For more details on avoiding re-propagation see e.g. =-=[Abd97]-=-. We say a set P of CHRs is terminating if for each C there exists C ′ such that C ↣ ∗ P C′ . We repeat the CHR soundness result [Frü95] which states that CHR rule applications perform equivalence tra... |

87 | Combining Programming with Theorem Proving
- Chen, Xi
- 2005
(Show Context)
Citation Context ...hburn and Weirich [JWW04] have added GADTs to GHC. However, GADTs and type classes do not seem to interact well in GHC. E.g., the examples from Section 4.1 are not typable. Sheard [She05] and Chen/Xi =-=[CX05]-=- have extended GADTs to allow users to specify their own program properties which previously required external proof systems such as [PS99,BBC + 96]. An interesting question is to what extent “extende... |

79 |
Associated type synonyms
- Chakravarty, Keller, et al.
- 2005
(Show Context)
Citation Context ...nslate instance bodies can be found elsewhere [SWP05]. 7sIn our source syntax, there is no explicit support for type improvement mechanisms such as functional dependencies [Jon00] or associated types =-=[CKJ05]-=-. Improvement conditions are encoded via CHRs as we will see shortly. Though, we may make use of the functional dependency notation in example programs. Following our earlier work [SS05,DJSS04] we emp... |

75 | A lightweight implementation of generics and dynamics
- Cheney, Hinze
- 2002
(Show Context)
Citation Context ...ckM s a ⊃ StackM s a A Framework for Extended Algebraic Data Types – p.11sGeneralized Algebraic Data Types Enforce data invariants via types: Leijen and Meijer [LM99] Okasaki [Oka99] Cheney and Hinze =-=[CH02]-=- Baars and Swierstra [BS02] and of course Kiselyov! “Generalized” algebraic data types: Index types (Zenger [Zen99], Xi) Guarded recursive data types (Xi, Chen and Chen [XCC03]) Generalized algebraic ... |

63 | Polymorphic type inference and abstract data types
- Läufer, Odersky
- 1994
(Show Context)
Citation Context ...ite functions which pattern match over user-definable types. There exist several extensions of algebraic data types which increase the expressiveness of the language significantly. Läufer and Odersky =-=[LO94]-=- consider the addition of (boxed) existential types whereas Läufer [Läu96] was the first to introduce a combination of single-parameter type classes and existential types [LO94]. Xi, Chen and Chen [XC... |

58 | A theory of overloading
- Stuckey, Sulzmann
(Show Context)
Citation Context ...assumption part (left-hand side of ⊃). For technical reasons, we need to ensure that type schemes ∀ā.C ⇒ t are in the (equivalent) normalized form ∀ā, b.C ∧ b = t ⇒ b where b is fresh. Details are in =-=[SS05]-=-. Note that there is no (Let) rule because we assume that all let-defined functions must be annotated with a type. The type checking problem says that for a given constraint C, environment Γ , express... |

58 | Typing dynamic typing
- Baars, Swierstra
- 2002
(Show Context)
Citation Context ...ework for Extended Algebraic Data Types – p.11sGeneralized Algebraic Data Types Enforce data invariants via types: Leijen and Meijer [LM99] Okasaki [Oka99] Cheney and Hinze [CH02] Baars and Swierstra =-=[BS02]-=- and of course Kiselyov! “Generalized” algebraic data types: Index types (Zenger [Zen99], Xi) Guarded recursive data types (Xi, Chen and Chen [XCC03]) Generalized algebraic data types (Peyton-Jones et... |

53 | Simplifying and improving qualified types
- Jones
- 1995
(Show Context)
Citation Context ...->n states that the first two parameters uniquely determine the third parameter. Hence, the Add type class behaves like a function. E.g., in case we encounter Add Zero m n the type n will be improved =-=[Jon95]-=- to m. We make use of the Add type class to refine the type of the append function. Thus, we can state the desired property that the length of the output list equals the sum of the length of the two i... |

51 | Wobbly types: type inference for generalised algebraic data types. Microsoft Research
- Jones, Washburn, et al.
- 2004
(Show Context)
Citation Context ...ecursive data types (GRDTs). GRDTs are largely equivalent to Cheney’s and Hinze’s firstclass phantom types [CH03] and Peyton Jones’s, Washburns’ and Weirich’s generalized algebraic data types (GADTs) =-=[JWW04]-=-. 4 All these extensions are very interesting but have largely been studied independently. Here, we present a system which unifies these seemingly unrelated extensions, something which has not been st... |

40 | Stratified type inference for generalized algebraic data types
- Pottier, Régis-Gianas
- 2006
(Show Context)
Citation Context ... constraints for type inference in an extension of Hindley/Milner with GADTs but did not give any checking method in the general form as stated here. In some subsequent work, Pottier and Régis-Gianas =-=[PRG06]-=- showed how to perform complete type checking for GADTs without implication constraints on the expense of demanding an excessive amount of type annotations. These annotations are inferred by an elabor... |

34 | Sound and decidable type inference for functional dependencies
- Duck, Jones, et al.
- 2004
(Show Context)
Citation Context ...of criteria (imposed on source EADT programs) such as the Haskell type class [Pey03] and Jones’s functional dependency restrictions [Jon00] which ensure termination of the resulting CHRs. We refer to =-=[DJSS04]-=- for more details. Though, termination does not ensure that type checking is complete. The problem is that type constraints arising out of the program text may be “ambiguous” which requires us to gues... |

30 | A General Framework for Hindley/Milner Type Systems with Constraints - Sulzmann - 2000 |

29 | Type classes with existential types
- Läufer
- 1996
(Show Context)
Citation Context ...several extensions of algebraic data types which increase the expressiveness of the language significantly. Läufer and Odersky [LO94] consider the addition of (boxed) existential types whereas Läufer =-=[Läu96]-=- was the first to introduce a combination of single-parameter type classes and existential types [LO94]. Xi, Chen and Chen [XCC03] introduced yet another extension of algebraic data types known as gua... |

29 | From fast exponentiation to square matrices: an adventure in types
- Okasaki
- 1999
(Show Context)
Citation Context ...ack s : Stack a s : s StackM s a ⊃ StackM s a A Framework for Extended Algebraic Data Types – p.11sGeneralized Algebraic Data Types Enforce data invariants via types: Leijen and Meijer [LM99] Okasaki =-=[Oka99]-=- Cheney and Hinze [CH02] Baars and Swierstra [BS02] and of course Kiselyov! “Generalized” algebraic data types: Index types (Zenger [Zen99], Xi) Guarded recursive data types (Xi, Chen and Chen [XCC03]... |

24 | Constraint-based type inference for guarded algebraic data types
- Simonet, Pottier
- 2005
(Show Context)
Citation Context ...ore, this rule plays a crucial role. Recall function append from Section 4.1 where in case of the second clause we find Add l m n, l = 6 Some formulations allow us to change the type of (sub)patterns =-=[SP05]-=-. This may matter if patterns are nested. For brevity, we neglect such an extension. Note that in case patterns are evaluated in a certain order, say from left-to-right, we can simply translate a nest... |

23 |
compiler home
- haskell
(Show Context)
Citation Context ...ping the body of a pattern clause. Here, we give excerpts of a standard program which defines a strongly-typed evaluator for a simple term language. We use the GADT notation as implemented in GHC 6.4 =-=[GHC]-=-. data Term a where Zero : Term Int Pair : Term b->Term c->Term (b,c) eval :: Term a -> a eval Zero = 0 eval (Pair t1 t2) = (eval t1, eval t2) The constructors of the above GADT Term a do not share th... |

23 |
Indizierte Typen
- Zenger
- 1998
(Show Context)
Citation Context ...t EADTs are a natural generalization of GADTs and types classes with extensions. By employing some type programming we can even mimic type properties which previously required special-purpose systems =-=[Zen99]-=-. Next, we take a look at the formal underpinnings of EADTs. 4.2 Expressions, Types and Constraints The syntax of programs can be found in Figure 1. We assume that K refers to constructors of user-def... |

22 | Putting Curry-Howard to work
- Sheard
- 2005
(Show Context)
Citation Context ...rk Peyton Jones, Washburn and Weirich [JWW04] have added GADTs to GHC. However, GADTs and type classes do not seem to interact well in GHC. E.g., the examples from Section 4.1 are not typable. Sheard =-=[She05]-=- and Chen/Xi [CX05] have extended GADTs to allow users to specify their own program properties which previously required external proof systems such as [PS99,BBC + 96]. An interesting question is to w... |

19 | Polymorphic typed defunctionalization - Pottier, Gauthier - 2004 |

18 | E.: Meta-programming with built-in type equality - Sheard, Pašalić - 2004 |

12 | Dynamic optimization for functional reactive programming using generalized algebraic data types - Nilsson - 2005 |

7 |
A systematic translation of guarded recursive data types to existential types
- Sulzmann, Wang
- 2004
(Show Context)
Citation Context ... with existential types (TCET): data Stack a = forall s. StackM s a => Stack s Generalized algebraic data types (GADT): data Exp a = (a=Int) => Zero | ... In fact, GADT can (almost) be encoded via ET =-=[SW04]-=- TCET can be encoded via GADT ... A Framework for Extended Algebraic Data Types – p.17sExtended Algebraic Data Types data T a1 ... am = forall b1,...,bn. C => K t1 ... tl | ... Constraints can be eith... |

5 |
ATS: A language to make typeful programming real and fun. http://www.cs.bu.edu/ hwxi/ATS/ATS.html
- Xi
(Show Context)
Citation Context ...ule StackM [a] a <==> True rule StackM [a] b ==> a=b CHRs for specifying type systems: [CF02, SS05, SS01]. A Framework for Extended Algebraic Data Types – p.18sSimulating Index Types Omega [She], ATS =-=[Xi]-=-: GADTs + user-specifiable properties. data List a n = n=Zero => Nil | forall m. n = Succ m => Cons a (List a m) kind Nat = Zero | Succ Nat add :: Nat -> Nat -> Nat add Zero m = m add (Succ l) m = Suc... |

4 | Fages, F.: Tclp: overloading, subtyping and parametric polymorphism made practical for constraint logic programming - Coquery - 2002 |

3 |
Lexically scoped type annotations. http://www.comp.nus.edu.sg/˜ sulzmann
- Sulzmann, Wazny
- 2005
(Show Context)
Citation Context ... tcdec ::= class T C ā where m :: C ⇒ t | instance C ⇒ T C ¯t CHRs R ::= rule T C1 t1, ..., T Cn tn ⇐⇒ C | rule T C1 t1, ..., T Cn tn =⇒ C Fig. 1. Syntax of Programs to sufficiently annotate programs =-=[SW05]-=-. We also omit un-annotated recursive function definitions, another straightforward extension. Our type language is standard. We assume that T ¯t refer to user-definable data types. We use common Hask... |

3 | A systematic approach in type system design based on Constraint Handling Rules - Stuckey, Sulzmann - 2001 |

1 |
P.J.Stuckey. Co-induction and type improvement in type class proofs. http://www.comp.nus.edu.sg/˜ sulzmann
- Sulzmann, Wazny
- 2005
(Show Context)
Citation Context ...for typing and translation programs. Hence, we ignore them for brevity. We also ignore the bodies of instance declarations. Details of how to type and translate instance bodies can be found elsewhere =-=[SWP05]-=-. 7sIn our source syntax, there is no explicit support for type improvement mechanisms such as functional dependencies [Jon00] or associated types [CKJ05]. Improvement conditions are encoded via CHRs ... |