[Haskell-cafe] Question on a common pattern
Maciej Marcin Piechotka
uzytkownik2 at gmail.com
Tue Mar 15 14:33:16 CET 2011
On Mon, 2011-03-14 at 17:56 +0100, Yves Parès wrote:
> If you have only one alternative, then you can simply do:
>
> Opt1 <- someIO
>
> E.g., if you are _sure_ that foo returns always a 'Just' within a monad you
> can perfectly do :
>
> Just x <- foo
>
Please beware - it is not exactly the same as with case if your
assumption is wrong:
> (do Just x <- return Nothing; [x])
[]
> (do x <- return Nothing; case x of Just x -> [x])
*** Exception: <interactive>:1:26-48: Non-exhaustive patterns in case
For IO and many monads it is the same but it is not necessary for any
monad.
Regards
More information about the Haskell-Cafe
mailing list