[Haskell-beginners] Re: Encapsulation and Polymorphism
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:
> 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.
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:
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
data Obj = forall a. (Show a, AquaticLifeform a, ...) => Obj a
[*] Caveat - Figure 16 is quite reminiscent of the "finally tagless"
style which is now widely used.
More information about the Beginners