[Haskell-cafe] container-classes (was: Restricted type classes)
jwlato at gmail.com
Mon Sep 6 12:53:29 EDT 2010
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.
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.
I think I've made my arguments as well as I can, so I'm going to be quiet
now unless something new comes up.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Haskell-Cafe