<div dir="ltr">Hello Haskell-beginners,<br><br>I'm trying to work through the "Write Yourself a Scheme in 48 Hours" tutorial. One of the<br>first exercises calls for writing code to sum up arguments on command line and display<br>
the sum.<br><br>After a few tries, this worked for me:<br><br>module Main where<br>import System.Environment<br><br>main :: IO ()<br>main = do args <- getArgs<br> putStrLn ("Hello, " ++ show (sumIt args))<br>
where sumIt x = sum $ map read x<br><br>However, I have two basic questions:<br><br>1. I initially tried putStrLn("Hello, " ++ show $ sumIt args), but that didn't compile. Why not?<br>If I wrap (show $ sumIt args) in parens, it works, but should I have to, if I didn't have to in<br>
the original code above?<br><br>2. I initially tried <br><br>where sumIt = sum $ map read<br><br>(the "point-free" style, I believe it's called?) but that didn't compile. Why not? A friend suggested<br><br>
where sumIt = sum . map read<br><br>and that does work; I guess my real problem, then, is that I don't really understand the difference <br>between the two and why the former doesn't work.<br><br>Thanks in advance,<br>
Anatoly.<br><br>-- <br>Anatoly Vorobey, <a href="mailto:avorobey@gmail.com">avorobey@gmail.com</a><br><a href="http://avva.livejournal.com">http://avva.livejournal.com</a> (Russian)<br><a href="http://www.lovestwell.org">http://www.lovestwell.org</a> (English)<br>
</div>