|
ABSTRACT
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.
REFERENCES
Note: OCR errors may be found in this Reference List extracted from the full text article. ACM has opted to expose the complete List rather than only correct and linked references.
| |
1
|
W. Burton, E. Meijer, P. Sansom, S. Thompson, and P.Wadler. Views: An extension to Haskell pattern matching, Oct. 1996. http://www.haskell.org/development/view.html.
|
 |
2
|
Kung Chen , Paul Hudak , Martin Odersky, Parametric type classes, Proceedings of the 1992 ACM conference on LISP and functional programming, p.170-181, June 22-24, 1992, San Francisco, California, United States
|
 |
3
|
|
| |
4
|
|
| |
5
|
J. Garrigue. Programming with polymorphic variants. In The 1998 ACM SIGPLAN Workshop on ML, Sept. 1998.
|
| |
6
|
J. Garrigue. Code reuse through polymorphic variants. In Workshop on Foundations of Software Engineering (FOSE) 2000, Nov. 2000.
|
| |
7
|
B. R. Gaster and M. P. Jones. A polymorphic type system for extensible records and variants. Technical Report Technical Report NOTTCS-TR-96-3, Computer Science, University of Nottingham, Nov. 1996.
|
| |
8
|
T. Hallgren. Fun with functional dependencies. In Proceedings of the Joint CS/CE Winter Meeting, pages 135--145, Jan. 2001. http://www.cs.chalmers.se/~hallgren/Papers/wm01.html.
|
| |
9
|
J. Hughes and J. Sparud. Haskell++: An object-oriented extension of Haskell. In Haskell Workshop 1995, 1995.
|
 |
10
|
|
| |
11
|
|
| |
12
|
M. P. Jones. Simplifying and improving qualified types. Research Report YALEU/DCS/RR-1040, Yale University, June 1994.
|
| |
13
|
M. P. Jones. Typing Haskell in Haskell. In Proceedings of the 1999 Haskell Workshop, pages 9--22, Oct. 1999.
|
| |
14
|
|
| |
15
|
K. Kagawa. Polymorphic variants in Haskell (prototype implementation), 2006. available from http://guppy.eng.kagawa-u.ac.jp/~kagawa/PVH.
|
 |
16
|
|
| |
17
|
K. Laufer. Type classes with existential types. Journal of Functional Programming, 6(3):485--517, May 1996.
|
 |
18
|
Sheng Liang , Paul Hudak , Mark Jones, Monad transformers and modular interpreters, Proceedings of the 22nd ACM SIGPLAN-SIGACT symposium on Principles of programming languages, p.333-343, January 23-25, 1995, San Francisco, California, United States
[doi> 10.1145/199448.199528]
|
 |
19
|
|
| |
20
|
|
| |
21
|
E. Meijer and K. Claessen. The design and implementation of Mondrian. In Proceedings of Haskell Workshop 1997, 1997.
|
 |
22
|
Todd Millstein , Colin Bleckner , Craig Chambers, Modular typechecking for hierarchically extensible datatypes and functions, Proceedings of the seventh ACM SIGPLAN international conference on Functional programming, p.110-122, October 04-06, 2002, Pittsburgh, PA, USA
|
| |
23
|
J. Nordlander. Polymorphic subtyping in O'Haskell. In Proc. the APPSEm Workshop on Subtyping and Dependent Types in Programming, 2000. Ponte de Lima, Portugal.
|
 |
24
|
Martin Odersky , Philip Wadler , Martin Wehr, A second look at overloading, Proceedings of the seventh international conference on Functional programming languages and computer architecture, p.135-146, June 26-28, 1995, La Jolla, California, United States
[doi> 10.1145/224164.224195]
|
 |
25
|
|
| |
26
|
S. Peyton Jones, J. Hughes, et al. Haskell 98: A Non-strict, Purely Functional Language, Feb. 1999. http://www.haskell.org/onlinereport/.
|
| |
27
|
S. Peyton Jones, M. Jones, and E. Meijer. Type classes: exploring the design space. In Haskell Workshop 1997, 1997.
|
| |
28
|
S. Peyton Jones and M. Shields. Lexically scoped type variables, 2004.
|
 |
29
|
Simon Peyton Jones , Dimitrios Vytiniotis , Stephanie Weirich , Geoffrey Washburn, Simple unification-based type inference for GADTs, Proceedings of the eleventh ACM SIGPLAN international conference on Functional programming, September 16-21, 2006, Portland, Oregon, USA
|
 |
30
|
|
 |
31
|
|
 |
32
|
|
| |
33
|
M. Zenger and M. Odersky. Independently extensible solutions to the expression problem. In Proceedings of the 12th International Workshop on Foundations of Object-Oriented Languages (FOOL 12), Jan. 2005.
|
|