[Haskell-cafe] Stacking monads
Brandon S. Allbery KF8NH
allbery at ece.cmu.edu
Fri Oct 3 19:34:24 EDT 2008
On 2008 Oct 3, at 16:12, Andrew Coppin wrote:
> Brandon S. Allbery KF8NH wrote:
>> On Oct 3, 2008, at 15:10 , Andrew Coppin wrote:
>>> Again, it looks like MonadPlus == Monad + Monoid, except all the
>>> method names are different. Why do we have this confusing
>>> duplication?
>>
>> Because typeclasses aren't like OO classes. Specifically: while
>> you can specify what looks like class inheritance (e.g. "this Monad
>> is also a Monoid" you can't override inherited methods (because
>> it's a Monad, you can't specify as part of the Monad instance the
>> definition of a Monoid class function). So if you want to define
>> MonadPlus to look like a Monad and a Monoid, you have to pick one
>> and *duplicate* the other (without using the same names, since
>> they're already taken by the typeclass you *don't* choose).
>
> I was thinking more, why not just delete MonadPlus completely, and
> have any function that needs a monad that's also a monoid say so in
> its context? (Obviously one of the answers to that is "because it
> would break vast amounts of existing code".)
It also touches on some Haskell98 braindamage. (Look up "MonadZero".)
--
brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allbery at kf8nh.com
system administrator [openafs,heimdal,too many hats] allbery at ece.cmu.edu
electrical and computer engineering, carnegie mellon university KF8NH
More information about the Haskell-Cafe
mailing list