これが私の最初のコードです
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 が書いた 2 番目のコードです。
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>