On 5/27/07, Andrew Coppin <[EMAIL PROTECTED]> wrote:
[snip]

such that a Reader is created with an initial list, and the read
function fetches 1 element out of that list. That is, the expression "x
<- read" will take the head element of the list and put it into x,
keeping the tail to be read later.


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)

2) or (as Isaac demonstrated) look to the definition of
Control.Monad.State.State for guidance own how to structure your
monad.
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to