[Haskell-cafe] One liner?
Paul Keir
pkeir at dcs.gla.ac.uk
Thu Oct 2 11:20:18 EDT 2008
Hi all,
There's a common little situation I keep bumping up against. I don't understand where I'm going wrong, so I've made a little example. It's to do with binding a result to a variable name using "<-". This code works fine:
----------------------------------------------
module Main where
import System.Directory (getDirectoryContents)
main = do dc <- getDirectoryContents "./foo/"
mapM_ putStrLn dc
----------------------------------------------
But if I try to avoid the use of the bind to "dc", I fail:
----------------------------------------------
mapM_ putStrLn (getDirectoryContents "./foo/")
----------------------------------------------
I've tried using map instead of mapM_, and inserted "return"s here and there, but no luck. Can anyone tell me where and why I'm going wrong? The error message is below.
Cheers,
Paul
Couldn't match expected type `[String]'
against inferred type `IO [FilePath]'
In the second argument of `mapM_', namely
`(getDirectoryContents "./foo/")'
In the expression: mapM_ putStrLn (getDirectoryContents "./foo/")
In the definition of `main':
main = mapM_ putStrLn (getDirectoryContents "./foo/")
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20081002/fb315acc/attachment.htm
More information about the Haskell-Cafe
mailing list