戻り値の型によって結果が変わる例
> :{ *| foo :: MonadThrow m => Int -> m Int *| foo x = (if x == 0 then throwM RatioZeroDenominator else return x) *| :} > :t foo foo :: MonadThrow m => Int -> m Int
IOの場合
> foo 1 :: IO Int 1 > foo 0 :: IO Int *** Exception: Ratio has zero denominator
Eitherの場合
> foo 1 :: Either SomeException Int Right 1 > foo 0 :: Either SomeException Int Left Ratio has zero denominator
Maybeの場合
> foo 1 :: Maybe Int Just 1 > foo 0 :: Maybe Int Nothing
リストの場合
> foo 1 :: [] Int [1] > foo 0 :: [] Int []
例えば、例外の対処のコーディングで、MaybeとEitherの2つ実装をする必要はない。