[Haskell-cafe] Let's do ListT right, finally

David Menendez dave at zednenem.com
Sun Oct 14 16:50:42 EDT 2007


On 10/14/07, Dan Piponi <dpiponi at gmail.com> wrote:
> On 10/14/07, Yitzchak Gale <gale at sefer.org> wrote:
> > Not very much, I suspect. That "monad" really is broken -
> > it's not a monad at all.
>
> Depending on your point of view, ListT isn't broken. It correctly
> transforms commutative monads into monads. The problem is that you
> can't express "commutative monad" any differently from "monad" in
> Haskell. And so it's been shoehorned into the wrong type class.

If desired, we could easily define a class for commutative monads, and
then state that ListT m is only a monad if m is a commutative monad.
For example,

class Monad m => CommutativeMonad m

instance (CommutativeMonad m) => Monad (ListT m) where
    return a = ListT (return [a])
    etc.

Naturally, it's up to the programmer to guarantee that instances of
CommutativeMonad are actually commutative monads.

-- 
Dave Menendez <dave at zednenem.com>
<http://www.eyrie.org/~zednenem/>


More information about the Libraries mailing list