ACM Home Page
Please provide us with feedback. Feedback
Polymorphic variants in Haskell
Full text PdfPdf (198 KB)
Source Haskell archive
Proceedings of the 2006 ACM SIGPLAN workshop on Haskell table of contents
Portland, Oregon, USA
SESSION: Session 2 table of contents
Pages: 37 - 47  
Year of Publication: 2006
ISBN:1-59593-489-8
Author
Koji Kagawa  RISE, Kagawa University, Takamatsu, Kagawa, JAPAN
Sponsors
SIGPLAN: ACM Special Interest Group on Programming Languages
ACM: Association for Computing Machinery
Publisher
ACM  New York, NY, USA
Bibliometrics
Downloads (6 Weeks): 14,   Downloads (12 Months): 60,   Citation Count: 1
Additional Information:

abstract   references   cited by   index terms   collaborative colleagues  

Tools and Actions: Request Permissions Request Permissions    Review this Article  
DOI Bookmark: Use this link to bookmark this Article: http://doi.acm.org/10.1145/1159842.1159848
What is a DOI?

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
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
19
 
20
 
21
E. Meijer and K. Claessen. The design and implementation of Mondrian. In Proceedings of Haskell Workshop 1997, 1997.
22
 
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
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
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.