I am a C# developer. Coming from OO side of the world, I start with thinking in terms of interfaces, classes and type hierarchies. Because of lack of OO in Haskell, sometimes I find myself stuck and I cannot think of a way to model certain problems with Haskell.
How to model, in Haskell, real world situations involving class hierarchies such as the one shown here: http://www.braindelay.com/danielbray/endangered-object-oriented-programming/isHierarchy-4.gif
Let’s assume the following operations: Humans can speak, Dogs can bark, and all members of a species can mate with members of the same species if they have opposite gender. I would define this in haskell like this:
Now the operation
matablehas typeSpecies s => s -> s -> Bool,barkhas typeCanine -> Stringandspeakhas typeHuman -> String -> String.I don’t know whether this helps, but given the rather abstract nature of the question, that’s the best I could come up with.
Edit: In response to Daniel’s comment:
A simple hierarchy for collections could look like this (ignoring already existing classes like Foldable and Functor):
Now sumOfEvenElements takes any kind of collection of integrals and returns the sum of all even elements of that collection.