有时我会写这样的代码
solveLogic :: Int -> Int -> Int
solveLogic a b =
let
x = 1
brainiac
| a >= x = 1
| a == b = 333
| otherwise = 5
in
brainiac
每次我都想写这些东西而不需要不需要的“大脑”功能,就像这样:
solveLogic :: Int -> Int -> Int
solveLogic a b =
let
x = 1
in
| a >= x = 1
| a == b = 333
| otherwise = 5
哪个代码更加“哈斯克尔式”。有什么办法可以做到这一点吗?
是的,使用where
clause:
solveLogic a b
| a >= x = 1
| a == b = 333
| otherwise = 5
where
x = 1
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)