Created
April 30, 2016 21:08
-
-
Save hasufell/1cd5da9ac3c2d29713e10e97131a9263 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- |Testing `Alternative` instance behavior via (<|>) | |
-- in conjunction with Exceptions. | |
-- | |
-- Behavior is not consistent. | |
module Test where | |
import Control.Applicative | |
import Control.Monad.Catch | |
import Data.Typeable | |
test1 :: IO () | |
test1 = (fail "") <|> print "abc" | |
test2 :: IO () | |
test2 = (throwM $ userError "") <|> print "abc" | |
data MyException = MkException String | |
deriving (Show, Eq, Typeable) | |
instance Exception MyException | |
test3 :: IO () | |
test3 = (throwM $ MkException "") <|> print "abc" | |
{-- | |
running: | |
*Test> test1 | |
"abc" | |
*Test> test2 | |
"abc" | |
*Test> test3 | |
*** Exception: MkException "" | |
types: | |
*Test> :t fail "" | |
fail "" :: Monad m => m a | |
*Test> :t throwM $ userError "" | |
throwM $ userError "" :: MonadThrow m => m a | |
*Test> :t throwM $ MkException "" | |
throwM $ MkException "" :: MonadThrow m => m a | |
--} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment