[Haskell-beginners] Re: Encapsulation and Polymorphism

Stephen Tetley stephen.tetley at gmail.com
Thu Aug 26 08:16:13 EDT 2010


On 26 August 2010 11:51, Ozgur Akgun <ozgurakgun at gmail.com> 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.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.


More information about the Beginners mailing list