[Haskell-cafe] I miss OO

Serguey Zefirov sergueyz at gmail.com
Wed Nov 25 16:13:32 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.
>
> So if I have objects/data note1, cursor1, and staff1,
>
> Python:
>  note1.time()
>  cursor1.time()
>  staff1.time()
>
> Haskell needs something like
>  note_time note1
>  cursor_time cursor1
>  staff_time staff1
>
> which is a lot more visually disorganized.

It looks like you use record syntax.

This is not bad per se, but you can use Haskell classes to get an OO feeling.

Like that:
class Time a where time :: a -> Time
instance Time Note where time = note_time
instance Time Cursor where time = cursor_time

> What's worse, I have a moderate case of RSI (repetitive strain injury) so I
> type slowly and depend on abbreviations a lot. I use the souped-up
> abbreviation capabilities of Emacs. Let's say I have a field/member-variable
> called orientedPcSet that is used across many classes. In Python, I can
> create an abbreviation for that and it is useful many times. In Haskell, I
> might need
>
> someType_orientedPcSet
> someOtherType_orientedPcSet
> thirdType_orientedPcSet

Same here, I think.


More information about the Haskell-Cafe mailing list