有没有办法重构这个:
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 .
最佳答案
let collide (b1 : Box) (b2 : Box) =
if bottom b1 > top b2 then false
elif top b1 < bottom b2 then false
elif right b1 < left b2 then false
elif left b1 > right b2 then false
else true
关于haskell - F#有多路if吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12593993/