Is it possible to use guards to define a function after a where is Haskell?
This works fine :
myMax a b = a + b - myMin a b
where myMin a b = if a < b then a else b
But this
myMax a b = a + b - myMin a b
where myMin a b
| a < b = a
| otherwise = b
will throw the following error message in ghci :
parse error (possibly incorrect indentation or mismatched brackets)
on the line corresponding to | a < b = a
Just as well, this will work :
myMax a b =
let myMin a b = if a < b then a else b
in a + b - myMin a b
But this won't :
myMax a b =
let myMin a b
| a < b = b
| otherwise = a
in a + b - myMin a b
My guess would be that it's because using guards does not actually define a variable, even though it is required by the where and let/in structures? I am very new to Haskell so any explanation is greatly welcome!