Skip to content

Instantly share code, notes, and snippets.

@xkikeg
Created July 4, 2013 06:10
Show Gist options
  • Save xkikeg/5925254 to your computer and use it in GitHub Desktop.
Save xkikeg/5925254 to your computer and use it in GitHub Desktop.
Maybeならguardで例外送出がかけるけどEitherならどうするんだろう?
import Data.Either
import Control.Monad
failable :: Int -> Maybe Int
failable x = do
guard $ x /= 0
guard $ x /= 10
return $ x + 10
doFailable :: Int -> IO ()
doFailable x = do
let y = failable x
case y of
Nothing -> putStrLn "Error!"
Just z -> print z
main :: IO ()
main = do
doFailable 10
doFailable 200
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment