Broken monad laws

Iavor Diatchki iavor.diatchki at
Wed Nov 23 17:45:04 EST 2005

I just noticed that the GHC/Hugs "standard" libraries have acquired a
list monad transformer, which is broken, because it does not satisfy
the associativity law when applied to non-commutative monads.  I am
not referring to some corner-case strictness problem, but rather a
fairly well known result.  The associativity law is important, because
without it the 'do' notation can be very confusing.  Bellow is an
example, for people not familiar with the porblem.

import Control.Monad.List

say    :: String -> ListT IO ()
say x   = lift (putStr x)

one_two, ex1,ex2 :: ListT IO ()
one_two = say "1 " `mplus` say "2 "
ex1     = do one_two
             say "3 "
             say "4 "
ex2     = do do one_two
                say "3 "
             say "4 "

main    = runListT ex1 >> putStrLn " or " >> runListT ex2

More information about the Libraries mailing list