Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 &&&
like image 262
fredoverflow Avatar asked Aug 28 '11 10:08

fredoverflow


1 Answers

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.

like image 127
augustss Avatar answered Oct 09 '22 21:10

augustss