<div dir="ltr"><div><div><div><div><div><div>William/Tom,<br><br></div>(1)  Yes, looking into lens and re-factoring my current experimental project in lens will be my next iteration. For now, I plan not to spend time on it.<br><br></div>(2)  Agreed.  Not sure how I missed that.<br><br></div>(3)  I see how foldM works now.  I missed the point that foldM not only is a
 `map` but also does a `sequence` after that.  I got stuck earlier, thinking
 I will end up with a list of state monads. The sequence steps executes 
this monadic action.<br> <br></div>But, how can I do a foldM in a state monad. Say, I need to map over a list of students and add up all their fees, can I get away not `evalState` inside the foldM step function?<br><br></div>Thanks. this is very exciting as I keep simplifying my code!<br><br></div>Guru<br><div><div><div><br><br>  </div></div></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Jul 8, 2016 at 7:55 PM,  <span dir="ltr"><<a href="mailto:amindfv@gmail.com" target="_blank">amindfv@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="auto"><span class=""><div></div><div><br></div><div><blockquote type="cite"><div class="gmail_extra"><div class="gmail_quote"><font color="#000000"><span style="background-color:rgba(255,255,255,0)">On Fri, Jul 8, 2016 at 9:57 PM, Guru Devanla <span dir="ltr"><<a href="mailto:gurudev.devanla@gmail.com" target="_blank">gurudev.devanla@gmail.com</a>></span> wrote:</span></font></div></div></blockquote></div><div><br></div></span><span class=""><div><blockquote type="cite"><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-color:rgb(204,204,204);padding-left:1ex"><div dir="ltr"><font color="#000000"><span style="background-color:rgba(255,255,255,0)">1.  I see that almost in every function I deal with state, I have e <- get , expression in the begining. I always ending up having to use the state to query for different values. I guess this is OK.</span></font></div></blockquote></div></div></blockquote></div></span><span class=""><div><br>El 8 jul 2016, a las 22:07, William Yager <<a href="mailto:will.yager@gmail.com" target="_blank">will.yager@gmail.com</a>> escribió:<br><br></div><blockquote type="cite"><div><div dir="ltr"><div>For #1, look into using the Lens library's support for the State monad. You can often avoid doing a get, and instead write things like `fees += 5`, which will add 5 to the field in the state called "fees".</div><div><br></div></div></div></blockquote><div><br></div></span><div>Lens is a pretty heavy extra thing for a beginner to have to learn -- you'll do fine with the 'modify' function:</div><div><br></div><div>modify :: (s -> s) -> State s ()</div><div><br></div><div>So instead of writing:</div><div><br></div><div>do</div><div>   s <- get</div><div>   put (s + 5)</div><div><br></div><div>You say:</div><div><br></div><div>modify (+5)</div><div><br></div><div><br></div><div>Tom</div></div></blockquote></div><br></div>