Created
June 29, 2012 06:57
-
-
Save tanakh/3016373 to your computer and use it in GitHub Desktop.
Alternative for MonadBaseControl IO
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 FlexibleInstances, UndecidableInstances, OverlappingInstances #-} | |
| import Control.Applicative | |
| import Control.Exception.Lifted | |
| import Control.Monad.State | |
| import Control.Monad.Trans | |
| import Control.Monad.Trans.Control | |
| import Prelude hiding (catch) | |
| instance (MonadBaseControl IO m) => Alternative m where | |
| -- empty :: m a | |
| empty = throwIO $ userError "empty IO" | |
| -- (<|>) :: m a -> m a -> m a | |
| a <|> b = a `catch` (\(SomeException _) -> b) | |
| main :: IO () | |
| main = do | |
| undefined <|> putStrLn "hello" | |
| (`evalStateT` ()) $ do | |
| undefined <|> liftIO (putStrLn "world") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment