[Haskell-beginners] Equivalent of inheritance in Haskell
C K Kashyap
ckkashyap at gmail.com
Tue Dec 14 04:10:56 CET 2010
>
> But there is not a way to easily say (in Haskell) "type A is
> everything that type B is plus these other things here ...". Haskell
> is not an OO language.
This captures what I had in mind. Using compound types seems ok but
I'd still need to do some mechanical stuff if I had to provide a
function that works on the compound type which is actually defined for
a component type.
If I understand you right .. you'd build a 'Man' type and 'Woman' type
by using a 'Person' type. Lets say, there is a function called getName
that is Person -> String
I'd have to mechanically define a function getName :: Man -> String -
that extracts the person inside and calls getName on it - did I
understand it right?
Or would you typically write extract functions that'll return the
components and then the user could call the method on the component?
As in .... getPerson :: Man -> Person ... then call getName on that.
How do you deal with situations like that?
More information about the Beginners
mailing list