Created
July 20, 2015 09:22
-
-
Save hvr/d2da92060715bc23f882 to your computer and use it in GitHub Desktop.
This file contains 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 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