Re: [Haskell-cafe] Mysterious monads

2007-05-29 Thread Andrew Coppin
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 option

Re: [Haskell-cafe] Mysterious monads

2007-05-29 Thread Henning Thielemann
On Sun, 27 May 2007, Andrew Coppin wrote: > 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. > > (Oh

Re: [Haskell-cafe] Mysterious monads

2007-05-28 Thread Nicolas Frisby
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 late

Re: [Haskell-cafe] Mysterious monads

2007-05-27 Thread Isaac Dupree
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Andrew Coppin wrote: > Take a look at the following: > > data Writer o v = Writer [o] v > > instance Monad (Writer o) where >return v = Writer [] v > >(Writer os v) >>= f = > let (Writer os' v') = f v > in Writer (os ++ os') v' >

Re: [Haskell-cafe] Mysterious monads

2007-05-27 Thread Stefan O'Rear
On Sun, May 27, 2007 at 02:43:32PM +0100, Andrew Coppin wrote: > Any thoughs? Take a look at MonadSupply on the wiki: http://haskell.org/haskellwiki/New_monads/MonadSupply Stefan ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell

[Haskell-cafe] Mysterious monads

2007-05-27 Thread Andrew Coppin
Take a look at the following: data Writer o v = Writer [o] v instance Monad (Writer o) where return v = Writer [] v (Writer os v) >>= f = let (Writer os' v') = f v in Writer (os ++ os') v' write :: o -> Writer o () write o = Writer [o] () writes :: [o] -> Writer o () wri