
Thank you, I didn't realize I can simply put the maybe computation inside the IO as you've shown. And I must research runState/evalState a bit more. But yes it doesn't map so well to maybe. The parrallel just came to my mind. The reason for splitting needToFetchAgain out was to keep function size small and the code readable. And in the caller function I can nicely write: needToFetchAgain <- needToFetchAgain export_filename when needToFetchAgain $ do .... 'when' coming from Control.Monad. Well so I'll leave this function as it is for now and make a note to read some more about runState/evalState. Thank you! Emmanuel On Wed, Oct 31, 2012 at 12:05 PM, Daniel Trstenjak < daniel.trstenjak@gmail.com> wrote:
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
_______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners