Reputation: 11
For example, I have a function below.
function :: x -> y -> z -> v -> Bool
I want to do something if function is equal to True in guards like:
| something = do something
| function == True = do something
| something = something do something
How can I implement it using a correct syntax?
Upvotes: 0
Views: 1042
Reputation: 116139
You can simply call the function in your guard. Example:
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"
Upvotes: 5