[Haskell-cafe] Re: Monad transformer, liftIO
Paolo Losi
paolo.losi at gmail.com
Sat Apr 4 03:52:38 EDT 2009
Michael Roth wrote:
> Hello list,
>
> maybe I'm just stupid, I'm trying to do something like this:
Ciao Michael,
As an alternative solution to Creighton's:
import Control.Monad.List
foobar :: ListT IO Int
foobar = do
a <- ListT . return $ [1,2,3]
b <- ListT . return $ [4,5,6]
liftIO $ putStrLn $ (show a) ++ " " ++ (show b)
return (a+b)
main = do
sums <- runListT foobar
print sums
For the expression ListT . return $ [1,2,3] of type ListT IO Int,
the return inferred is:
return: a -> IO a
return [1,2,3] = IO [1,2,3]
and then you wrap the IO [] with the ListT newtype constructor.
Paolo
More information about the Haskell-Cafe
mailing list