例如,我有一个函数。
function :: x -> y -> z -> v -> Bool
如果在守卫中函数等于True,我想做点什么:
| something = do something
| function == True = do something
| something = something do something
如何使用正确的语法实现它?
答案 0 :(得分:5)
你可以简单地在守卫中调用该功能。 例如:
bar :: Int -> Int
bar x = x*x
baz :: Int -> Int
baz x = x+2
baw :: Int -> Bool -- note: this returns a Bool instead
baw x = x < 12
foo :: Int -> Int -> String
foo x y
| x > 2 = "a"
| bar x + baz y < 100 = "b"
| baw x = "c"
| otherwise = "d"