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
|
2014-06-28 19:43:51 +00:00
|
|
|
import 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.
|
2014-06-28 19:43:51 +00:00
|
|
|
(||>) :: GhcMonad m => m a -> m a -> m 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'.
|
2014-06-28 19:43:51 +00:00
|
|
|
goNext :: GhcMonad m => m 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.
|
2014-06-28 19:43:51 +00:00
|
|
|
runAnyOne :: GhcMonad m => [m a] -> m a
|
2012-02-16 05:44:20 +00:00
|
|
|
runAnyOne = foldr (||>) goNext
|