[Haskell-cafe] Mysterious monads

Andrew Coppin andrewcoppin at btinternet.com
Tue May 29 16:36:03 EDT 2007


Nicolas Frisby wrote:
> Your intended behavior for Reader indicates stateful computational
> features. The "read later" roughly expands to "be read by some monadic
> action on the rhs of a >>=" as in
>
> (read >>= \x -> read {-this  is later-} >>= ...)
>
> Recognizing the stateful nature gives you two options:
>
> 1) Implement yours as a restricted version of Control.Monad.State
>
>    type ReaderAC = State
>    readAC = get >>= \x -> put (tail x) >> return (head x)

I'll at least have a look at that...

> 2) or (as Isaac demonstrated) look to the definition of
> Control.Monad.State.State for guidance own how to structure your
> monad.

Ah yes. I just sat down to do this, and... oh look. There in the first 
few lines, a non-standard language extension that I don't understand.

...which neatly brings us back to the reason I'm trying to reimplement 
this by hand in the first place. ;-)



More information about the Haskell-Cafe mailing list