<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<META NAME="Generator" CONTENT="MS Exchange Server version 6.5.7653.38">
<TITLE>One liner?</TITLE>
</HEAD>
<BODY>
<!-- Converted from text/plain format -->
<P><FONT SIZE=2>Hi all,<BR>
<BR>
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:<BR>
<BR>
----------------------------------------------<BR>
module Main where<BR>
<BR>
import System.Directory (getDirectoryContents)<BR>
<BR>
main = do dc <- getDirectoryContents "./foo/"<BR>
mapM_ putStrLn dc<BR>
----------------------------------------------<BR>
<BR>
But if I try to avoid the use of the bind to "dc", I fail:<BR>
<BR>
----------------------------------------------<BR>
mapM_ putStrLn (getDirectoryContents "./foo/")<BR>
----------------------------------------------<BR>
<BR>
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.<BR>
<BR>
Cheers,<BR>
Paul<BR>
<BR>
<BR>
Couldn't match expected type `[String]'<BR>
against inferred type `IO [FilePath]'<BR>
In the second argument of `mapM_', namely<BR>
`(getDirectoryContents "./foo/")'<BR>
In the expression: mapM_ putStrLn (getDirectoryContents "./foo/")<BR>
In the definition of `main':<BR>
main = mapM_ putStrLn (getDirectoryContents "./foo/")<BR>
</FONT>
</P>
</BODY>
</HTML>