Broken monad laws

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Broken monad laws

Iavor Diatchki
Hello,
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.
-Iavor

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
_______________________________________________
Libraries mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/libraries
Reply | Threaded
Open this post in threaded view
|

Re: [Haskell] Broken monad laws

Sean Seefried

On 24/11/2005, at 9:45 AM, Iavor Diatchki wrote:

> Hello,
> 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.
> -Iavor

This seems to have been discussed already:

http://haskell.cs.yale.edu/hawiki/ListTDoneRight

Sean

_______________________________________________
Haskell mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell