Last active
January 14, 2020 09:19
-
-
Save monadplus/97c1f47d03689cee903f32f7e8dadf25 to your computer and use it in GitHub Desktop.
Non-algebraic op
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 FlexibleContexts #-} | |
-- Credit for this code to: https://github.com/pva701 | |
module Task0 | |
( f | |
, f1 | |
, f2 | |
)where | |
import Control.Monad.Except (throwError, runExceptT, catchError, MonadError, runExcept) | |
import Control.Monad.State (runState, modify, MonadState, runStateT) | |
f :: (MonadError String m, MonadState Int m) => m () | |
f = | |
(modify (const 5) *> throwError "Nope") | |
`catchError` \_ -> pure () | |
f1 :: (Either String (), Int) | |
f1 = flip runState 0 $ runExceptT f | |
f2 :: Either String ((), Int) | |
f2 = runExcept $ runStateT f 0 | |
-- *Main> f1 | |
-- (Right (),5) | |
-- *Main> f2 | |
-- Right ((),0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment