[Haskell-cafe] container-classes (was: Restricted type classes)

Ivan Lazar Miljenovic ivan.miljenovic at gmail.com
Mon Sep 6 23:46:16 EDT 2010

On 7 September 2010 02:53, John Lato <jwlato at gmail.com> wrote:
> I'd like to make one more argument in favor of my preference for more
> splitting of type classes.  IMO it's beneficial to split up classes to
> minimize unnecessary dependencies.  That is, while e.g. Monoid is very
> useful for containers, many container methods won't need it, e.g. "elem" or
> "filter".  When you divide the type classes so only what's necessary is
> required, more data structures will be able to meet those criteria, which in
> turn makes the class more generally useful.

Well, my current work is to implement restricted versions of the
various type classes (I'm undecided if they should be split off into a
separate package or not) and then have the Data.Containers module
basically define type aliases (which will probably still use Monoid
though, since the vast majority of containers are able to be empty).

> As an example, I have an extension to iteratee which uses raw buffers for
> holding data.  This allows it to operate in truly constant memory (only one
> allocation, deallocated when it's finished), which has resulted in
> performance benefits.  Unfortunately there is not a good Monoid instance for
> this type because appending buffers is not possible.  By introducing the
> NullPoint class (equivalent to mempty of Monoid) in iteratee, my raw buffer
> extension is able to re-use several iteratee functions which it would not be
> able to if I had require Monoid instead of NullPoint.

Hmmm, splitting up Monoid might make sense.  I'll have a think about
that (I was going to just keep Monoid as is since no constraints are

Ivan Lazar Miljenovic
Ivan.Miljenovic at gmail.com

More information about the Haskell-Cafe mailing list