Thank you, I didn&#39;t realize I can simply put the maybe computation inside the IO as you&#39;ve shown. And I must research runState/evalState a bit more.<br>But yes it doesn&#39;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 &lt;- needToFetchAgain export_filename<br>
    when needToFetchAgain $ do<br>       ....<br><br>&#39;when&#39; coming from Control.Monad.<br><br>Well so I&#39;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">&lt;<a href="mailto:daniel.trstenjak@gmail.com" target="_blank">daniel.trstenjak@gmail.com</a>&gt;</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>
&gt; But this function is already in the IO monad (maybe I&#39;m thinking about<br>
&gt; 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&#39;t help that much, because the<br>
functions you&#39;re calling doesn&#39;t return a Maybe value.<br>
<br>
<br>
In your case, why having a &#39;needToFetchAgain&#39; and probably a &#39;fetch&#39;<br>
function instead of just a &#39;refetch&#39; 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>