这是我的第一个代码
maybe_devide :: Maybe Integer -> Maybe Integer -> Maybe Integer
maybe_devide maybeX maybeY = case (maybeX, maybeY) of
(Just x, Just y)
|x/=0 && y/=0 -> Just (div x y)
|x==0 && y/=0 -> Just 0
|x/=0 && y==0 -> Nothing
(Nothing, Just y) -> Nothing
(Just x, Nothing) -> Nothing
代码 1 的错误消息如下所示:
[1 of 1] Compiling Main ( test2.hs, interpreted )
test2.hs:1:246: parse error on input `->'
Failed, modules loaded: none.
这是我的朋友 Bryan Olivier 编写的第二个代码:
maybe_devide :: Maybe Integer -> Maybe Integer -> Maybe Integer
maybe_devide maybeX maybeY = case (maybeX, maybeY) of
(Just x, Just y)
|x/=0 && y/=0 -> Just (div x y)
|x==0 && y/=0 -> Just 0
|x/=0 && y==0 -> Nothing
(Nothing, Just y) -> Nothing
(Just x, Nothing) -> Nothing
但是,这次的错误信息有所不同:
Warning: Pattern match(es) are non-exhaustive
In a case alternative:
Patterns not matched:
(Nothing, Nothing)
(Just _, Just _)
test.hs:7:18: Warning: Defined but not used: `y'
test.hs:8:9: Warning: Defined but not used: `x'
Ok, modules loaded: Main.
*Main>