Skip to content

Instantly share code, notes, and snippets.

@kowey
Created January 2, 2010 14:45
Show Gist options
  • Save kowey/267515 to your computer and use it in GitHub Desktop.
Save kowey/267515 to your computer and use it in GitHub Desktop.
import Control.Monad.Writer
import Control.Monad.Maybe
type FooM a = MaybeT (Writer [String]) a
test =
do print (runIt warningFail) -- I want [ 'failure' ]
print (runIt warningSuccess) -- I want [ 'success' ]
print (runIt (warningFail >> warningSuccess)) -- I want [ 'failure' ]
print (runIt (warningSuccess >> warningFail)) -- I want [ 'success', 'failure' ]
where
runIt = runWriter . runMaybeT
warningSuccess :: FooM Int
warningSuccess =
do tell [ "success" ]
return (42 :: Int)
warningFail :: FooM ()
warningFail =
do tell [ "failure" ]
fail "argh"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment