[Haskell-cafe] Re: The State Monad
John Goerzen
jgoerzen at complete.org
Thu Oct 7 23:28:46 EDT 2004
On 2004-10-07, J. Garrett Morris <J.Garrett.Morris at Dartmouth.EDU> wrote:
> I can run both of those without a problem - could you post more of
> your code? It's probably somewhere else. /gXm
You're right; I must have goofed somewhere. But I don't have real code
yet, since I can't figure out the basic way of doing things. Here was
my latest attempt:
getOrSet :: Maybe Int -> State Int Int
getOrSet m = case m of
Nothing -> do
n <- get
return n
Just x -> do
put x
return x
But it doesn't seem to really be useful.
When I try execState/evalState, it just return my argument when I call
it with Nothing, or the thing passed to Just when I call it with that.
More information about the Haskell-Cafe
mailing list