2012-02-16 05:44:20 +00:00
|
|
|
{-# LANGUAGE ScopedTypeVariables #-}
|
|
|
|
|
2013-05-17 01:00:01 +00:00
|
|
|
module Language.Haskell.GhcMod.GHCChoice where
|
2012-02-16 05:44:20 +00:00
|
|
|
|
2014-03-27 06:45:51 +00:00
|
|
|
import Control.Exception (IOException)
|
2014-03-27 06:08:07 +00:00
|
|
|
import CoreMonad (liftIO)
|
2014-03-27 06:45:51 +00:00
|
|
|
import qualified Exception as GE
|
|
|
|
import GHC (Ghc, GhcMonad)
|
2012-02-16 05:44:20 +00:00
|
|
|
|
|
|
|
----------------------------------------------------------------
|
|
|
|
|
2013-09-16 00:56:08 +00:00
|
|
|
-- | Try the left 'Ghc' action. If 'IOException' occurs, try
|
|
|
|
-- the right 'Ghc' action.
|
2012-02-16 05:44:20 +00:00
|
|
|
(||>) :: Ghc a -> Ghc a -> Ghc a
|
2014-03-27 06:45:51 +00:00
|
|
|
x ||> y = x `GE.gcatch` (\(_ :: IOException) -> y)
|
2012-02-16 05:44:20 +00:00
|
|
|
|
2013-09-16 00:56:08 +00:00
|
|
|
-- | Go to the next 'Ghc' monad by throwing 'AltGhcgoNext'.
|
2012-02-16 05:44:20 +00:00
|
|
|
goNext :: Ghc a
|
2014-03-27 06:45:51 +00:00
|
|
|
goNext = liftIO . GE.throwIO $ userError "goNext"
|
2012-02-16 05:44:20 +00:00
|
|
|
|
2013-09-16 00:56:08 +00:00
|
|
|
-- | Run any one 'Ghc' monad.
|
2012-02-16 05:44:20 +00:00
|
|
|
runAnyOne :: [Ghc a] -> Ghc a
|
|
|
|
runAnyOne = foldr (||>) goNext
|
2013-09-16 00:56:08 +00:00
|
|
|
|
|
|
|
----------------------------------------------------------------
|
|
|
|
|
|
|
|
-- | Try the left 'GhcMonad' action. If 'IOException' occurs, try
|
|
|
|
-- the right 'GhcMonad' action.
|
|
|
|
(|||>) :: GhcMonad m => m a -> m a -> m a
|
2014-03-27 06:45:51 +00:00
|
|
|
x |||> y = x `GE.gcatch` (\(_ :: IOException) -> y)
|