Skip to content

Instantly share code, notes, and snippets.

@hasufell
Created April 30, 2016 21:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hasufell/1cd5da9ac3c2d29713e10e97131a9263 to your computer and use it in GitHub Desktop.
Save hasufell/1cd5da9ac3c2d29713e10e97131a9263 to your computer and use it in GitHub Desktop.
-- |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