[Haskell-cafe] Re: IO in lists

Magnus Therning magnus at therning.org
Fri Jan 26 05:51:17 EST 2007


You are suggesting later in this thread that the old ListT could be used
to solve my initial problem.  I don't see how, so I'm wondering if you'd
mind sorting some things out for me?

On Tue, Jan 23, 2007 at 11:59:58 +0200, Yitzchak Gale wrote:
[..]
>test = do
> a <- liftIO getChar
> guard $ a /= 'q'
> return $ a `mplus` test

This piece has type problems.  I couldn't get ghci to accept it without
making some changes:

  test :: ListT IO Char
  test = do
      a <- liftIO getChar
      guard $ a /= 'q'
      (return a) `mplus` test

[..]
>test2 = runListT . mapM (liftIO print)

There are some type problems here too, and I don't really see how to fix
them.

  > :t liftIO
  liftIO :: (MonadIO m) => IO a -> m a
  > :t print
  print :: (Show a) => a -> IO ()
  > :t (liftIO print)
      Couldn't match expected type `IO a'
             against inferred type `a1 -> IO ()'
      In the first argument of `liftIO', namely `print'

I also don't quite see how 'mapM foo` can be applied to a ListT since
'mapM foo' would have the type [a] -> m [b] (a & b depending on foo).
Perhaps you didn't mean mapM but rather mapListT?
But using mapListT in a similar way:

  > runListT.mapListT (\ m -> m >>= mapM putChar) $ test

does not result in the desired interleaving.  Changing to using runListT
first also gives the wrong behaviour:

  > runListT test >>= mapM_ putChar

I am really confused about your statement that ListT as found in GHC 6.6
can be used to solve my problem.  I'd like to avoid using
unsafeInterleaveIO if there's a nice solution for it.  IMHO a solution
with ListT would be nice, so I'd really like to understand how to make
it work the way I want it.

/M

-- 
Magnus Therning                             (OpenPGP: 0xAB4DFBA4)
magnus at therning.org             Jabber: magnus.therning at gmail.com
http://therning.org/magnus
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20070126/96a29bd3/attachment.bin


More information about the Haskell-Cafe mailing list