Skip to content

Instantly share code, notes, and snippets.

@sinelaw
Last active August 29, 2015 14:06
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 sinelaw/812a82efeed97352d557 to your computer and use it in GitHub Desktop.
Save sinelaw/812a82efeed97352d557 to your computer and use it in GitHub Desktop.
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