Skip to content

Instantly share code, notes, and snippets.

@MiyamonY
Created March 5, 2015 09:13
Show Gist options
  • Save MiyamonY/cefa30d2cbdcbf5a0a40 to your computer and use it in GitHub Desktop.
Save MiyamonY/cefa30d2cbdcbf5a0a40 to your computer and use it in GitHub Desktop.
haskell error
import Test.HUnit
import Control.Monad.Except
-- instance (Error e) => Monad (Either e) where
-- return x = Right x
-- Right x >>= f = f x
-- Left err >>= f = Left err
-- fail msg = Left (strMsg msg)
tests = ["Either1" ~: (Left "boom" >>= (\ x -> return . succ $ x)) ~?= (Left "boom" :: Either String Int),
"Either2" ~: (Left "boom" >>= \ x -> (Left "no way!" :: Either String Int) ) ~?= Left "boom",
"Either3" ~: (Right 100 >>= \ x -> (Left "no way" :: Either String Int)) ~?= Left "no way"]
runTests = do
runTestTT $ TestList tests
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment