The code is morally correct but lacking in a few places. The conditional stuff is actually fine, the part that's tripping you up is
- Indicating that you want a tuple
- Constructing a
Maybe
value
First of all, the type Maybe Float Float
is ill-formed, Maybe
takes one type argument not two, I think you mean Maybe (Float, Float)
which should be read as "A Maybe
of a pair of floats". Then to construct a single expression of type (Float, Float)
we use (-, -)
. So instead of a b
which really means "a
applied as a function to b
" we'd have (a, b)
, a pair of a
and b
. Last but not least, we want to construct a Maybe
in the end so we need to explicitly wrap the whole tuple in the Just
constructor leaving us with Just (a, b)
.
test :: Float -> Float -> Maybe (Float, Float)
test a b
| a>0 && b>0 = Just (a, b)
| otherwise = Nothing
I
is always capitalized.Maybe
constructor only takes one type. If you want two, you're going to have to pair the Floats some way. Sadly, I'm not that familiar with Haskell to point you towards how to do that.