Let's say I want to define odd
in Haskell. How I would go about it is of course not . even
. However, that's exactly the same as not $ even
or not (even)
. What's the advantage of using (.)
instead of one of the other two options? I know it's encouraged, but I don't know why exactly.
Asked
Active
Viewed 193 times
0

Thomas
- 261
- 1
- 7
-
This is incorrect, I suggest you test those in GHCi, especially `not (even)`. `not . even $ x` *happens* to work the same as `not $ even $ x`, but that's just an accident of precedence: the latter is parsed as `not $ (even $ x)`. – Ørjan Johansen Sep 28 '15 at 17:51
-
As they say in the vernacular, "not even!" – dfeuer Sep 28 '15 at 17:53
-
@dfeuer I don't think is a duplicate..... – dsign Sep 28 '15 at 17:56
-
@ØrjanJohansen Even if the example is incorrect, I would also like to know why the dot is encouraged. I think is a good question. – dsign Sep 28 '15 at 17:57
-
It's function composition, gives more mathematical flavor and enables talking about functions without values (points). – karakfa Sep 28 '15 at 17:59
-
@dsign, see [What is a canonical question/answer and what is their purpose?](http://meta.stackoverflow.com/questions/291992/what-is-a-canonical-question-answer-and-what-is-their-purpose). – dfeuer Sep 28 '15 at 18:04
-
@dfeuer Ah, but it is a duplicate of the one given by Sam! – dsign Sep 28 '15 at 18:07
-
1@dsign I guess it is, although I'm not sure I agree Don's top-voted answer is the best one. – Ørjan Johansen Sep 28 '15 at 18:10