Hi I can’t figure this out myself and i also couldn’t find an example online
I’m trying to use a maybe or a guard and the examples i found have just two variables,
when i edit or follow the examples with more then two i get an error heres what i am trying to do
--maybe example
Fun :: Double -> Double -> Double -> Maybe Double
Fun a b c
| a >= -1.0 || a <= 1.0 || b >= -1.0 || b <=1.0 || c /=0 || c >= -1.0 = Nothing
| otherwise = Just max( ((c^ (-c)) + (a^(-c)-1.0) ^ (a+ (-1.0/a))) 0.0)
error with gchi
The function `Just' is applied to two arguments,
but its type `a0 -> Maybe a0' has only one
while hlint gives
No suggestions
trying to use a guard instead i get a different error
--guard example
Fun :: Double -> Double -> Double -> Maybe Double
Fun a b c
| a >= -1.0 || a <= 1.0 || b >= -1.0 || b <=1.0 || c /=0 || c >= -1.0 = error "Value out of range "
| otherwise = max( ((c^ (-c)) + (a^(-c)-1.0) ^ (a+ (-1.0/a))) 0.0)
and heres ghc and hlints errors
test.hs:10:1:
Invalid type signature: Fun :: Double
-> Double -> Double -> Maybe Double
Should be of form <variable> :: <type>
$ hlint test.hs
Error message:
Left-hand side of type signature is not a variable: Fun
Code:
Fun :: Double -> Double -> Double -> Maybe Double
> Fun a b c
You must write functions with a lower-case letter. This means writing this:
Functions can never start with upper-case letters, since upper-case identifiers are reserved for modules (
Data.Listfor example) and type constructors and data constructors (likeIntorMaybeorJust) and some other things.You also have an issue with the application of the
Justconstructor. If you write this:… it means the same thing as:
i.e. you are giving
Justtwo arguments. You need to fix this by adjusting your parens: