I a fresh man in Haskell. Here is my program :
maybe_divide :: Maybe Integer -> Maybe Integer -> Maybe Integer
maybe_divide a b = case (a, b) of
(Just a, Just b)
| (Just a, Just b)
| (Nothing, _) -> Nothing
| (_, Just 0) -> Nothing
| (_, Nothing) -> Nothing
| (Just a,Just b) -> Just (a `div` b)
The compiler shows that: pattern syntax in expression context:_. When I just use case without guards it works. Why it doesn't work within guards?
As mentioned in the post guards are not needed for pattern matching. You can remove some cases that are superfluous.
But You don't have to write that function at all. Because Maybe is a Monad you can just write this.
And then to get your version of maybe_divide you can write this.
Which may be easier to read as this.