On Tue, Jan 16, 2007 at 14:06:08 +0200, Yitzchak Gale wrote:
[..]
>But the list monad [] is not a transformer, so you can't lift in it,
>even if the contained type happens also to be a monad.

Yeah, I had some vague thought of that being a problem, which lead me to
ListT.  Your statement put some good words to that thought.

>Perhaps you are looking for something like this, using the monad
>transformer version of []:
>
>listChars2 :: ListT IO Char
>listChars2 = do
> c <- lift getChar
> if c == 'q'
>   then return [c]
>   else return [c] `mplus` listChars2
>
>GHC finds this much more tasty, and then
>
>runListT listChars2
>
>does what I think you may want.

Yes, that is fairly close to what I want to do.  Now, it'd be really
good if I could apply a function to each item in the ListT, with the
constraint that it should be done lazily.  I.e. the following will not
do

 runListT listChars2 >>= (mapM_ putChar)

because it first reads the input until 'q' is pressed.  I.e. this
produces the interaction:

  abcqabcq

What I want is the interaction:

  aabbccqq

Hope you understand what I mean.

/M

P.S. I'm aware a reqursive solution is possible and I've already coded
one that works.  I'm just curious if a "map solution" is possible.

-- 
Magnus Therning                             (OpenPGP: 0xAB4DFBA4)
[EMAIL PROTECTED]             Jabber: [EMAIL PROTECTED]
http://therning.org/magnus

Attachment: pgpkBnPyR98zZ.pgp
Description: PGP signature

_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to