A simple technique for handling multiple polymorphism
OOPLSA '86 Conference proceedings on Object-oriented programming systems, languages and applications
Views: a way for pattern matching to cohabit with data abstraction
POPL '87 Proceedings of the 14th ACM SIGACT-SIGPLAN symposium on Principles of programming languages
Type checking records and variants in a natural extension of ML
POPL '89 Proceedings of the 16th ACM SIGPLAN-SIGACT symposium on Principles of programming languages
LFP '92 Proceedings of the 1992 ACM conference on LISP and functional programming
Design patterns: elements of reusable object-oriented software
Design patterns: elements of reusable object-oriented software
Monad transformers and modular interpreters
POPL '95 Proceedings of the 22nd ACM SIGPLAN-SIGACT symposium on Principles of programming languages
A polymorphic record calculus and its compilation
ACM Transactions on Programming Languages and Systems (TOPLAS)
FPCA '95 Proceedings of the seventh international conference on Functional programming languages and computer architecture
Modular object-oriented programming with units and mixins
ICFP '98 Proceedings of the third ACM SIGPLAN international conference on Functional programming
Extensible algebraic datatypes with defaults
Proceedings of the sixth ACM SIGPLAN international conference on Functional programming
Modular typechecking for hierarchically extensible datatypes and functions
Proceedings of the seventh ACM SIGPLAN international conference on Functional programming
Qualified types: theory and practice (ordering relation)
Qualified types: theory and practice (ordering relation)
Faking it Simulating dependent types in Haskell
Journal of Functional Programming
Strongly typed heterogeneous collections
Haskell '04 Proceedings of the 2004 ACM SIGPLAN workshop on Haskell
Open data types and open functions
Proceedings of the 8th ACM SIGPLAN international conference on Principles and practice of declarative programming
Simple unification-based type inference for GADTs
Proceedings of the eleventh ACM SIGPLAN international conference on Functional programming
Shared subtypes: subtyping recursive parametrized algebraic data types
Proceedings of the first ACM SIGPLAN symposium on Haskell
An error-tolerant type system for variational lambda calculus
Proceedings of the 17th ACM SIGPLAN international conference on Functional programming
Extending Type Inference to Variational Programs
ACM Transactions on Programming Languages and Systems (TOPLAS)
Hi-index | 0.00 |
In languages that support polymorphic variants, a single variant value can be passed to many contexts that accept different sets of constructors. Polymorphic variants can be used in order to introduce extensible algebraic datatypes into functional programming languages and are potentially useful for application domains such as interpreters, graphical user interface (GUI) libraries and database interfaces, where the number of necessary constructors cannot be determined in advance. Very few functional languages, however, have a mechanism to extend existing datatypes by adding new constructors. In general, for polymorphic variants to be useful, we would need some mechanisms to reuse existing functions and extend them for new constructors.Actually, the type system of Haskell, when extended with parametric type classes (or multi-parameter type classes with functional dependencies), has enough power not only to mimic polymorphic variants but also to extend existing functions for new constructors.This paper, first, explains how to do this in Haskell's type system (Haskell 98 with popular extensions). However, this encoding of polymorphic variants is difficult to use in practice. This is because it is quite tedious for programmers to write mimic codes by hand and because the problem of ambiguous overloading resolution would embarrass programmers. Therefore, the paper proposes an extension of Haskell's type classes that supports polymorphic variants directly. It has a novel form of instance declarations where records and variants are handled symmetrically.This type system can produce vanilla Haskell codes as a result of type inference. Therefore it behaves as a preprocessor which translates the extended language into plain Haskell. Programmers would be able to use polymorphic variants without worrying nasty problems such as ambiguities.