[Haskell-beginners] cascade of if statements
Daniel Trstenjak
daniel.trstenjak at gmail.com
Wed Oct 31 12:05:13 CET 2012
Hi Emmanuel,
On Wed, Oct 31, 2012 at 11:25:05AM +0100, Emmanuel Touzery wrote:
> But this function is already in the IO monad (maybe I'm thinking about
> this in the wrong way though).
A huge step in understanding monads for myself was to realize, that
you can put any monadic computation (IO is the exception) inside an
other monadic computation.
e.g.
ioComputation :: IO ()
ioComputation = do
let maybe = do maybeComputation1
maybeComputation2
...
return ()
Most monads have some kind of execution function, like the state monad (runState, evalState):
ioComputation :: IO ()
let initalState = ...
result = evalState $ do stateComputation1
stateComputation2
initalState
return ()
In your case the Maybe monad doesn't help that much, because the
functions you're calling doesn't return a Maybe value.
In your case, why having a 'needToFetchAgain' and probably a 'fetch'
function instead of just a 'refetch' function, which encapsulates
the whole fetching?
Greetings,
Daniel
More information about the Beginners
mailing list