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

24 lines
696 B
Haskell
Raw Normal View History

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