
Thank you; I did read that thread, and it helped me better grasp
typeclasses. However it confused me even more as to which is the most
idiomatic solution in haskell for my problem. This thread is partly the
reason why I asked this time ;-)
On Fri, Feb 8, 2013 at 11:58 AM, Mateusz Kowalczyk
Greetings,
I have recently asked for a difference between an interface as we know it from OOP and a type class in Haskell. Although it's not an answer to your question, you might find it useful. You can find the conversation archived on gmane at [1]
[1] - http://comments.gmane.org/gmane.comp.lang.haskell.beginners/11341
On 08/02/13 09:50, Emmanuel Touzery wrote:
Hello,
i wrote two programs in haskell which have the same problem: they define a common datatype (let's say Event for instance), and they have several modules, each one importing a list of Event from a specific data source.
So all these modules have a similar api:
getEvents :: <params> -> IO [Event]
And maybe a couple extra functions, more or less the same for each module.
In OO, I would make a base class, like EventProvider, with a couple abstract methods and in the main class of my app, I would have a list of EventProvider and loop over them. That way to add a new EventProvider, I would just add the import and an element in that list.
Currently in haskell I duplicate the function calls for each provider. And because there is no interface constraint, each module has a slightly different API.
The "obvious" way to do in haskell what I would do in OO would be through type classes. However I realize type classes are not quite interfaces. I'm wondering what would be the "haskell way" to solve this problem?
For sure type classes do the job. But is it the idiomatic way of solving this problem?
Thank you!
Emmanuel
_______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners
_______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners