[Haskell-cafe] Named function fields vs. type classes

Keean Schupke k.schupke at imperial.ac.uk
Wed Dec 15 04:47:53 EST 2004


See the HList library (http://www.cwi.ni/~ralf/HList) and use an HList
constrained by your interface.

    Keean.

John Goerzen wrote:

>Hi,
>
>I often have a situation where I'm designing specialized components to
>do a more general task.   Examples could include mail folder code (maildir,
>mbox, etc), configuration file parsing, protocol handlers for URL
>accesses, logging backends, etc.
>
>For some of these, I've used a data object with named fields, each one
>of them being a function that performs various tasks (open connection to
>the URL, read data, whatever.)  So, I get a standard interface.  The
>advantage of this approach is that I can build a list containing all
>sorts of different data objects in it.
>
>For others, I've used typeclasses, and made the different specialized
>components a member of the typeclass.  This seems to provide a cleaner
>interface, and one that is more readily extended (maybe I want to
>support IMAP folders, and support all its searching capabilities too).
>
>On the other hand, it's difficult or impossible to make a list of a
>bunch of different types of things that have nothing in common save
>being members of the class.
>
>Is there any advice on the best way to do these things?
>
>Thanks,
>
>John
>
>_______________________________________________
>Haskell-Cafe mailing list
>Haskell-Cafe at haskell.org
>http://www.haskell.org/mailman/listinfo/haskell-cafe
>  
>



More information about the Haskell-Cafe mailing list