[Haskell-cafe] OOP'er with (hopefully) trivial questions.....

Miguel Mitrofanov miguelimo38 at yandex.ru
Mon Dec 17 14:12:55 EST 2007


> There's a third way, too, and I haven't seen anybody mention it yet

I've noticed it, but there are some problems with this  
representation, so I decided not to mention it. It's OK as far as we  
don't want functions working on two areas - I don't see, how we can  
implement, say, intersect :: Shape -> Shape -> Bool in this way.  
However, it's a useful pattern.

> (apologies if I just missed it).  You can provide an explicit record
> of the relevant "member functions", and "instantiate" it in different
> ways.  E.g.
>
>    data Shape = Shape { area :: Int }
>
>    square x      = Shape (x^2)
>    rectangle x y = Shape (x*y)
>    circle r      = Shape (pi*r^2)


More information about the Haskell-Cafe mailing list