Re: oops (was: Re: if-then-else inside a do)

2002-01-30 Thread Mark Carroll
On Wed, 30 Jan 2002, Kevin Glynn wrote: I think the Haskell Wiki was going to be the place to collect interesting code fragments. However, I must add that these functions are already part of the Haskell 98 standard. See the Monad module in the Library Report. Ah, cool, both points sound

if-then-else inside a do

2002-01-29 Thread Andre W B Furtado
In the following code, will other things be executed or the return () will end function f? I guess the answer is yes (other things WILL be executed anyway), but I'd like to understand why won't the return () be the [state change/result produced] created by f. f :: IO () f = do -- lots of

Re: if-then-else inside a do

2002-01-29 Thread Bernard James POPE
In the following code, will other things be executed or the return () will end function f? I guess the answer is yes (other things WILL be executed anyway), but I'd like to understand why won't the return () be the [state change/result produced] created by f. f :: IO () f = do --

Re: if-then-else inside a do

2002-01-29 Thread Bernard James POPE
Hi again, Forgot to mention this in my last email. I find myself writing a lot of if-then-elses in do notation, and most often the else branch is return (). This gets a bit cumbersome to write and messes up the code. So now I tend to use: doIf :: Monad a = Bool - [a b] - a () doIf b e =

Re: if-then-else inside a do

2002-01-29 Thread Fergus Henderson
On 29-Jan-2002, Andre W B Furtado [EMAIL PROTECTED] wrote: In the following code, will other things be executed or the return () will end function f? I guess the answer is yes (other things WILL be executed anyway), but I'd like to understand why won't the return () be the [state

Re: if-then-else inside a do

2002-01-29 Thread Johannes Waldmann
Forgot to mention this in my last email. I find myself writing a lot of if-then-elses in do notation, and most often the else branch is return (). This gets a bit cumbersome to write and messes up the code. There's also the Monad library http://haskell.org/onlinelibrary/monad.html that

oops (was: Re: if-then-else inside a do)

2002-01-29 Thread Bernard James POPE
Oops, Thanks to Kevin who pointed out: when :: (Monad m) = Bool - m () - m () when p s = if p then s else return () unless :: (Monad m) = Bool - m () - m () unless p s= when (not p) s So now I tend to use: doIf :: Monad a = Bool - [a b] - a ()

Re: oops (was: Re: if-then-else inside a do)

2002-01-29 Thread Mark Carroll
On Wed, 30 Jan 2002, Bernard James POPE wrote: (snip) when :: (Monad m) = Bool - m () - m () when p s = if p then s else return () unless :: (Monad m) = Bool - m () - m () unless p s= when (not p) s (snip) That's cute. People post all sorts of handy

Re: oops (was: Re: if-then-else inside a do)

2002-01-29 Thread Kevin Glynn
I think the Haskell Wiki was going to be the place to collect interesting code fragments. However, I must add that these functions are already part of the Haskell 98 standard. See the Monad module in the Library Report. cheers k Mark Carroll writes: On Wed, 30 Jan 2002, Bernard James