Re: [Haskell-cafe] Representing Hierarchies with Typeclasses

I have looked at how to embedded object oriented systems into haskell for practical reasons. By far the best resource I found was Oleg Kiselyov and Ralph Lämmel's work: https://arxiv.org/pdf/cs/0509027.pdf It shows the multiple possibilities. I have used the idea of having a super class be a polymorphic type with a tail. data Point s = Pt { x :: Int, y:: Int, tail :: s} And then specializing the parameter s into your derived class type Radius = Int type Circle = Point Radius many times. But *be warned*, I try to avoid object hierarchies like the plague! They lead to code that is not reusable. You may want to consider other simpler possibilities. Here is one of my earlier experiments that may be useful to you (I no longer have the views expressed there). https://github.com/dimitri-xyz/inheritance-in-haskell Cheers, Dimitri -- 2E45 D376 A744 C671 5100 A261 210B 8461 0FB0 CA1F

Hi Dimitri, Thanks for the link! I'll take a look. The goal of doing this was to make foreign Java imports reusable for subclasses in GHCVM. Thanks, Rahul On Wed, Oct 5, 2016 at 7:25 PM, Dimitri DeFigueiredo < defigueiredo@ucdavis.edu> wrote:
I have looked at how to embedded object oriented systems into haskell for practical reasons. By far the best resource I found was Oleg Kiselyov and Ralph Lämmel's work:
https://arxiv.org/pdf/cs/0509027.pdf
It shows the multiple possibilities. I have used the idea of having a super class be a polymorphic type with a tail.
data Point s = Pt { x :: Int, y:: Int, tail :: s}
And then specializing the parameter s into your derived class
type Radius = Int type Circle = Point Radius
many times.
But *be warned*, I try to avoid object hierarchies like the plague! They lead to code that is not reusable. You may want to consider other simpler possibilities. Here is one of my earlier experiments that may be useful to you (I no longer have the views expressed there).
https://github.com/dimitri-xyz/inheritance-in-haskell
Cheers,
Dimitri
-- 2E45 D376 A744 C671 5100 A261 210B 8461 0FB0 CA1F
-- Rahul Muttineni
participants (2)
-
Dimitri DeFigueiredo
-
Rahul Muttineni