[Haskell-begin] some basic syntax questions

Anatoly Vorobey avorobey at gmail.com
Fri Jul 25 15:45:45 EDT 2008

Hello Haskell-beginners,

I'm trying to work through the "Write Yourself a Scheme in 48 Hours"
tutorial. One of the
first exercises calls for writing code to sum up arguments on command line
and display
the sum.

After a few tries, this worked for me:

module Main where
import System.Environment

main :: IO ()
main = do args <- getArgs
          putStrLn ("Hello, " ++ show (sumIt args))
       where sumIt x = sum $ map read x

However, I have two basic questions:

1. I initially tried putStrLn("Hello, " ++ show $ sumIt args), but that
didn't compile. Why not?
If I wrap (show $ sumIt args) in parens, it works, but should I have to, if
I didn't have to in
the original code above?

2. I initially tried

where sumIt = sum $ map read

(the "point-free" style, I believe it's called?) but that didn't compile.
Why not? A friend suggested

where sumIt = sum . map read

and that does work; I guess my real problem, then, is that I don't really
understand the difference
between the two and why the former doesn't work.

Thanks in advance,

Anatoly Vorobey, avorobey at gmail.com
http://avva.livejournal.com (Russian)
http://www.lovestwell.org (English)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/beginners/attachments/20080725/fc8fd05c/attachment.htm

More information about the Beginners mailing list