[Haskell-cafe] I miss OO

Jason Dusek jason.dusek at gmail.com
Wed Nov 25 19:34:26 EST 2009

2009/11/25 Michael Mossey <mpm at alumni.caltech.edu>:
> I'm fairly new to Haskell, and starting to write some big
> projects.  Previously I used OO exclusively, mostly Python. I
> really miss the "namespace" capabilities... a class can have a
> lot of generic method names which may be identical for several
> different classes because there is no ambiguity.
> In my musical application, many "objects" (or in Haskell,
> data) have a time associated with them. In Python I would have
> an accessor function called "time" in every class.

  This is really an opportunity to consider an important
  difference between the OO and typed, functional approach to
  things. In OO, we create classes that "have time" as a
  property or method; in the typed, functional approach we
  say there are a family of types that all allow a certain
  function to be called on them, `time :: t -> Time`. This is
  what type classes are all about; they allow us to say "here is
  a function and some types it works with".

  After all, you don't just want a `time` property -- you also
  want it to give you a `Time`. When one is accustomed to treating
  properties as "part of an object", it's natural to go the
  record syntax route; but this doesn't capture the notion that
  all these records conform to a certain type equation. In this
  way, Haskell is more demanding of you; but it also offers you
  a way to make the semantics of your data explicit.

Jason Dusek

More information about the Haskell-Cafe mailing list