Last active
August 20, 2018 18:23
-
-
Save joshuakfarrar/d705c5f462b21cf20c906afc5eb8dcf8 to your computer and use it in GitHub Desktop.
Using ExceptT to catch errors in Haskell.
This file contains hidden or 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
{-# LANGUAGE NoImplicitPrelude #-} | |
module Main where | |
import Protolude | |
import qualified Data.Text as T | |
calculateThing :: ExceptT Text IO Text | |
calculateThing = do | |
print $ T.pack "log" | |
return $ T.pack "uccess" | |
--throwError $ T.pack "fail" | |
main :: IO () | |
main = do | |
{- | |
need to modify the wrapped value? | |
fmap a lambda over ExceptT! (fmap (b -> c) (m a b) returns (m a c)) | |
-} | |
result <- runExceptT $ fmap (\x -> T.cons 's' x) calculateThing | |
case result of | |
Right success -> putStrLn success | |
Left error -> putStrLn error |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment