[Haskell-cafe] I miss OO
Luke Palmer
lrpalmer at gmail.com
Thu Nov 26 02:21:34 EST 2009
On Thu, Nov 26, 2009 at 12:03 AM, Eugene Kirpichov <ekirpichov at gmail.com> wrote:
> Hi,
>
> Are you sure you need to store the time *inside* your "objects"
> instead of using, say, pairs "(Time, YourObject)" (and lists of them
> instead of lists of your objects)?
> It would seem strange to me that a note HAS-A time even in an OO
> design: more likely, a note is associated with a time, and this is
> modeled by pairing them.
+1
This hadn't occurred to me, but in retrospect is quite obvious. In
FRP notation, these are "Futures", eg. Future Note.
Luke
> 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.
>>
>> 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
>>
>> which prevents me from using abbreviations effectively (especially the
>> dynamic-completion feature). (It would help to make the underscore not part
>> of word syntax, but that's not ideal.)
>>
>> So I'm thinking of moving to a scheme in Haskell using modules, most types
>> being defined in their own modules, and doing qualified imports. Generic
>> names like 'time' can be defined in each module w/o clashing. Then I have
>>
>> Note.time note1
>> Cursor.time cursor1
>> Staff.time staff1
>>
>> This is very useful because I can define abbreviations for the type name and
>> for oft-used accessor function names and these abbrevs are more organized,
>> easier to remember, and easier to combine.
>>
>> I would be interested in comments... is this a good way to do things? Am I
>> trying too hard to impose OO on Haskell and is there a better way?
>>
>> Thanks,
>> Mike
>>
>> _______________________________________________
>> Haskell-Cafe mailing list
>> Haskell-Cafe at haskell.org
>> http://www.haskell.org/mailman/listinfo/haskell-cafe
>>
>
>
>
> --
> Eugene Kirpichov
> Web IR developer, market.yandex.ru
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
More information about the Haskell-Cafe
mailing list