ghc-mod/Language/Haskell/GhcMod/GHCChoice.hs

24 lines
696 B
Haskell
Raw Normal View History

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