Send Beginners mailing list submissions to
        beginners@haskell.org

To subscribe or unsubscribe via the World Wide Web, visit
        http://www.haskell.org/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
        beginners-requ...@haskell.org

You can reach the person managing the list at
        beginners-ow...@haskell.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1. Re:  Re: Encapsulation and Polymorphism (Ozgur Akgun)


----------------------------------------------------------------------

Message: 1
Date: Thu, 26 Aug 2010 13:32:20 +0100
From: Ozgur Akgun <ozgurak...@gmail.com>
Subject: Re: [Haskell-beginners] Re: Encapsulation and Polymorphism
To: Stephen Tetley <stephen.tet...@gmail.com>
Cc: beginners@haskell.org
Message-ID:
        <aanlktik7sg1ok29b_ltry82aw5k1awye-pc5dyn-v...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

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 <stephen.tet...@gmail.com> wrote:

> On 26 August 2010 11:51, Ozgur Akgun <ozgurak...@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<http://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
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
http://www.haskell.org/pipermail/beginners/attachments/20100826/5ad5f99b/attachment-0001.html

------------------------------

_______________________________________________
Beginners mailing list
Beginners@haskell.org
http://www.haskell.org/mailman/listinfo/beginners


End of Beginners Digest, Vol 26, Issue 51
*****************************************

Reply via email to