Deprecated: The each() function is deprecated. This message will be suppressed on further calls in /home/zhenxiangba/zhenxiangba.com/public_html/phproxy-improved-master/index.php on line 456
Haskell's overlooked object system
[go: Go Back, main page]

Haskell's overlooked object system

Major new release, September 10, 2005
Authors
Oleg Kiselyov and Ralf Lämmel

Abstract
Haskell provides type-class-bounded and parametric polymorphism as opposed to subtype polymorphism of object-oriented languages such as Java and OCaml. It is a contentious question whether Haskell~98 without extensions, or with common extensions, or with new extensions can fully support conventional object-oriented programming with encapsulation, mutable state, inheritance, overriding, statically checked implicit and explicit subtyping, and so on.

In a first phase, we demonstrate how far we can get with object-oriented functional programming, if we restrict ourselves to plain Haskell~98. In the second and major phase, we systematically substantiate that Haskell~98, with some common extensions, supports all the conventional OO features plus more advanced ones, including first-class lexically scoped classes, implicitly polymorphic classes, flexible multiple inheritance, safe downcasts and safe co-variant arguments. Haskell indeed can support width and depth, structural and nominal subtyping. We address the particular challenge to preserve Haskell's type inference even for objects and object-operating functions. Advanced type inference is a strength of Haskell that is worth preserving. Many of the features we get ``for free'': the type system of Haskell turns out to be a great help and a guide rather than a hindrance.

The OO features are introduced in Haskell as the OOHaskell library, non-trivially based on the HList library of extensible polymorphic records with first-class labels and subtyping. The library sample code, which is patterned after the examples found in OO textbooks and programming language tutorials, including the OCaml object tutorial, demonstrates that OO code translates into OOHaskell in an intuition-preserving way: essentially expression-by-expression, without requiring global transformations.

OOHaskell lends itself as a sandbox for typed OO language design.

Keywords
Object-oriented functional programming, Object type inference, Typed object-oriented language design, Heterogeneous collections, ML-ART, Mutable objects, Type-Class-based programming, Haskell, Haskell~98, Structural subtyping, Duck typing, Nominal subtyping, Width subtyping, Deep subtyping, Co-variance

Bibtex entries
@unpublished{OOHaskell,
 author = "Oleg Kiselyov and Ralf L{\"a}mmel",
 title = "{Haskell's overlooked object system}",
 year = 2005,
 notes = "Draft; Submitted for journal publication; online since 30 Sep.\ 2004; Full version released 10 September 2005"
}

View draft paper

Download OOHaskell


Website maintained by Ralf Lämmel (Email: ralf@cwi.nl)