Skip to content

Instantly share code, notes, and snippets.

@hvr
Created July 20, 2015 09:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hvr/d2da92060715bc23f882 to your computer and use it in GitHub Desktop.
Save hvr/d2da92060715bc23f882 to your computer and use it in GitHub Desktop.
{-# 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