[Haskell-cafe] Representing Hierarchies with Typeclasses
Dimitri DeFigueiredo
defigueiredo at ucdavis.edu
Wed Oct 5 13:55:55 UTC 2016
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
More information about the Haskell-Cafe
mailing list