Skip to content

Instantly share code, notes, and snippets.

@tanakh
Created June 29, 2012 06:57
Show Gist options
  • Select an option

  • Save tanakh/3016373 to your computer and use it in GitHub Desktop.

Select an option

Save tanakh/3016373 to your computer and use it in GitHub Desktop.
Alternative for MonadBaseControl IO
{-# 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