Skip to content

Instantly share code, notes, and snippets.

@hasufell hasufell/Test.hs
Created Apr 30, 2016

Embed
What would you like to do?
-- |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
You can’t perform that action at this time.