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.<br>But yes it doesn't map so well to maybe. The parrallel just came to my mind.<br>
<br>The reason for splitting needToFetchAgain out was to keep function size small and the code readable.<br><br>And in the caller function I can nicely write:<br><br> needToFetchAgain <- needToFetchAgain export_filename<br>
when needToFetchAgain $ do<br> ....<br><br>'when' coming from Control.Monad.<br><br>Well so I'll leave this function as it is for now and make a note to read some more about runState/evalState.<br><br>
Thank you!<br><br>Emmanuel<br><br><div class="gmail_quote">On Wed, Oct 31, 2012 at 12:05 PM, Daniel Trstenjak <span dir="ltr"><<a href="mailto:daniel.trstenjak@gmail.com" target="_blank">daniel.trstenjak@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
Hi Emmanuel,<br>
<div class="im"><br>
On Wed, Oct 31, 2012 at 11:25:05AM +0100, Emmanuel Touzery wrote:<br>
> But this function is already in the IO monad (maybe I'm thinking about<br>
> this in the wrong way though).<br>
<br>
</div>A huge step in understanding monads for myself was to realize, that<br>
you can put any monadic computation (IO is the exception) inside an<br>
other monadic computation.<br>
<br>
e.g.<br>
<br>
ioComputation :: IO ()<br>
ioComputation = do<br>
let maybe = do maybeComputation1<br>
maybeComputation2<br>
...<br>
return ()<br>
<br>
<br>
Most monads have some kind of execution function, like the state monad (runState, evalState):<br>
<br>
ioComputation :: IO ()<br>
let initalState = ...<br>
result = evalState $ do stateComputation1<br>
stateComputation2<br>
initalState<br>
return ()<br>
<br>
<br>
<br>
In your case the Maybe monad doesn't help that much, because the<br>
functions you're calling doesn't return a Maybe value.<br>
<br>
<br>
In your case, why having a 'needToFetchAgain' and probably a 'fetch'<br>
function instead of just a 'refetch' function, which encapsulates<br>
the whole fetching?<br>
<br>
<br>
Greetings,<br>
Daniel<br>
<br>
_______________________________________________<br>
Beginners mailing list<br>
<a href="mailto:Beginners@haskell.org">Beginners@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/beginners" target="_blank">http://www.haskell.org/mailman/listinfo/beginners</a><br>
</blockquote></div><br>