[Haskell-cafe] Those damned parentheses

Andrew Coppin andrewcoppin at btinternet.com
Tue May 10 19:15:53 CEST 2011


On 10/05/2011 08:30 AM, Yitzchak Gale wrote:

> I think the clearest way to write it is:
>
> f = putStrLn . (++ " - message received") . show . Main.id

You're serious??

> If I were to describe to someone in words what this
> function does, I would say something like: "Apply Main.id,
> turn it into a string, tack a message onto the end, and
> print it." So why not write it that way in Haskell?

Hmm, I suppose.

OTOH, this breaks if you want to insert several items into a string. For 
example,

   f x y z = putStrLn ("X = " ++ show x ++ ", Y = " ++ show y ++ ", Z = 
" ++ show z)

(Fortunately, here a simple call to ($) will fix you up nicely.)



More information about the Haskell-Cafe mailing list