有没有一种方法可以重构这个代码:
let collide (b1 : Box) (b2 : Box) =
if bottom b1 > top b2
then false
else if top b1 < bottom b2
then false
else if right b1 < left b2
then false
else if left b1 > right b2
then false
else true
以比这更易读的方式:
let collide (b1 : Box) (b2 : Box) =
match () with
| _ when bottom b1 > top b2 -> false
| _ when top b1 < bottom b2 -> false
| _ when right b1 < left b2 -> false
| _ when left b1 > right b2 -> false
| _ -> true
我在考虑与GHC 7.6.1中的多路if表达式类似的东西:http://www.haskell.org/ghc/docs/7.6.1/html/users_guide/syntax-extns.html#multi-way-if。
bottom b1<=top b2 && ...
- undefinednot (bottom ... && .... && ........)
,如何处理? - undefinednot
真的不是 :),(not a)&&(not b)
的等价表达式是not(a||b)
- undefined