[Haskell-begin] some basic syntax questions
avorobey at gmail.com
Fri Jul 25 15:45:45 EDT 2008
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
After a few tries, this worked for me:
module Main where
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
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Beginners