
Stephen,
I see your point, and I am not a fan of OO style programming in Haskell. I
just wanted to answer OP's question.
In OOP you can have a list of objects of different types, provided they are
subclasses of a common class. But then. you can only apply methods of the
base class to the elements of this list. (Yes you can do some fiddling to
recover the actual type of an element, but you can do similar things in
Haskell as well)
If you desperately want to achieve this effect in Haskell, you can. But
there most probably are better ways of doing things idiomatically.
Best,
Ozgur
On 26 August 2010 13:16, Stephen Tetley
On 26 August 2010 11:51, Ozgur Akgun
wrote: [SNIP] But that's because you use Show while defining the Obj data type. You can implement other functionalities, by introducing a custom type class, and implementing functionalities in instance declarations.
Hi Ozgur
This is well known, of course, Ralf Lammel (umlauts on the a in Lammel) and Klaus Ostermann have a catalogue of "shoehorns" to fit OO design into Haskell:
http://homepages.cwi.nl/~ralf/gpce06/paper.pdfhttp://homepages.cwi.nl/%7Eralf/gpce06/paper.pdf
However these styles aren't exemplary [*] - little Haskell code that I've seen in the wild makes use of them. For instance, having a type class for each operation as per CustomTC seems exorbitant, likewise adding type class contexts to datatype definitions quickly becomes unwieldy:
data Obj = forall a. (Show a, AquaticLifeform a, ...) => Obj a
Best wishes
Stephen
[*] Caveat - Figure 16 is quite reminiscent of the "finally tagless" style which is now widely used. _______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners