[Haskell-beginners] Request for Another State Monad Example
mbsullivan at gmail.com
Wed Sep 17 14:05:46 EDT 2008
As I'm sure all Haskell beginners do, I'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.
The ubiquitous state monad example for Haskell tutorials seems to be a
random number generator, with a function like the following (from
getAny :: (Random a) => State StdGen a
getAny = do g <- get
(x,g') <- return $ random g
My first question is very basic, but here it goes: I see it everywhere, but
what does the "=>" signify? Specifically, in this example what does "(Random
a) =>" do in the type signature?
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?
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Beginners