manually defining boolean conjunction
In chapter 4 of Erik Meijer on Functional Programming Fundamentals, he essentially writes:
True &&& x | x == True = True
| x == False = False
Isn't开发者_如何转开发 this unnecessarily verbose? Couldn't I just write:
True &&& x = x
or even:
(&&&) True = id
(&&&) False = const False
By the way, how come I cannot write the following?
(True &&&) = id
(False &&&) = const False
ghci responds with:
Parse error in pattern: True &&&
Yes, the way you define it is better. From the Prelude:
True && x = x
False && _ = False
You can only use sections in expressions, not in patterns. There is no deep reason why (True &&)
shouldn't be allowed in a pattern. But it's such a rare thing to want that I don't think it's worth the complication.
精彩评论