{-# LANGUAGE ScopedTypeVariables, StandaloneDeriving, TemplateHaskell #-}
module Debian.Loc
    ( __LOC__
    , mapExn
    ) where

import Control.Applicative ((<$>), (<*>), pure)
import Control.Exception (Exception, throw)
import Control.Monad.Catch (MonadCatch, catch)
import Language.Haskell.TH

__LOC__ :: Q Exp
__LOC__ :: Q Exp
__LOC__ = Q Loc
location Q Loc -> (Loc -> Q Exp) -> Q Exp
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \ Loc
x ->
             Name -> [Q (Name, Exp)] -> Q Exp
recConE 'Loc [ (,) (Name -> Exp -> (Name, Exp)) -> Q Name -> Q (Exp -> (Name, Exp))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Name -> Q Name
forall (f :: * -> *) a. Applicative f => a -> f a
pure 'loc_filename) Q (Exp -> (Name, Exp)) -> Q Exp -> Q (Name, Exp)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Lit -> Q Exp
litE (String -> Lit
stringL (Loc -> String
loc_filename Loc
x))
                          , (,) (Name -> Exp -> (Name, Exp)) -> Q Name -> Q (Exp -> (Name, Exp))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Name -> Q Name
forall (f :: * -> *) a. Applicative f => a -> f a
pure 'loc_package) Q (Exp -> (Name, Exp)) -> Q Exp -> Q (Name, Exp)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Lit -> Q Exp
litE (String -> Lit
stringL (Loc -> String
loc_package Loc
x))
                          , (,) (Name -> Exp -> (Name, Exp)) -> Q Name -> Q (Exp -> (Name, Exp))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Name -> Q Name
forall (f :: * -> *) a. Applicative f => a -> f a
pure 'loc_module) Q (Exp -> (Name, Exp)) -> Q Exp -> Q (Name, Exp)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Lit -> Q Exp
litE (String -> Lit
stringL (Loc -> String
loc_module Loc
x))
                          , (,) (Name -> Exp -> (Name, Exp)) -> Q Name -> Q (Exp -> (Name, Exp))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Name -> Q Name
forall (f :: * -> *) a. Applicative f => a -> f a
pure 'loc_start) Q (Exp -> (Name, Exp)) -> Q Exp -> Q (Name, Exp)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> [|($(litE (integerL (fromIntegral (fst (loc_start x))))),
                                                             $(litE (integerL (fromIntegral (snd (loc_start x)))))) :: (Int, Int)|]
                          , (,) (Name -> Exp -> (Name, Exp)) -> Q Name -> Q (Exp -> (Name, Exp))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Name -> Q Name
forall (f :: * -> *) a. Applicative f => a -> f a
pure 'loc_end) Q (Exp -> (Name, Exp)) -> Q Exp -> Q (Name, Exp)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> [|($(litE (integerL (fromIntegral (fst (loc_end x))))),
                                                           $(litE (integerL (fromIntegral (snd (loc_end x)))))) :: (Int, Int)|] ]

mapExn :: forall e m a. (MonadCatch m, Exception e) => m a -> (e -> e) -> m a
mapExn :: m a -> (e -> e) -> m a
mapExn m a
task e -> e
f = m a
task m a -> (e -> m a) -> m a
forall (m :: * -> *) e a.
(MonadCatch m, Exception e) =>
m a -> (e -> m a) -> m a
`catch` (\ (e
e :: e) -> e -> m a
forall a e. Exception e => e -> a
throw (e -> e
f e
e))