[Haskell-cafe] Conditionals and case expressions in do blocks

aditya siram aditya.siram at gmail.com
Wed Jan 26 21:32:20 CET 2011


I think that for monads the cleanest way of doing conditional
execution is using  'when' and 'unless' [1] and 'guard' if your type
is a Monoid.

-deech

[1] http://www.haskell.org/ghc/docs/latest/html/libraries/base/Control-Monad.html#6

On Wed, Jan 26, 2011 at 2:22 PM, Edward Amsden <eca7215 at cs.rit.edu> wrote:
> Inside a do block, I can very conveniently substitute
>
> let x = <pure exp>
> <continued monadic code>
>
> for either
> x <- return <pure exp>
> <continued monadic code>
>
> or
> let x = <pure exp>
> in do
> <continued monadic code>
>
> However, I can't do anything similar (that I know of) with if or case
> expressions. If I use if or case inside a do block, it's likely that
> I'm still using monadic expressions (at least in my experience). Is
> there some nasty semantic ambiguity that comes of this? Is it just not
> in the standard yet? Is there some extension that I'm not aware of?
>
> --
> Edward Amsden
> Undergraduate
> Computer Science
> Rochester Institute of Technology
> www.edwardamsden.com
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>



More information about the Haskell-Cafe mailing list