Skip to content

Instantly share code, notes, and snippets.

Created July 20, 2015 09:22
What would you like to do?
{-# LANGUAGE ScopedTypeVariables #-}
import Control.Monad.Identity
import Control.Monad.Except
import Control.Monad.State.Strict
type SET s e m = StateT s (ExceptT e m)
type EST e s m = ExceptT e (StateT s m)
type SE s e = StateT s (Except e)
type ES e s = ExceptT e (State s)
data St = St
data Err = Err
-- errors w/ rollback
runES :: forall e s a . ES e s a -> s -> (Either e a, s)
runES act s0 = runState (runExceptT act :: State s (Either e a)) s0
-- errors w/o rollback
runSE :: forall s e a . SE s e a -> s -> Either e (a,s)
runSE act s0 = runExcept (runStateT act s0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment