Skip to content

Instantly share code, notes, and snippets.

@mankyKitty
Last active August 29, 2015 14:10
Show Gist options
  • Save mankyKitty/1a7e0a4f315e6b79904e to your computer and use it in GitHub Desktop.
Save mankyKitty/1a7e0a4f315e6b79904e to your computer and use it in GitHub Desktop.
{-# LANGUAGE OverloadedStrings #-}
module Main where
import Prelude hiding (first)
import Control.Applicative
import Data.Text (Text)
import qualified Data.Text as T
import Control.Monad.Trans.Either
import Control.Error ((??))
import Control.Monad.Trans (liftIO)
import Data.Bifunctor (first)
data Snarf
= Foodly
| Goop
deriving Show
data Gloop
= Glarg
| Gulp
deriving Show
data GurgErr
= GErrOne
| GErrTwo
deriving Show
data Garg = GargleBlast GurgErr
deriving Show
goof :: EitherT Garg IO Snarf
goof = EitherT . return .
first (const GargleBlast GErrOne) $ Right Foodly
main :: IO ()
main = do
e <- runEitherT $ garf =<< goof
case e of
Left err -> print e
Right _ -> putStrLn "FIRE ZE MISSILEZ!"
foo :: Snarf -> IO (Maybe Gloop)
foo Foodly = return $ Just Gulp
foo _ = return Nothing
garf :: Snarf -> EitherT Garg IO ()
garf s = do
a <- liftIO $ foo s
_ <- a ?? (GargleBlast GErrTwo)
liftIO $ print a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment