[Haskell-beginners] interface/abstract class: what is the haskell way?

Emmanuel Touzery etouzery at gmail.com
Fri Feb 8 10:50:30 CET 2013


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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20130208/e1b0b746/attachment-0001.htm>


More information about the Beginners mailing list