<div dir="ltr"><font size="2"><span style="font-family: arial,helvetica,sans-serif;">Hi All,</span><br style="font-family: arial,helvetica,sans-serif;"><br style="font-family: arial,helvetica,sans-serif;"><span style="font-family: arial,helvetica,sans-serif;">As I&#39;m sure all Haskell beginners do, I&#39;m having a bit of a struggle wrapping my head around all of the uses for monads. My current frustration is trying to figure out how to use the state monad to attach some persistent state between different calls to a function. I have two questions that I would appreciate it if somebody could help me with.</span><br style="font-family: arial,helvetica,sans-serif;">
<br style="font-family: arial,helvetica,sans-serif;"><span style="font-family: arial,helvetica,sans-serif;">The ubiquitous state monad example for Haskell tutorials seems to be a random number generator, with a function like the following (from <a href="http://www.haskell.org/all_about_monads/html/statemonad.html#example">http://www.haskell.org/all_about_monads/html/statemonad.html#example</a>):</span><br style="font-family: arial,helvetica,sans-serif;">
</font><pre style="font-family: arial,helvetica,sans-serif; margin-left: 40px;"><font size="2"><font size="2">getAny :: (Random a) =&gt; State StdGen a<br>getAny = do g      &lt;- get<br>            (x,g&#39;) &lt;- return $ random g<br>
            put g&#39;<br>            return x</font><br></font></pre><font size="2"><span style="font-family: arial,helvetica,sans-serif;">My first question is very basic, but here it goes: I see it everywhere, but what does the &quot;=&gt;&quot; signify? Specifically, in this example what does &quot;(Random a) =&gt;&quot; do in the type signature?&nbsp; <br>
<br>My second question is more of a request, I suppose. I think it would be useful to get another example that does not have the added complications of dealing with the Random package, and saves more than one piece of data as state. How would one go about (for example) creating a Fibonacci sequence generator that saves the last state, such that on each call it returns the next number in the Fibonacci sequence?<br>
<br>Thank you,<br>Mike<br><br>&nbsp;</span><br style="font-family: arial,helvetica,sans-serif;"></font></div>