开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜