[Haskell-cafe] do notation strangeness

Ilya Tsindlekht eilya497 at 013.net
Sat Dec 8 12:12:28 EST 2007


On Sat, Dec 08, 2007 at 02:59:16PM -0200, Felipe Lessa wrote:
> Hello!
> 
> I see from http://www.haskell.org/haskellwiki/Monads_as_computation#Do_notation
> that
> 
> do { v <- x ; <stmts> }
>   = x >>= \v -> do { <stmts> }
> 
> However, look at this GHCi session:
> 
> Prelude> let return' = return :: a -> Maybe a
> Prelude> do {1 <- return 1; return' "ok"}
> Just "ok"
> Prelude> return 1 >>= \1 -> return' "ok"
> Just "ok"
> Prelude> do {1 <- return 3; return' "ok"}
> Nothing
> Prelude> return 3 >>= \1 -> return' "ok"
> *** Exception: <interactive>:1:13-30: Non-exhaustive patterns in lambda
What seems confusing to you?

\1 -> foo
is the same as
\x -> case x of {1 -> foo;}

When this function is evaluated with parameter different from 1, Haskell
fails to find matching pattern for x and exception occurs.


More information about the Haskell-Cafe mailing list