Last active
August 29, 2015 14:06
-
-
Save sinelaw/812a82efeed97352d557 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
module Test where | |
import Data.Maybe | |
import Control.Monad | |
import Control.Monad.Trans | |
import Control.Monad.Trans.Maybe | |
import Control.Monad.Trans.Maybe(MaybeT(..)) | |
import Control.Monad.State(State, runState, forM, get, put) | |
positiveOnly :: Int -> Maybe Int | |
positiveOnly x = if x > 0 then Just x else Nothing | |
f :: MaybeT (State Int) () | |
f = do | |
state <- get | |
-- how to get rid of the 'case' by taking advantage of monad transformers? | |
case positiveOnly state of | |
Nothing -> mzero | |
Just x' -> put $ x' - 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment