Type-indexed data types (original) (raw)
Related papers
Generic programming for indexed datatypes
2011
Abstract An indexed datatype is a type that uses a parameter as a type-level tag; a typical example is the type of vectors, which are indexed over a type-level natural number encoding their length. Since the introduction of generalised algebraic datatypes, indexed datatypes have become commonplace in Haskell. Values of indexed datatypes are often more involved than values of plain datatypes, and programmers would benefit from having generic programs on indexed datatypes.
Polytypic values possess polykinded types
2000
A polytypic value is one that is defined by induction on the structure of types. In Haskell types are assigned so-called kinds that distinguish between manifest types like the type of integers and functions on types like the list type constructor. Previous approaches to polytypic programming were restricted in that they only allowed to parameterize values by types of one fixed kind. In this paper we show how to define values that are indexed by types of arbitrary kinds.
PolyP---a polytypic programming language extension
1997
Many functions have to be written over and over again for di erent datatypes, either because datatypes change during the development of programs, or because functions with similar functionality are needed on di erent datatypes. Examples of such functions are pretty printers, debuggers, equality functions, uni ers, pattern matchers, rewriting functions, etc. Such functions are called polytypic functions. A polytypic function is a function that is de ned by induction on the structure of user-de ned datatypes. This paper extends a functional language (a subset of Haskell) with a construct for writing polytypic functions. The extended language type checks de nitions of polytypic functions, and infers the types of all other expressions using an extension of Jones' theories of quali ed types and higher-order polymorphism. The semantics of the programs in the extended language is obtained by adding type arguments to functions in a dictionary passing style. Programs in the extended language are translated to Haskell.
Typecase: A design pattern for type-indexed functions
2005
Abstract A type-indexed function is a function that is defined for each member of some family of types. Haskell's type class mechanism provides collections of open type-indexed functions, in which the indexing family can be extended by defining a new type class instance but the collection of functions is fixed. The purpose of this paper is to present TypeCase: a design pattern that allows the definition of closed type-indexed functions, in which the index family is fixed but the collection of functions is extensible.
Polyp - A Polytypic Programming Language
1997
Many functions have to be written over and over again for di erent datatypes, either because datatypes change during the development of programs, or because functions with similar functionality are needed on di erent datatypes. Examples of such functions are pretty printers, debuggers, equality functions, uni ers, pattern matchers, rewriting functions, etc. Such functions are called polytypic functions. A polytypic function is a function that is de ned by induction on the structure of user-de ned datatypes. This paper extends a functional language (a subset of Haskell) with a construct for writing polytypic functions. The extended language type checks de nitions of polytypic functions, and infers the types of all other expressions using an extension of Jones' theories of quali ed types and higher-order polymorphism. The semantics of the programs in the extended language is obtained by adding type arguments to functions in a dictionary passing style. Programs in the extended language are translated to Haskell.
2006
A generic function is defined by induction on the structure of types. The structure of a data type can be defined in several ways. For example, in PolyP a pattern functor gives the structure of a data type viewed as a fixed point, and in Generic Haskell a structural representation type gives an isomorphic type view of a data type in terms of sums of products. Depending on this generic view on the structure of data types, some generic functions are easier, more difficult, or even impossible to define.
Polymorphic typing of an algorithmic language
The polymorphic type discipline, as in the ML language, fits well within purely applicative languages, but does not extend naturally to the main feature of algorithmic languages: in-place update of data structures. Similar typing difficulties arise with other extensions of applicative languages: logical variables, communication channels, continuation handling. This work studies (in the setting of relational semantics) two new approaches to the polymorphic typing of these non-applicative features. The first one relies on a restriction of generalization over types (the notion of dangerous variables), and on a refined typing of functional values (closure typing). The resulting type system is compatible with the ML core language, and is the most expressive type systems for ML with imperative features proposed so far. The second approach relies on switching to ``by-name'' semantics for the constructs of polymorphism, instead of the usual ``by-value'' semantics. The resulting language differs from ML, but lends itself easily to polymorphic typing. Both approaches smoothly integrate non-applicative features and polymorphic typing. (English translation of \cite{Leroy-these}.)
Towards open type functions for Haskell
2007
We report on an extension of Haskell with type(-level) functions and equality constraints. We illustrate their usefulness in the context of phantom types, GADTs and type classes. Problems in the context of type checking are identified and we sketch our solution: a decidable type checking algorithm for a restricted class of type functions. Moreover, functional dependencies are now obsolete: we show how they can be encoded as type functions.
Generic Haskell: Practice and Theory
2003
Generic Haskell is an extension of Haskell that supports the construction of generic programs. These lecture notes describe the basic constructs of Generic Haskell and highlight the underlying theory.
Towards Open Type Functions for Haskell—DRAFT—
2007
We report on an extension of Haskell with type(-level) functions and equality constraints. We illustrate their usefulness in the context of phantom types, GADTs and type classes. Problems in the context of type checking are identified and we sketch our solution: a decidable type checking algorithm for a restricted class of type functions. Moreover, functional dependencies are now obsolete: we show how they can be encoded as type functions. This paper is submitted to the Implementing Functional Languages workshop, Sept 2007 (IFL07).