相同的符號,但非常不同的錯誤消息這是我的第一代碼兩個在終端
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>
Thx男人,我們的代碼是完美的XD – libra