[Haskell-cafe] State of OOP in Haskell

Arie Peterson ariep at xs4all.nl
Mon Jan 29 09:14:33 EST 2007

Steve Downey wrote:

| OO, at least when done well, maps well to how people think. Things
| that can be directed to perform actions. There is also a well
| developed practice of OO analysis and design. It's not clear (at least
| to me) that there is an equivalent set of practices for functional
| programming.
| [...]
| The consensus answer to 'how do I implement my OO model in Haskell'
| seems to be 'you're asking the wrong question'. But what is the right
| question?

That's a good question. In fact, it may even be the right question.
(sorry, I'm having a bad week)

The OO viewpoint of "objects with associated actions" is not entirely
alien to Haskell/fp. Data types (abstract or concrete) are "classes of
objects"; the "associated actions" are the functions that process and
produce values of the given data type.

The nature of functions allows an "action" to be associated with more than
one object, relieving the programmer from a sometimes arbitrary choice:

> data Car = ...
> data Garage = ...
> repair :: Garage -> Car -> Car

Should the "repair" action be associated with the garage or with the car?
Well, with both, actually. (If this example does not convince you, you can
probably think of better ones yourself.)



More information about the Haskell-Cafe mailing list