
Hello, I'm starting to use Haskell for writing actual programs using monads and I'm already lost. I have the following script: #!/usr/bin/runhugs
module Main where import System(getArgs) main = do putStr "Hello, World\n" strs <- getArgs map putStrLn strs
Which gives the following error: runhugs: Error occurred Reading file "./mailalias.lhs": Reading file "/usr/lib/hugs/lib/System.hs": Reading file "./mailalias.lhs": Type checking ERROR "./mailalias.lhs":5 - Type error in final generator *** Term : map putStrLn strs *** Type : [IO ()] *** Does not match : IO a Can someone please explain what I'm doing wrong? Thanks!

On 12 Sep 2003 22:08:30 -0000 kuq32tr02@sneakemail.com wrote:
Hello,
I'm starting to use Haskell for writing actual programs using monads and I'm already lost.
I have the following script:
#!/usr/bin/runhugs
module Main where import System(getArgs) main = do putStr "Hello, World\n" strs <- getArgs map putStrLn strs
Which gives the following error:
runhugs: Error occurred Reading file "./mailalias.lhs": Reading file "/usr/lib/hugs/lib/System.hs": Reading file "./mailalias.lhs": Type checking ERROR "./mailalias.lhs":5 - Type error in final generator *** Term : map putStrLn strs *** Type : [IO ()] *** Does not match : IO a
Can someone please explain what I'm doing wrong?
map :: (a -> b) -> [a] -> [b] putStrLn :: String -> IO () therefore map putStrLn :: [String] -> [IO ()] map maps a -pure function- over a list. What you want is to map a -monadic computation- over the list, further you don't care about the result. mapM_ :: Monad m => (a -> m b) -> [a] -> m () mapM_ putStrLn :: [String] -> IO ()

Alle 00:08, sabato 13 settembre 2003, kuq32tr02@sneakemail.com ha scritto:
ERROR "./mailalias.lhs":5 - Type error in final generator *** Term : map putStrLn strs *** Type : [IO ()] *** Does not match : IO a
Can someone please explain what I'm doing wrong?
This is a type error. You have to "mapM_", not map, see the types in the documentation and try to convince yourself that you need an IO list and not a list of IO, then that you really need an IO () and not an IO list (wich would be returned by mapM). The syntax for a list of t in haskell is [t], in case you didn't notice. V.
participants (3)
-
Derek Elkins
-
kuq32tr02@sneakemail.com
-
Nick Name