{-# LANGUAGE CPP, DeriveDataTypeable,
             DeriveGeneric, FlexibleInstances, DefaultSignatures,
             RankNTypes, RoleAnnotations, ScopedTypeVariables,
             MagicHash, KindSignatures, PolyKinds, TypeApplications, DataKinds,
             GADTs, UnboxedTuples, UnboxedSums, TypeInType,
             Trustworthy, DeriveFunctor #-}

{-# OPTIONS_GHC -fno-warn-inline-rule-shadowing #-}

-----------------------------------------------------------------------------
-- |
-- Module      :  Language.Haskell.Syntax
-- Copyright   :  (c) The University of Glasgow 2003
-- License     :  BSD-style (see the file libraries/base/LICENSE)
--
-- Maintainer  :  libraries@haskell.org
-- Stability   :  experimental
-- Portability :  portable
--
-- Abstract syntax definitions for Template Haskell.
--
-----------------------------------------------------------------------------

module Language.Haskell.TH.Syntax
    ( module Language.Haskell.TH.Syntax
      -- * Language extensions
    , module Language.Haskell.TH.LanguageExtensions
    , ForeignSrcLang(..)
    ) where

import Data.Data hiding (Fixity(..))
import Data.IORef
import System.IO.Unsafe ( unsafePerformIO )
import System.FilePath
import GHC.IO.Unsafe    ( unsafeDupableInterleaveIO )
import Control.Monad (liftM)
import Control.Monad.IO.Class (MonadIO (..))
import Control.Monad.Fix (MonadFix (..))
import Control.Applicative (liftA2)
import Control.Exception (BlockedIndefinitelyOnMVar (..), catch, throwIO)
import Control.Exception.Base (FixIOException (..))
import Control.Concurrent.MVar (newEmptyMVar, readMVar, putMVar)
import System.IO        ( hPutStrLn, stderr )
import Data.Char        ( isAlpha, isAlphaNum, isUpper, ord )
import Data.Int
import Data.List.NonEmpty ( NonEmpty(..) )
import Data.Void        ( Void, absurd )
import Data.Word
import Data.Ratio
import GHC.CString      ( unpackCString# )
import GHC.Generics     ( Generic )
import GHC.Types        ( Int(..), Word(..), Char(..), Double(..), Float(..),
                          TYPE, RuntimeRep(..) )
import GHC.Prim         ( Int#, Word#, Char#, Double#, Float#, Addr# )
import GHC.Ptr          ( Ptr, plusPtr )
import GHC.Lexeme       ( startsVarSym, startsVarId )
import GHC.ForeignSrcLang.Type
import Language.Haskell.TH.LanguageExtensions
import Numeric.Natural
import Prelude
import Foreign.ForeignPtr
import Foreign.C.String
import Foreign.C.Types

#if __GLASGOW_HASKELL__ >= 901
import GHC.Types ( Levity(..) )
#endif

-----------------------------------------------------
--
--              The Quasi class
--
-----------------------------------------------------

class (MonadIO m, MonadFail m) => Quasi m where
  qNewName :: String -> m Name
        -- ^ Fresh names

        -- Error reporting and recovery
  qReport  :: Bool -> String -> m ()    -- ^ Report an error (True) or warning (False)
                                        -- ...but carry on; use 'fail' to stop
  qRecover :: m a -- ^ the error handler
           -> m a -- ^ action which may fail
           -> m a               -- ^ Recover from the monadic 'fail'

        -- Inspect the type-checker's environment
  qLookupName :: Bool -> String -> m (Maybe Name)
       -- True <=> type namespace, False <=> value namespace
  qReify          :: Name -> m Info
  qReifyFixity    :: Name -> m (Maybe Fixity)
  qReifyType      :: Name -> m Type
  qReifyInstances :: Name -> [Type] -> m [Dec]
       -- Is (n tys) an instance?
       -- Returns list of matching instance Decs
       --    (with empty sub-Decs)
       -- Works for classes and type functions
  qReifyRoles         :: Name -> m [Role]
  qReifyAnnotations   :: Data a => AnnLookup -> m [a]
  qReifyModule        :: Module -> m ModuleInfo
  qReifyConStrictness :: Name -> m [DecidedStrictness]

  qLocation :: m Loc

  qRunIO :: IO a -> m a
  qRunIO = IO a -> m a
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO
  -- ^ Input/output (dangerous)
  qGetPackageRoot :: m FilePath

  qAddDependentFile :: FilePath -> m ()

  qAddTempFile :: String -> m FilePath

  qAddTopDecls :: [Dec] -> m ()

  qAddForeignFilePath :: ForeignSrcLang -> String -> m ()

  qAddModFinalizer :: Q () -> m ()

  qAddCorePlugin :: String -> m ()

  qGetQ :: Typeable a => m (Maybe a)

  qPutQ :: Typeable a => a -> m ()

  qIsExtEnabled :: Extension -> m Bool
  qExtsEnabled :: m [Extension]

  qPutDoc :: DocLoc -> String -> m ()
  qGetDoc :: DocLoc -> m (Maybe String)

-----------------------------------------------------
--      The IO instance of Quasi
--
--  This instance is used only when running a Q
--  computation in the IO monad, usually just to
--  print the result.  There is no interesting
--  type environment, so reification isn't going to
--  work.
--
-----------------------------------------------------

instance Quasi IO where
  qNewName :: FilePath -> IO Name
qNewName = FilePath -> IO Name
newNameIO

  qReport :: Bool -> FilePath -> IO ()
qReport Bool
True  FilePath
msg = Handle -> FilePath -> IO ()
hPutStrLn Handle
stderr (FilePath
"Template Haskell error: " FilePath -> FilePath -> FilePath
forall a. [a] -> [a] -> [a]
++ FilePath
msg)
  qReport Bool
False FilePath
msg = Handle -> FilePath -> IO ()
hPutStrLn Handle
stderr (FilePath
"Template Haskell error: " FilePath -> FilePath -> FilePath
forall a. [a] -> [a] -> [a]
++ FilePath
msg)

  qLookupName :: Bool -> FilePath -> IO (Maybe Name)
qLookupName Bool
_ FilePath
_       = FilePath -> IO (Maybe Name)
forall a. FilePath -> IO a
badIO FilePath
"lookupName"
  qReify :: Name -> IO Info
qReify Name
_              = FilePath -> IO Info
forall a. FilePath -> IO a
badIO FilePath
"reify"
  qReifyFixity :: Name -> IO (Maybe Fixity)
qReifyFixity Name
_        = FilePath -> IO (Maybe Fixity)
forall a. FilePath -> IO a
badIO FilePath
"reifyFixity"
  qReifyType :: Name -> IO Type
qReifyType Name
_          = FilePath -> IO Type
forall a. FilePath -> IO a
badIO FilePath
"reifyFixity"
  qReifyInstances :: Name -> [Type] -> IO [Dec]
qReifyInstances Name
_ [Type]
_   = FilePath -> IO [Dec]
forall a. FilePath -> IO a
badIO FilePath
"reifyInstances"
  qReifyRoles :: Name -> IO [Role]
qReifyRoles Name
_         = FilePath -> IO [Role]
forall a. FilePath -> IO a
badIO FilePath
"reifyRoles"
  qReifyAnnotations :: forall a. Data a => AnnLookup -> IO [a]
qReifyAnnotations AnnLookup
_   = FilePath -> IO [a]
forall a. FilePath -> IO a
badIO FilePath
"reifyAnnotations"
  qReifyModule :: Module -> IO ModuleInfo
qReifyModule Module
_        = FilePath -> IO ModuleInfo
forall a. FilePath -> IO a
badIO FilePath
"reifyModule"
  qReifyConStrictness :: Name -> IO [DecidedStrictness]
qReifyConStrictness Name
_ = FilePath -> IO [DecidedStrictness]
forall a. FilePath -> IO a
badIO FilePath
"reifyConStrictness"
  qLocation :: IO Loc
qLocation             = FilePath -> IO Loc
forall a. FilePath -> IO a
badIO FilePath
"currentLocation"
  qRecover :: forall a. IO a -> IO a -> IO a
qRecover IO a
_ IO a
_          = FilePath -> IO a
forall a. FilePath -> IO a
badIO FilePath
"recover" -- Maybe we could fix this?
  qGetPackageRoot :: IO FilePath
qGetPackageRoot       = FilePath -> IO FilePath
forall a. FilePath -> IO a
badIO FilePath
"getProjectRoot"
  qAddDependentFile :: FilePath -> IO ()
qAddDependentFile FilePath
_   = FilePath -> IO ()
forall a. FilePath -> IO a
badIO FilePath
"addDependentFile"
  qAddTempFile :: FilePath -> IO FilePath
qAddTempFile FilePath
_        = FilePath -> IO FilePath
forall a. FilePath -> IO a
badIO FilePath
"addTempFile"
  qAddTopDecls :: [Dec] -> IO ()
qAddTopDecls [Dec]
_        = FilePath -> IO ()
forall a. FilePath -> IO a
badIO FilePath
"addTopDecls"
  qAddForeignFilePath :: ForeignSrcLang -> FilePath -> IO ()
qAddForeignFilePath ForeignSrcLang
_ FilePath
_ = FilePath -> IO ()
forall a. FilePath -> IO a
badIO FilePath
"addForeignFilePath"
  qAddModFinalizer :: Q () -> IO ()
qAddModFinalizer Q ()
_    = FilePath -> IO ()
forall a. FilePath -> IO a
badIO FilePath
"addModFinalizer"
  qAddCorePlugin :: FilePath -> IO ()
qAddCorePlugin FilePath
_      = FilePath -> IO ()
forall a. FilePath -> IO a
badIO FilePath
"addCorePlugin"
  qGetQ :: forall a. Typeable a => IO (Maybe a)
qGetQ                 = FilePath -> IO (Maybe a)
forall a. FilePath -> IO a
badIO FilePath
"getQ"
  qPutQ :: forall a. Typeable a => a -> IO ()
qPutQ a
_               = FilePath -> IO ()
forall a. FilePath -> IO a
badIO FilePath
"putQ"
  qIsExtEnabled :: Extension -> IO Bool
qIsExtEnabled Extension
_       = FilePath -> IO Bool
forall a. FilePath -> IO a
badIO FilePath
"isExtEnabled"
  qExtsEnabled :: IO [Extension]
qExtsEnabled          = FilePath -> IO [Extension]
forall a. FilePath -> IO a
badIO FilePath
"extsEnabled"
  qPutDoc :: DocLoc -> FilePath -> IO ()
qPutDoc DocLoc
_ FilePath
_           = FilePath -> IO ()
forall a. FilePath -> IO a
badIO FilePath
"putDoc"
  qGetDoc :: DocLoc -> IO (Maybe FilePath)
qGetDoc DocLoc
_             = FilePath -> IO (Maybe FilePath)
forall a. FilePath -> IO a
badIO FilePath
"getDoc"

instance Quote IO where
  newName :: FilePath -> IO Name
newName = FilePath -> IO Name
newNameIO

newNameIO :: String -> IO Name
newNameIO :: FilePath -> IO Name
newNameIO FilePath
s = do { Uniq
n <- IORef Uniq -> (Uniq -> (Uniq, Uniq)) -> IO Uniq
forall a b. IORef a -> (a -> (a, b)) -> IO b
atomicModifyIORef' IORef Uniq
counter (\Uniq
x -> (Uniq
x Uniq -> Uniq -> Uniq
forall a. Num a => a -> a -> a
+ Uniq
1, Uniq
x))
                 ; Name -> IO Name
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (FilePath -> Uniq -> Name
mkNameU FilePath
s Uniq
n) }

badIO :: String -> IO a
badIO :: forall a. FilePath -> IO a
badIO FilePath
op = do   { Bool -> FilePath -> IO ()
forall (m :: * -> *). Quasi m => Bool -> FilePath -> m ()
qReport Bool
True (FilePath
"Can't do `" FilePath -> FilePath -> FilePath
forall a. [a] -> [a] -> [a]
++ FilePath
op FilePath -> FilePath -> FilePath
forall a. [a] -> [a] -> [a]
++ FilePath
"' in the IO monad")
                ; FilePath -> IO a
forall a. FilePath -> IO a
forall (m :: * -> *) a. MonadFail m => FilePath -> m a
fail FilePath
"Template Haskell failure" }

-- Global variable to generate unique symbols
counter :: IORef Uniq
{-# NOINLINE counter #-}
counter :: IORef Uniq
counter = IO (IORef Uniq) -> IORef Uniq
forall a. IO a -> a
unsafePerformIO (Uniq -> IO (IORef Uniq)
forall a. a -> IO (IORef a)
newIORef Uniq
0)


-----------------------------------------------------
--
--              The Q monad
--
-----------------------------------------------------

newtype Q a = Q { forall a. Q a -> forall (m :: * -> *). Quasi m => m a
unQ :: forall m. Quasi m => m a }

-- \"Runs\" the 'Q' monad. Normal users of Template Haskell
-- should not need this function, as the splice brackets @$( ... )@
-- are the usual way of running a 'Q' computation.
--
-- This function is primarily used in GHC internals, and for debugging
-- splices by running them in 'IO'.
--
-- Note that many functions in 'Q', such as 'reify' and other compiler
-- queries, are not supported when running 'Q' in 'IO'; these operations
-- simply fail at runtime. Indeed, the only operations guaranteed to succeed
-- are 'newName', 'runIO', 'reportError' and 'reportWarning'.
runQ :: Quasi m => Q a -> m a
runQ :: forall (m :: * -> *) a. Quasi m => Q a -> m a
runQ (Q forall (m :: * -> *). Quasi m => m a
m) = m a
forall (m :: * -> *). Quasi m => m a
m

instance Monad Q where
  Q forall (m :: * -> *). Quasi m => m a
m >>= :: forall a b. Q a -> (a -> Q b) -> Q b
>>= a -> Q b
k  = (forall (m :: * -> *). Quasi m => m b) -> Q b
forall a. (forall (m :: * -> *). Quasi m => m a) -> Q a
Q (m a
forall (m :: * -> *). Quasi m => m a
m m a -> (a -> m b) -> m b
forall a b. m a -> (a -> m b) -> m b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \a
x -> Q b -> forall (m :: * -> *). Quasi m => m b
forall a. Q a -> forall (m :: * -> *). Quasi m => m a
unQ (a -> Q b
k a
x))
  >> :: forall a b. Q a -> Q b -> Q b
(>>) = Q a -> Q b -> Q b
forall a b. Q a -> Q b -> Q b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
(*>)

instance MonadFail Q where
  fail :: forall a. FilePath -> Q a
fail FilePath
s     = Bool -> FilePath -> Q ()
report Bool
True FilePath
s Q () -> Q a -> Q a
forall a b. Q a -> Q b -> Q b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> (forall (m :: * -> *). Quasi m => m a) -> Q a
forall a. (forall (m :: * -> *). Quasi m => m a) -> Q a
Q (FilePath -> m a
forall a. FilePath -> m a
forall (m :: * -> *) a. MonadFail m => FilePath -> m a
fail FilePath
"Q monad failure")

instance Functor Q where
  fmap :: forall a b. (a -> b) -> Q a -> Q b
fmap a -> b
f (Q forall (m :: * -> *). Quasi m => m a
x) = (forall (m :: * -> *). Quasi m => m b) -> Q b
forall a. (forall (m :: * -> *). Quasi m => m a) -> Q a
Q ((a -> b) -> m a -> m b
forall a b. (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap a -> b
f m a
forall (m :: * -> *). Quasi m => m a
x)

instance Applicative Q where
  pure :: forall a. a -> Q a
pure a
x = (forall (m :: * -> *). Quasi m => m a) -> Q a
forall a. (forall (m :: * -> *). Quasi m => m a) -> Q a
Q (a -> m a
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure a
x)
  Q forall (m :: * -> *). Quasi m => m (a -> b)
f <*> :: forall a b. Q (a -> b) -> Q a -> Q b
<*> Q forall (m :: * -> *). Quasi m => m a
x = (forall (m :: * -> *). Quasi m => m b) -> Q b
forall a. (forall (m :: * -> *). Quasi m => m a) -> Q a
Q (m (a -> b)
forall (m :: * -> *). Quasi m => m (a -> b)
f m (a -> b) -> m a -> m b
forall a b. m (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> m a
forall (m :: * -> *). Quasi m => m a
x)
  Q forall (m :: * -> *). Quasi m => m a
m *> :: forall a b. Q a -> Q b -> Q b
*> Q forall (m :: * -> *). Quasi m => m b
n = (forall (m :: * -> *). Quasi m => m b) -> Q b
forall a. (forall (m :: * -> *). Quasi m => m a) -> Q a
Q (m a
forall (m :: * -> *). Quasi m => m a
m m a -> m b -> m b
forall a b. m a -> m b -> m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> m b
forall (m :: * -> *). Quasi m => m b
n)

-- | @since 2.17.0.0
instance Semigroup a => Semigroup (Q a) where
  <> :: Q a -> Q a -> Q a
(<>) = (a -> a -> a) -> Q a -> Q a -> Q a
forall a b c. (a -> b -> c) -> Q a -> Q b -> Q c
forall (f :: * -> *) a b c.
Applicative f =>
(a -> b -> c) -> f a -> f b -> f c
liftA2 a -> a -> a
forall a. Semigroup a => a -> a -> a
(<>)

-- | @since 2.17.0.0
instance Monoid a => Monoid (Q a) where
  mempty :: Q a
mempty = a -> Q a
forall a. a -> Q a
forall (f :: * -> *) a. Applicative f => a -> f a
pure a
forall a. Monoid a => a
mempty

-- | If the function passed to 'mfix' inspects its argument,
-- the resulting action will throw a 'FixIOException'.
--
-- @since 2.17.0.0
instance MonadFix Q where
  -- We use the same blackholing approach as in fixIO.
  -- See Note [Blackholing in fixIO] in System.IO in base.
  mfix :: forall a. (a -> Q a) -> Q a
mfix a -> Q a
k = do
    MVar a
m <- IO (MVar a) -> Q (MVar a)
forall a. IO a -> Q a
runIO IO (MVar a)
forall a. IO (MVar a)
newEmptyMVar
    a
ans <- IO a -> Q a
forall a. IO a -> Q a
runIO (IO a -> IO a
forall a. IO a -> IO a
unsafeDupableInterleaveIO
             (MVar a -> IO a
forall a. MVar a -> IO a
readMVar MVar a
m IO a -> (BlockedIndefinitelyOnMVar -> IO a) -> IO a
forall e a. Exception e => IO a -> (e -> IO a) -> IO a
`catch` \BlockedIndefinitelyOnMVar
BlockedIndefinitelyOnMVar ->
                                    FixIOException -> IO a
forall e a. Exception e => e -> IO a
throwIO FixIOException
FixIOException))
    a
result <- a -> Q a
k a
ans
    IO () -> Q ()
forall a. IO a -> Q a
runIO (MVar a -> a -> IO ()
forall a. MVar a -> a -> IO ()
putMVar MVar a
m a
result)
    a -> Q a
forall a. a -> Q a
forall (m :: * -> *) a. Monad m => a -> m a
return a
result


-----------------------------------------------------
--
--              The Quote class
--
-----------------------------------------------------



-- | The 'Quote' class implements the minimal interface which is necessary for
-- desugaring quotations.
--
-- * The @Monad m@ superclass is needed to stitch together the different
-- AST fragments.
-- * 'newName' is used when desugaring binding structures such as lambdas
-- to generate fresh names.
--
-- Therefore the type of an untyped quotation in GHC is `Quote m => m Exp`
--
-- For many years the type of a quotation was fixed to be `Q Exp` but by
-- more precisely specifying the minimal interface it enables the `Exp` to
-- be extracted purely from the quotation without interacting with `Q`.
class Monad m => Quote m where
  {- |
  Generate a fresh name, which cannot be captured.

  For example, this:

  @f = $(do
    nm1 <- newName \"x\"
    let nm2 = 'mkName' \"x\"
    return ('LamE' ['VarP' nm1] (LamE [VarP nm2] ('VarE' nm1)))
   )@

  will produce the splice

  >f = \x0 -> \x -> x0

  In particular, the occurrence @VarE nm1@ refers to the binding @VarP nm1@,
  and is not captured by the binding @VarP nm2@.

  Although names generated by @newName@ cannot /be captured/, they can
  /capture/ other names. For example, this:

  >g = $(do
  >  nm1 <- newName "x"
  >  let nm2 = mkName "x"
  >  return (LamE [VarP nm2] (LamE [VarP nm1] (VarE nm2)))
  > )

  will produce the splice

  >g = \x -> \x0 -> x0

  since the occurrence @VarE nm2@ is captured by the innermost binding
  of @x@, namely @VarP nm1@.
  -}
  newName :: String -> m Name

instance Quote Q where
  newName :: FilePath -> Q Name
newName FilePath
s = (forall (m :: * -> *). Quasi m => m Name) -> Q Name
forall a. (forall (m :: * -> *). Quasi m => m a) -> Q a
Q (FilePath -> m Name
forall (m :: * -> *). Quasi m => FilePath -> m Name
qNewName FilePath
s)

-----------------------------------------------------
--
--              The TExp type
--
-----------------------------------------------------

type role TExp nominal   -- See Note [Role of TExp]
newtype TExp (a :: TYPE (r :: RuntimeRep)) = TExp
  { forall a. TExp a -> Exp
unType :: Exp -- ^ Underlying untyped Template Haskell expression
  }
-- ^ Represents an expression which has type @a@. Built on top of 'Exp', typed
-- expressions allow for type-safe splicing via:
--
--   - typed quotes, written as @[|| ... ||]@ where @...@ is an expression; if
--     that expression has type @a@, then the quotation has type
--     @'Q' ('TExp' a)@
--
--   - typed splices inside of typed quotes, written as @$$(...)@ where @...@
--     is an arbitrary expression of type @'Q' ('TExp' a)@
--
-- Traditional expression quotes and splices let us construct ill-typed
-- expressions:
--
-- >>> fmap ppr $ runQ [| True == $( [| "foo" |] ) |]
-- GHC.Types.True GHC.Classes.== "foo"
-- >>> GHC.Types.True GHC.Classes.== "foo"
-- <interactive> error:
--     • Couldn't match expected type ‘Bool’ with actual type ‘[Char]’
--     • In the second argument of ‘(==)’, namely ‘"foo"’
--       In the expression: True == "foo"
--       In an equation for ‘it’: it = True == "foo"
--
-- With typed expressions, the type error occurs when /constructing/ the
-- Template Haskell expression:
--
-- >>> fmap ppr $ runQ [|| True == $$( [|| "foo" ||] ) ||]
-- <interactive> error:
--     • Couldn't match type ‘[Char]’ with ‘Bool’
--       Expected type: Q (TExp Bool)
--         Actual type: Q (TExp [Char])
--     • In the Template Haskell quotation [|| "foo" ||]
--       In the expression: [|| "foo" ||]
--       In the Template Haskell splice $$([|| "foo" ||])
--
-- Representation-polymorphic since /template-haskell-2.16.0.0/.

-- | Discard the type annotation and produce a plain Template Haskell
-- expression
--
-- Representation-polymorphic since /template-haskell-2.16.0.0/.
unTypeQ :: forall (r :: RuntimeRep) (a :: TYPE r) m . Quote m => m (TExp a) -> m Exp
unTypeQ :: forall a (m :: * -> *). Quote m => m (TExp a) -> m Exp
unTypeQ m (TExp a)
m = do { TExp Exp
e <- m (TExp a)
m
               ; Exp -> m Exp
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return Exp
e }

-- | Annotate the Template Haskell expression with a type
--
-- This is unsafe because GHC cannot check for you that the expression
-- really does have the type you claim it has.
--
-- Representation-polymorphic since /template-haskell-2.16.0.0/.
unsafeTExpCoerce :: forall (r :: RuntimeRep) (a :: TYPE r) m .
                      Quote m => m Exp -> m (TExp a)
unsafeTExpCoerce :: forall a (m :: * -> *). Quote m => m Exp -> m (TExp a)
unsafeTExpCoerce m Exp
m = do { Exp
e <- m Exp
m
                        ; TExp a -> m (TExp a)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Exp -> TExp a
forall a. Exp -> TExp a
TExp Exp
e) }

{- Note [Role of TExp]
~~~~~~~~~~~~~~~~~~~~~~
TExp's argument must have a nominal role, not phantom as would
be inferred (#8459).  Consider

  e :: TExp Age
  e = MkAge 3

  foo = $(coerce e) + 4::Int

The splice will evaluate to (MkAge 3) and you can't add that to
4::Int. So you can't coerce a (TExp Age) to a (TExp Int). -}

-- Code constructor

type role Code representational nominal   -- See Note [Role of TExp]
newtype Code m (a :: TYPE (r :: RuntimeRep)) = Code
  { forall (m :: * -> *) a. Code m a -> m (TExp a)
examineCode :: m (TExp a) -- ^ Underlying monadic value
  }

-- | Unsafely convert an untyped code representation into a typed code
-- representation.
unsafeCodeCoerce :: forall (r :: RuntimeRep) (a :: TYPE r) m .
                      Quote m => m Exp -> Code m a
unsafeCodeCoerce :: forall a (m :: * -> *). Quote m => m Exp -> Code m a
unsafeCodeCoerce m Exp
m = m (TExp a) -> Code m a
forall (m :: * -> *) a. m (TExp a) -> Code m a
Code (m Exp -> m (TExp a)
forall a (m :: * -> *). Quote m => m Exp -> m (TExp a)
unsafeTExpCoerce m Exp
m)

-- | Lift a monadic action producing code into the typed 'Code'
-- representation
liftCode :: forall (r :: RuntimeRep) (a :: TYPE r) m . m (TExp a) -> Code m a
liftCode :: forall a (m :: * -> *). m (TExp a) -> Code m a
liftCode = m (TExp a) -> Code m a
forall (m :: * -> *) a. m (TExp a) -> Code m a
Code

-- | Extract the untyped representation from the typed representation
unTypeCode :: forall (r :: RuntimeRep) (a :: TYPE r) m . Quote m
           => Code m a -> m Exp
unTypeCode :: forall a (m :: * -> *). Quote m => Code m a -> m Exp
unTypeCode = m (TExp a) -> m Exp
forall a (m :: * -> *). Quote m => m (TExp a) -> m Exp
unTypeQ (m (TExp a) -> m Exp)
-> (Code m a -> m (TExp a)) -> Code m a -> m Exp
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Code m a -> m (TExp a)
forall (m :: * -> *) a. Code m a -> m (TExp a)
examineCode

-- | Modify the ambient monad used during code generation. For example, you
-- can use `hoistCode` to handle a state effect:
-- @
--  handleState :: Code (StateT Int Q) a -> Code Q a
--  handleState = hoistCode (flip runState 0)
-- @
hoistCode :: forall m n (r :: RuntimeRep) (a :: TYPE r) . Monad m
          => (forall x . m x -> n x) -> Code m a -> Code n a
hoistCode :: forall (m :: * -> *) (n :: * -> *) a.
Monad m =>
(forall x. m x -> n x) -> Code m a -> Code n a
hoistCode forall x. m x -> n x
f (Code m (TExp a)
a) = n (TExp a) -> Code n a
forall (m :: * -> *) a. m (TExp a) -> Code m a
Code (m (TExp a) -> n (TExp a)
forall x. m x -> n x
f m (TExp a)
a)


-- | Variant of (>>=) which allows effectful computations to be injected
-- into code generation.
bindCode :: forall m a (r :: RuntimeRep) (b :: TYPE r) . Monad m
         => m a -> (a -> Code m b) -> Code m b
bindCode :: forall (m :: * -> *) a b.
Monad m =>
m a -> (a -> Code m b) -> Code m b
bindCode m a
q a -> Code m b
k = m (TExp b) -> Code m b
forall a (m :: * -> *). m (TExp a) -> Code m a
liftCode (m a
q m a -> (a -> m (TExp b)) -> m (TExp b)
forall a b. m a -> (a -> m b) -> m b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Code m b -> m (TExp b)
forall (m :: * -> *) a. Code m a -> m (TExp a)
examineCode (Code m b -> m (TExp b)) -> (a -> Code m b) -> a -> m (TExp b)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Code m b
k)

-- | Variant of (>>) which allows effectful computations to be injected
-- into code generation.
bindCode_ :: forall m a (r :: RuntimeRep) (b :: TYPE r) . Monad m
          => m a -> Code m b -> Code m b
bindCode_ :: forall (m :: * -> *) a b. Monad m => m a -> Code m b -> Code m b
bindCode_ m a
q Code m b
c = m (TExp b) -> Code m b
forall a (m :: * -> *). m (TExp a) -> Code m a
liftCode ( m a
q m a -> m (TExp b) -> m (TExp b)
forall a b. m a -> m b -> m b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Code m b -> m (TExp b)
forall (m :: * -> *) a. Code m a -> m (TExp a)
examineCode Code m b
c)

-- | A useful combinator for embedding monadic actions into 'Code'
-- @
-- myCode :: ... => Code m a
-- myCode = joinCode $ do
--   x <- someSideEffect
--   return (makeCodeWith x)
-- @
joinCode :: forall m (r :: RuntimeRep) (a :: TYPE r) . Monad m
         => m (Code m a) -> Code m a
joinCode :: forall (m :: * -> *) a. Monad m => m (Code m a) -> Code m a
joinCode = (m (Code m a) -> (Code m a -> Code m a) -> Code m a)
-> (Code m a -> Code m a) -> m (Code m a) -> Code m a
forall a b c. (a -> b -> c) -> b -> a -> c
flip m (Code m a) -> (Code m a -> Code m a) -> Code m a
forall (m :: * -> *) a b.
Monad m =>
m a -> (a -> Code m b) -> Code m b
bindCode Code m a -> Code m a
forall a. a -> a
id

----------------------------------------------------
-- Packaged versions for the programmer, hiding the Quasi-ness


-- | Report an error (True) or warning (False),
-- but carry on; use 'fail' to stop.
report  :: Bool -> String -> Q ()
report :: Bool -> FilePath -> Q ()
report Bool
b FilePath
s = (forall (m :: * -> *). Quasi m => m ()) -> Q ()
forall a. (forall (m :: * -> *). Quasi m => m a) -> Q a
Q (Bool -> FilePath -> m ()
forall (m :: * -> *). Quasi m => Bool -> FilePath -> m ()
qReport Bool
b FilePath
s)
{-# DEPRECATED report "Use reportError or reportWarning instead" #-} -- deprecated in 7.6

-- | Report an error to the user, but allow the current splice's computation to carry on. To abort the computation, use 'fail'.
reportError :: String -> Q ()
reportError :: FilePath -> Q ()
reportError = Bool -> FilePath -> Q ()
report Bool
True

-- | Report a warning to the user, and carry on.
reportWarning :: String -> Q ()
reportWarning :: FilePath -> Q ()
reportWarning = Bool -> FilePath -> Q ()
report Bool
False

-- | Recover from errors raised by 'reportError' or 'fail'.
recover :: Q a -- ^ handler to invoke on failure
        -> Q a -- ^ computation to run
        -> Q a
recover :: forall a. Q a -> Q a -> Q a
recover (Q forall (m :: * -> *). Quasi m => m a
r) (Q forall (m :: * -> *). Quasi m => m a
m) = (forall (m :: * -> *). Quasi m => m a) -> Q a
forall a. (forall (m :: * -> *). Quasi m => m a) -> Q a
Q (m a -> m a -> m a
forall a. m a -> m a -> m a
forall (m :: * -> *) a. Quasi m => m a -> m a -> m a
qRecover m a
forall (m :: * -> *). Quasi m => m a
r m a
forall (m :: * -> *). Quasi m => m a
m)

-- We don't export lookupName; the Bool isn't a great API
-- Instead we export lookupTypeName, lookupValueName
lookupName :: Bool -> String -> Q (Maybe Name)
lookupName :: Bool -> FilePath -> Q (Maybe Name)
lookupName Bool
ns FilePath
s = (forall (m :: * -> *). Quasi m => m (Maybe Name)) -> Q (Maybe Name)
forall a. (forall (m :: * -> *). Quasi m => m a) -> Q a
Q (Bool -> FilePath -> m (Maybe Name)
forall (m :: * -> *). Quasi m => Bool -> FilePath -> m (Maybe Name)
qLookupName Bool
ns FilePath
s)

-- | Look up the given name in the (type namespace of the) current splice's scope. See "Language.Haskell.TH.Syntax#namelookup" for more details.
lookupTypeName :: String -> Q (Maybe Name)
lookupTypeName :: FilePath -> Q (Maybe Name)
lookupTypeName  FilePath
s = (forall (m :: * -> *). Quasi m => m (Maybe Name)) -> Q (Maybe Name)
forall a. (forall (m :: * -> *). Quasi m => m a) -> Q a
Q (Bool -> FilePath -> m (Maybe Name)
forall (m :: * -> *). Quasi m => Bool -> FilePath -> m (Maybe Name)
qLookupName Bool
True FilePath
s)

-- | Look up the given name in the (value namespace of the) current splice's scope. See "Language.Haskell.TH.Syntax#namelookup" for more details.
lookupValueName :: String -> Q (Maybe Name)
lookupValueName :: FilePath -> Q (Maybe Name)
lookupValueName FilePath
s = (forall (m :: * -> *). Quasi m => m (Maybe Name)) -> Q (Maybe Name)
forall a. (forall (m :: * -> *). Quasi m => m a) -> Q a
Q (Bool -> FilePath -> m (Maybe Name)
forall (m :: * -> *). Quasi m => Bool -> FilePath -> m (Maybe Name)
qLookupName Bool
False FilePath
s)

{-
Note [Name lookup]
~~~~~~~~~~~~~~~~~~
-}
{- $namelookup #namelookup#
The functions 'lookupTypeName' and 'lookupValueName' provide
a way to query the current splice's context for what names
are in scope. The function 'lookupTypeName' queries the type
namespace, whereas 'lookupValueName' queries the value namespace,
but the functions are otherwise identical.

A call @lookupValueName s@ will check if there is a value
with name @s@ in scope at the current splice's location. If
there is, the @Name@ of this value is returned;
if not, then @Nothing@ is returned.

The returned name cannot be \"captured\".
For example:

> f = "global"
> g = $( do
>          Just nm <- lookupValueName "f"
>          [| let f = "local" in $( varE nm ) |]

In this case, @g = \"global\"@; the call to @lookupValueName@
returned the global @f@, and this name was /not/ captured by
the local definition of @f@.

The lookup is performed in the context of the /top-level/ splice
being run. For example:

> f = "global"
> g = $( [| let f = "local" in
>            $(do
>                Just nm <- lookupValueName "f"
>                varE nm
>             ) |] )

Again in this example, @g = \"global\"@, because the call to
@lookupValueName@ queries the context of the outer-most @$(...)@.

Operators should be queried without any surrounding parentheses, like so:

> lookupValueName "+"

Qualified names are also supported, like so:

> lookupValueName "Prelude.+"
> lookupValueName "Prelude.map"

-}


{- | 'reify' looks up information about the 'Name'. It will fail with
a compile error if the 'Name' is not visible. A 'Name' is visible if it is
imported or defined in a prior top-level declaration group. See the
documentation for 'newDeclarationGroup' for more details.

It is sometimes useful to construct the argument name using 'lookupTypeName' or 'lookupValueName'
to ensure that we are reifying from the right namespace. For instance, in this context:

> data D = D

which @D@ does @reify (mkName \"D\")@ return information about? (Answer: @D@-the-type, but don't rely on it.)
To ensure we get information about @D@-the-value, use 'lookupValueName':

> do
>   Just nm <- lookupValueName "D"
>   reify nm

and to get information about @D@-the-type, use 'lookupTypeName'.
-}
reify :: Name -> Q Info
reify :: Name -> Q Info
reify Name
v = (forall (m :: * -> *). Quasi m => m Info) -> Q Info
forall a. (forall (m :: * -> *). Quasi m => m a) -> Q a
Q (Name -> m Info
forall (m :: * -> *). Quasi m => Name -> m Info
qReify Name
v)

{- | @reifyFixity nm@ attempts to find a fixity declaration for @nm@. For
example, if the function @foo@ has the fixity declaration @infixr 7 foo@, then
@reifyFixity 'foo@ would return @'Just' ('Fixity' 7 'InfixR')@. If the function
@bar@ does not have a fixity declaration, then @reifyFixity 'bar@ returns
'Nothing', so you may assume @bar@ has 'defaultFixity'.
-}
reifyFixity :: Name -> Q (Maybe Fixity)
reifyFixity :: Name -> Q (Maybe Fixity)
reifyFixity Name
nm = (forall (m :: * -> *). Quasi m => m (Maybe Fixity))
-> Q (Maybe Fixity)
forall a. (forall (m :: * -> *). Quasi m => m a) -> Q a
Q (Name -> m (Maybe Fixity)
forall (m :: * -> *). Quasi m => Name -> m (Maybe Fixity)
qReifyFixity Name
nm)

{- | @reifyType nm@ attempts to find the type or kind of @nm@. For example,
@reifyType 'not@   returns @Bool -> Bool@, and
@reifyType ''Bool@ returns @Type@.
This works even if there's no explicit signature and the type or kind is inferred.
-}
reifyType :: Name -> Q Type
reifyType :: Name -> Q Type
reifyType Name
nm = (forall (m :: * -> *). Quasi m => m Type) -> Q Type
forall a. (forall (m :: * -> *). Quasi m => m a) -> Q a
Q (Name -> m Type
forall (m :: * -> *). Quasi m => Name -> m Type
qReifyType Name
nm)

{- | Template Haskell is capable of reifying information about types and
terms defined in previous declaration groups. Top-level declaration splices break up
declaration groups.

For an example, consider this  code block. We define a datatype @X@ and
then try to call 'reify' on the datatype.

@
module Check where

data X = X
    deriving Eq

$(do
    info <- reify ''X
    runIO $ print info
 )
@

This code fails to compile, noting that @X@ is not available for reification at the site of 'reify'. We can fix this by creating a new declaration group using an empty top-level splice:

@
data X = X
    deriving Eq

$(pure [])

$(do
    info <- reify ''X
    runIO $ print info
 )
@

We provide 'newDeclarationGroup' as a means of documenting this behavior
and providing a name for the pattern.

Since top level splices infer the presence of the @$( ... )@ brackets, we can also write:

@
data X = X
    deriving Eq

newDeclarationGroup

$(do
    info <- reify ''X
    runIO $ print info
 )
@

-}
newDeclarationGroup :: Q [Dec]
newDeclarationGroup :: Q [Dec]
newDeclarationGroup = [Dec] -> Q [Dec]
forall a. a -> Q a
forall (f :: * -> *) a. Applicative f => a -> f a
pure []

{- | @reifyInstances nm tys@ returns a list of visible instances of @nm tys@. That is,
if @nm@ is the name of a type class, then all instances of this class at the types @tys@
are returned. Alternatively, if @nm@ is the name of a data family or type family,
all instances of this family at the types @tys@ are returned.

Note that this is a \"shallow\" test; the declarations returned merely have
instance heads which unify with @nm tys@, they need not actually be satisfiable.

  - @reifyInstances ''Eq [ 'TupleT' 2 \``AppT`\` 'ConT' ''A \``AppT`\` 'ConT' ''B ]@ contains
    the @instance (Eq a, Eq b) => Eq (a, b)@ regardless of whether @A@ and
    @B@ themselves implement 'Eq'

  - @reifyInstances ''Show [ 'VarT' ('mkName' "a") ]@ produces every available
    instance of 'Eq'

There is one edge case: @reifyInstances ''Typeable tys@ currently always
produces an empty list (no matter what @tys@ are given).

An instance is visible if it is imported or defined in a prior top-level
declaration group. See the documentation for 'newDeclarationGroup' for more details.

-}
reifyInstances :: Name -> [Type] -> Q [InstanceDec]
reifyInstances :: Name -> [Type] -> Q [Dec]
reifyInstances Name
cls [Type]
tys = (forall (m :: * -> *). Quasi m => m [Dec]) -> Q [Dec]
forall a. (forall (m :: * -> *). Quasi m => m a) -> Q a
Q (Name -> [Type] -> m [Dec]
forall (m :: * -> *). Quasi m => Name -> [Type] -> m [Dec]
qReifyInstances Name
cls [Type]
tys)

{- | @reifyRoles nm@ returns the list of roles associated with the parameters
(both visible and invisible) of
the tycon @nm@. Fails if @nm@ cannot be found or is not a tycon.
The returned list should never contain 'InferR'.

An invisible parameter to a tycon is often a kind parameter. For example, if
we have

@
type Proxy :: forall k. k -> Type
data Proxy a = MkProxy
@

and @reifyRoles Proxy@, we will get @['NominalR', 'PhantomR']@. The 'NominalR' is
the role of the invisible @k@ parameter. Kind parameters are always nominal.
-}
reifyRoles :: Name -> Q [Role]
reifyRoles :: Name -> Q [Role]
reifyRoles Name
nm = (forall (m :: * -> *). Quasi m => m [Role]) -> Q [Role]
forall a. (forall (m :: * -> *). Quasi m => m a) -> Q a
Q (Name -> m [Role]
forall (m :: * -> *). Quasi m => Name -> m [Role]
qReifyRoles Name
nm)

-- | @reifyAnnotations target@ returns the list of annotations
-- associated with @target@.  Only the annotations that are
-- appropriately typed is returned.  So if you have @Int@ and @String@
-- annotations for the same target, you have to call this function twice.
reifyAnnotations :: Data a => AnnLookup -> Q [a]
reifyAnnotations :: forall a. Data a => AnnLookup -> Q [a]
reifyAnnotations AnnLookup
an = (forall (m :: * -> *). Quasi m => m [a]) -> Q [a]
forall a. (forall (m :: * -> *). Quasi m => m a) -> Q a
Q (AnnLookup -> m [a]
forall a. Data a => AnnLookup -> m [a]
forall (m :: * -> *) a. (Quasi m, Data a) => AnnLookup -> m [a]
qReifyAnnotations AnnLookup
an)

-- | @reifyModule mod@ looks up information about module @mod@.  To
-- look up the current module, call this function with the return
-- value of 'Language.Haskell.TH.Lib.thisModule'.
reifyModule :: Module -> Q ModuleInfo
reifyModule :: Module -> Q ModuleInfo
reifyModule Module
m = (forall (m :: * -> *). Quasi m => m ModuleInfo) -> Q ModuleInfo
forall a. (forall (m :: * -> *). Quasi m => m a) -> Q a
Q (Module -> m ModuleInfo
forall (m :: * -> *). Quasi m => Module -> m ModuleInfo
qReifyModule Module
m)

-- | @reifyConStrictness nm@ looks up the strictness information for the fields
-- of the constructor with the name @nm@. Note that the strictness information
-- that 'reifyConStrictness' returns may not correspond to what is written in
-- the source code. For example, in the following data declaration:
--
-- @
-- data Pair a = Pair a a
-- @
--
-- 'reifyConStrictness' would return @['DecidedLazy', DecidedLazy]@ under most
-- circumstances, but it would return @['DecidedStrict', DecidedStrict]@ if the
-- @-XStrictData@ language extension was enabled.
reifyConStrictness :: Name -> Q [DecidedStrictness]
reifyConStrictness :: Name -> Q [DecidedStrictness]
reifyConStrictness Name
n = (forall (m :: * -> *). Quasi m => m [DecidedStrictness])
-> Q [DecidedStrictness]
forall a. (forall (m :: * -> *). Quasi m => m a) -> Q a
Q (Name -> m [DecidedStrictness]
forall (m :: * -> *). Quasi m => Name -> m [DecidedStrictness]
qReifyConStrictness Name
n)

-- | Is the list of instances returned by 'reifyInstances' nonempty?
--
-- If you're confused by an instance not being visible despite being
-- defined in the same module and above the splice in question, see the
-- docs for 'newDeclarationGroup' for a possible explanation.
isInstance :: Name -> [Type] -> Q Bool
isInstance :: Name -> [Type] -> Q Bool
isInstance Name
nm [Type]
tys = do { [Dec]
decs <- Name -> [Type] -> Q [Dec]
reifyInstances Name
nm [Type]
tys
                       ; Bool -> Q Bool
forall a. a -> Q a
forall (m :: * -> *) a. Monad m => a -> m a
return (Bool -> Bool
not ([Dec] -> Bool
forall a. [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [Dec]
decs)) }

-- | The location at which this computation is spliced.
location :: Q Loc
location :: Q Loc
location = (forall (m :: * -> *). Quasi m => m Loc) -> Q Loc
forall a. (forall (m :: * -> *). Quasi m => m a) -> Q a
Q m Loc
forall (m :: * -> *). Quasi m => m Loc
qLocation

-- |The 'runIO' function lets you run an I\/O computation in the 'Q' monad.
-- Take care: you are guaranteed the ordering of calls to 'runIO' within
-- a single 'Q' computation, but not about the order in which splices are run.
--
-- Note: for various murky reasons, stdout and stderr handles are not
-- necessarily flushed when the compiler finishes running, so you should
-- flush them yourself.
runIO :: IO a -> Q a
runIO :: forall a. IO a -> Q a
runIO IO a
m = (forall (m :: * -> *). Quasi m => m a) -> Q a
forall a. (forall (m :: * -> *). Quasi m => m a) -> Q a
Q (IO a -> m a
forall a. IO a -> m a
forall (m :: * -> *) a. Quasi m => IO a -> m a
qRunIO IO a
m)

-- | Get the package root for the current package which is being compiled.
-- This can be set explicitly with the -package-root flag but is normally
-- just the current working directory.
--
-- The motivation for this flag is to provide a principled means to remove the
-- assumption from splices that they will be executed in the directory where the
-- cabal file resides. Projects such as haskell-language-server can't and don't
-- change directory when compiling files but instead set the -package-root flag
-- appropiately.
getPackageRoot :: Q FilePath
getPackageRoot :: Q FilePath
getPackageRoot = (forall (m :: * -> *). Quasi m => m FilePath) -> Q FilePath
forall a. (forall (m :: * -> *). Quasi m => m a) -> Q a
Q m FilePath
forall (m :: * -> *). Quasi m => m FilePath
qGetPackageRoot

-- | The input is a filepath, which if relative is offset by the package root.
makeRelativeToProject :: FilePath -> Q FilePath
makeRelativeToProject :: FilePath -> Q FilePath
makeRelativeToProject FilePath
fp | FilePath -> Bool
isRelative FilePath
fp = do
  FilePath
root <- Q FilePath
getPackageRoot
  FilePath -> Q FilePath
forall a. a -> Q a
forall (m :: * -> *) a. Monad m => a -> m a
return (FilePath
root FilePath -> FilePath -> FilePath
</> FilePath
fp)
makeRelativeToProject FilePath
fp = FilePath -> Q FilePath
forall a. a -> Q a
forall (m :: * -> *) a. Monad m => a -> m a
return FilePath
fp



-- | Record external files that runIO is using (dependent upon).
-- The compiler can then recognize that it should re-compile the Haskell file
-- when an external file changes.
--
-- Expects an absolute file path.
--
-- Notes:
--
--   * ghc -M does not know about these dependencies - it does not execute TH.
--
--   * The dependency is based on file content, not a modification time
addDependentFile :: FilePath -> Q ()
addDependentFile :: FilePath -> Q ()
addDependentFile FilePath
fp = (forall (m :: * -> *). Quasi m => m ()) -> Q ()
forall a. (forall (m :: * -> *). Quasi m => m a) -> Q a
Q (FilePath -> m ()
forall (m :: * -> *). Quasi m => FilePath -> m ()
qAddDependentFile FilePath
fp)

-- | Obtain a temporary file path with the given suffix. The compiler will
-- delete this file after compilation.
addTempFile :: String -> Q FilePath
addTempFile :: FilePath -> Q FilePath
addTempFile FilePath
suffix = (forall (m :: * -> *). Quasi m => m FilePath) -> Q FilePath
forall a. (forall (m :: * -> *). Quasi m => m a) -> Q a
Q (FilePath -> m FilePath
forall (m :: * -> *). Quasi m => FilePath -> m FilePath
qAddTempFile FilePath
suffix)

-- | Add additional top-level declarations. The added declarations will be type
-- checked along with the current declaration group.
addTopDecls :: [Dec] -> Q ()
addTopDecls :: [Dec] -> Q ()
addTopDecls [Dec]
ds = (forall (m :: * -> *). Quasi m => m ()) -> Q ()
forall a. (forall (m :: * -> *). Quasi m => m a) -> Q a
Q ([Dec] -> m ()
forall (m :: * -> *). Quasi m => [Dec] -> m ()
qAddTopDecls [Dec]
ds)

-- |
addForeignFile :: ForeignSrcLang -> String -> Q ()
addForeignFile :: ForeignSrcLang -> FilePath -> Q ()
addForeignFile = ForeignSrcLang -> FilePath -> Q ()
addForeignSource
{-# DEPRECATED addForeignFile
               "Use 'Language.Haskell.TH.Syntax.addForeignSource' instead"
  #-} -- deprecated in 8.6

-- | Emit a foreign file which will be compiled and linked to the object for
-- the current module. Currently only languages that can be compiled with
-- the C compiler are supported, and the flags passed as part of -optc will
-- be also applied to the C compiler invocation that will compile them.
--
-- Note that for non-C languages (for example C++) @extern "C"@ directives
-- must be used to get symbols that we can access from Haskell.
--
-- To get better errors, it is recommended to use #line pragmas when
-- emitting C files, e.g.
--
-- > {-# LANGUAGE CPP #-}
-- > ...
-- > addForeignSource LangC $ unlines
-- >   [ "#line " ++ show (__LINE__ + 1) ++ " " ++ show __FILE__
-- >   , ...
-- >   ]
addForeignSource :: ForeignSrcLang -> String -> Q ()
addForeignSource :: ForeignSrcLang -> FilePath -> Q ()
addForeignSource ForeignSrcLang
lang FilePath
src = do
  let suffix :: FilePath
suffix = case ForeignSrcLang
lang of
                 ForeignSrcLang
LangC      -> FilePath
"c"
                 ForeignSrcLang
LangCxx    -> FilePath
"cpp"
                 ForeignSrcLang
LangObjc   -> FilePath
"m"
                 ForeignSrcLang
LangObjcxx -> FilePath
"mm"
                 ForeignSrcLang
LangAsm    -> FilePath
"s"
                 ForeignSrcLang
RawObject  -> FilePath
"a"
  FilePath
path <- FilePath -> Q FilePath
addTempFile FilePath
suffix
  IO () -> Q ()
forall a. IO a -> Q a
runIO (IO () -> Q ()) -> IO () -> Q ()
forall a b. (a -> b) -> a -> b
$ FilePath -> FilePath -> IO ()
writeFile FilePath
path FilePath
src
  ForeignSrcLang -> FilePath -> Q ()
addForeignFilePath ForeignSrcLang
lang FilePath
path

-- | Same as 'addForeignSource', but expects to receive a path pointing to the
-- foreign file instead of a 'String' of its contents. Consider using this in
-- conjunction with 'addTempFile'.
--
-- This is a good alternative to 'addForeignSource' when you are trying to
-- directly link in an object file.
addForeignFilePath :: ForeignSrcLang -> FilePath -> Q ()
addForeignFilePath :: ForeignSrcLang -> FilePath -> Q ()
addForeignFilePath ForeignSrcLang
lang FilePath
fp = (forall (m :: * -> *). Quasi m => m ()) -> Q ()
forall a. (forall (m :: * -> *). Quasi m => m a) -> Q a
Q (ForeignSrcLang -> FilePath -> m ()
forall (m :: * -> *). Quasi m => ForeignSrcLang -> FilePath -> m ()
qAddForeignFilePath ForeignSrcLang
lang FilePath
fp)

-- | Add a finalizer that will run in the Q monad after the current module has
-- been type checked. This only makes sense when run within a top-level splice.
--
-- The finalizer is given the local type environment at the splice point. Thus
-- 'reify' is able to find the local definitions when executed inside the
-- finalizer.
addModFinalizer :: Q () -> Q ()
addModFinalizer :: Q () -> Q ()
addModFinalizer Q ()
act = (forall (m :: * -> *). Quasi m => m ()) -> Q ()
forall a. (forall (m :: * -> *). Quasi m => m a) -> Q a
Q (Q () -> m ()
forall (m :: * -> *). Quasi m => Q () -> m ()
qAddModFinalizer (Q () -> forall (m :: * -> *). Quasi m => m ()
forall a. Q a -> forall (m :: * -> *). Quasi m => m a
unQ Q ()
act))

-- | Adds a core plugin to the compilation pipeline.
--
-- @addCorePlugin m@ has almost the same effect as passing @-fplugin=m@ to ghc
-- in the command line. The major difference is that the plugin module @m@
-- must not belong to the current package. When TH executes, it is too late
-- to tell the compiler that we needed to compile first a plugin module in the
-- current package.
addCorePlugin :: String -> Q ()
addCorePlugin :: FilePath -> Q ()
addCorePlugin FilePath
plugin = (forall (m :: * -> *). Quasi m => m ()) -> Q ()
forall a. (forall (m :: * -> *). Quasi m => m a) -> Q a
Q (FilePath -> m ()
forall (m :: * -> *). Quasi m => FilePath -> m ()
qAddCorePlugin FilePath
plugin)

-- | Get state from the 'Q' monad. Note that the state is local to the
-- Haskell module in which the Template Haskell expression is executed.
getQ :: Typeable a => Q (Maybe a)
getQ :: forall a. Typeable a => Q (Maybe a)
getQ = (forall (m :: * -> *). Quasi m => m (Maybe a)) -> Q (Maybe a)
forall a. (forall (m :: * -> *). Quasi m => m a) -> Q a
Q m (Maybe a)
forall a. Typeable a => m (Maybe a)
forall (m :: * -> *). Quasi m => m (Maybe a)
forall (m :: * -> *) a. (Quasi m, Typeable a) => m (Maybe a)
qGetQ

-- | Replace the state in the 'Q' monad. Note that the state is local to the
-- Haskell module in which the Template Haskell expression is executed.
putQ :: Typeable a => a -> Q ()
putQ :: forall a. Typeable a => a -> Q ()
putQ a
x = (forall (m :: * -> *). Quasi m => m ()) -> Q ()
forall a. (forall (m :: * -> *). Quasi m => m a) -> Q a
Q (a -> m ()
forall a. Typeable a => a -> m ()
forall (m :: * -> *) a. (Quasi m, Typeable a) => a -> m ()
qPutQ a
x)

-- | Determine whether the given language extension is enabled in the 'Q' monad.
isExtEnabled :: Extension -> Q Bool
isExtEnabled :: Extension -> Q Bool
isExtEnabled Extension
ext = (forall (m :: * -> *). Quasi m => m Bool) -> Q Bool
forall a. (forall (m :: * -> *). Quasi m => m a) -> Q a
Q (Extension -> m Bool
forall (m :: * -> *). Quasi m => Extension -> m Bool
qIsExtEnabled Extension
ext)

-- | List all enabled language extensions.
extsEnabled :: Q [Extension]
extsEnabled :: Q [Extension]
extsEnabled = (forall (m :: * -> *). Quasi m => m [Extension]) -> Q [Extension]
forall a. (forall (m :: * -> *). Quasi m => m a) -> Q a
Q m [Extension]
forall (m :: * -> *). Quasi m => m [Extension]
qExtsEnabled

-- | Add Haddock documentation to the specified location. This will overwrite
-- any documentation at the location if it already exists. This will reify the
-- specified name, so it must be in scope when you call it. If you want to add
-- documentation to something that you are currently splicing, you can use
-- 'addModFinalizer' e.g.
--
-- > do
-- >   let nm = mkName "x"
-- >   addModFinalizer $ putDoc (DeclDoc nm) "Hello"
-- >   [d| $(varP nm) = 42 |]
--
-- The helper functions 'withDecDoc' and 'withDecsDoc' will do this for you, as
-- will the 'funD_doc' and other @_doc@ combinators.
-- You most likely want to have the @-haddock@ flag turned on when using this.
-- Adding documentation to anything outside of the current module will cause an
-- error.
putDoc :: DocLoc -> String -> Q ()
putDoc :: DocLoc -> FilePath -> Q ()
putDoc DocLoc
t FilePath
s = (forall (m :: * -> *). Quasi m => m ()) -> Q ()
forall a. (forall (m :: * -> *). Quasi m => m a) -> Q a
Q (DocLoc -> FilePath -> m ()
forall (m :: * -> *). Quasi m => DocLoc -> FilePath -> m ()
qPutDoc DocLoc
t FilePath
s)

-- | Retreives the Haddock documentation at the specified location, if one
-- exists.
-- It can be used to read documentation on things defined outside of the current
-- module, provided that those modules were compiled with the @-haddock@ flag.
getDoc :: DocLoc -> Q (Maybe String)
getDoc :: DocLoc -> Q (Maybe FilePath)
getDoc DocLoc
n = (forall (m :: * -> *). Quasi m => m (Maybe FilePath))
-> Q (Maybe FilePath)
forall a. (forall (m :: * -> *). Quasi m => m a) -> Q a
Q (DocLoc -> m (Maybe FilePath)
forall (m :: * -> *). Quasi m => DocLoc -> m (Maybe FilePath)
qGetDoc DocLoc
n)

instance MonadIO Q where
  liftIO :: forall a. IO a -> Q a
liftIO = IO a -> Q a
forall a. IO a -> Q a
runIO

instance Quasi Q where
  qNewName :: FilePath -> Q Name
qNewName            = FilePath -> Q Name
forall (m :: * -> *). Quote m => FilePath -> m Name
newName
  qReport :: Bool -> FilePath -> Q ()
qReport             = Bool -> FilePath -> Q ()
report
  qRecover :: forall a. Q a -> Q a -> Q a
qRecover            = Q a -> Q a -> Q a
forall a. Q a -> Q a -> Q a
recover
  qReify :: Name -> Q Info
qReify              = Name -> Q Info
reify
  qReifyFixity :: Name -> Q (Maybe Fixity)
qReifyFixity        = Name -> Q (Maybe Fixity)
reifyFixity
  qReifyType :: Name -> Q Type
qReifyType          = Name -> Q Type
reifyType
  qReifyInstances :: Name -> [Type] -> Q [Dec]
qReifyInstances     = Name -> [Type] -> Q [Dec]
reifyInstances
  qReifyRoles :: Name -> Q [Role]
qReifyRoles         = Name -> Q [Role]
reifyRoles
  qReifyAnnotations :: forall a. Data a => AnnLookup -> Q [a]
qReifyAnnotations   = AnnLookup -> Q [a]
forall a. Data a => AnnLookup -> Q [a]
reifyAnnotations
  qReifyModule :: Module -> Q ModuleInfo
qReifyModule        = Module -> Q ModuleInfo
reifyModule
  qReifyConStrictness :: Name -> Q [DecidedStrictness]
qReifyConStrictness = Name -> Q [DecidedStrictness]
reifyConStrictness
  qLookupName :: Bool -> FilePath -> Q (Maybe Name)
qLookupName         = Bool -> FilePath -> Q (Maybe Name)
lookupName
  qLocation :: Q Loc
qLocation           = Q Loc
location
  qGetPackageRoot :: Q FilePath
qGetPackageRoot     = Q FilePath
getPackageRoot
  qAddDependentFile :: FilePath -> Q ()
qAddDependentFile   = FilePath -> Q ()
addDependentFile
  qAddTempFile :: FilePath -> Q FilePath
qAddTempFile        = FilePath -> Q FilePath
addTempFile
  qAddTopDecls :: [Dec] -> Q ()
qAddTopDecls        = [Dec] -> Q ()
addTopDecls
  qAddForeignFilePath :: ForeignSrcLang -> FilePath -> Q ()
qAddForeignFilePath = ForeignSrcLang -> FilePath -> Q ()
addForeignFilePath
  qAddModFinalizer :: Q () -> Q ()
qAddModFinalizer    = Q () -> Q ()
addModFinalizer
  qAddCorePlugin :: FilePath -> Q ()
qAddCorePlugin      = FilePath -> Q ()
addCorePlugin
  qGetQ :: forall a. Typeable a => Q (Maybe a)
qGetQ               = Q (Maybe a)
forall a. Typeable a => Q (Maybe a)
getQ
  qPutQ :: forall a. Typeable a => a -> Q ()
qPutQ               = a -> Q ()
forall a. Typeable a => a -> Q ()
putQ
  qIsExtEnabled :: Extension -> Q Bool
qIsExtEnabled       = Extension -> Q Bool
isExtEnabled
  qExtsEnabled :: Q [Extension]
qExtsEnabled        = Q [Extension]
extsEnabled
  qPutDoc :: DocLoc -> FilePath -> Q ()
qPutDoc             = DocLoc -> FilePath -> Q ()
putDoc
  qGetDoc :: DocLoc -> Q (Maybe FilePath)
qGetDoc             = DocLoc -> Q (Maybe FilePath)
getDoc


----------------------------------------------------
-- The following operations are used solely in GHC.HsToCore.Quote when
-- desugaring brackets. They are not necessary for the user, who can use
-- ordinary return and (>>=) etc

sequenceQ :: forall m . Monad m => forall a . [m a] -> m [a]
sequenceQ :: forall (m :: * -> *) a. Monad m => [m a] -> m [a]
sequenceQ = [m a] -> m [a]
forall (t :: * -> *) (m :: * -> *) a.
(Traversable t, Monad m) =>
t (m a) -> m (t a)
forall (m :: * -> *) a. Monad m => [m a] -> m [a]
sequence


-----------------------------------------------------
--
--              The Lift class
--
-----------------------------------------------------

-- | A 'Lift' instance can have any of its values turned into a Template
-- Haskell expression. This is needed when a value used within a Template
-- Haskell quotation is bound outside the Oxford brackets (@[| ... |]@ or
-- @[|| ... ||]@) but not at the top level. As an example:
--
-- > add1 :: Int -> Q (TExp Int)
-- > add1 x = [|| x + 1 ||]
--
-- Template Haskell has no way of knowing what value @x@ will take on at
-- splice-time, so it requires the type of @x@ to be an instance of 'Lift'.
--
-- A 'Lift' instance must satisfy @$(lift x) ≡ x@ and @$$(liftTyped x) ≡ x@
-- for all @x@, where @$(...)@ and @$$(...)@ are Template Haskell splices.
-- It is additionally expected that @'lift' x ≡ 'unTypeQ' ('liftTyped' x)@.
--
-- 'Lift' instances can be derived automatically by use of the @-XDeriveLift@
-- GHC language extension:
--
-- > {-# LANGUAGE DeriveLift #-}
-- > module Foo where
-- >
-- > import Language.Haskell.TH.Syntax
-- >
-- > data Bar a = Bar1 a (Bar a) | Bar2 String
-- >   deriving Lift
--
-- Representation-polymorphic since /template-haskell-2.16.0.0/.
class Lift (t :: TYPE r) where
  -- | Turn a value into a Template Haskell expression, suitable for use in
  -- a splice.
  lift :: Quote m => t -> m Exp
#if __GLASGOW_HASKELL__ >= 901
  default lift :: (r ~ ('BoxedRep 'Lifted), Quote m) => t -> m Exp
#else
  default lift :: (r ~ 'LiftedRep, Quote m) => t -> m Exp
#endif
  lift = Code m t -> m Exp
forall a (m :: * -> *). Quote m => Code m a -> m Exp
unTypeCode (Code m t -> m Exp) -> (t -> Code m t) -> t -> m Exp
forall b c a. (b -> c) -> (a -> b) -> a -> c
. t -> Code m t
forall t (m :: * -> *). (Lift t, Quote m) => t -> Code m t
forall (m :: * -> *). Quote m => t -> Code m t
liftTyped

  -- | Turn a value into a Template Haskell typed expression, suitable for use
  -- in a typed splice.
  --
  -- @since 2.16.0.0
  liftTyped :: Quote m => t -> Code m t


-- If you add any instances here, consider updating test th/TH_Lift
instance Lift Integer where
  liftTyped :: forall (m :: * -> *). Quote m => Uniq -> Code m Uniq
liftTyped Uniq
x = m Exp -> Code m Uniq
forall a (m :: * -> *). Quote m => m Exp -> Code m a
unsafeCodeCoerce (Uniq -> m Exp
forall t (m :: * -> *). (Lift t, Quote m) => t -> m Exp
forall (m :: * -> *). Quote m => Uniq -> m Exp
lift Uniq
x)
  lift :: forall (m :: * -> *). Quote m => Uniq -> m Exp
lift Uniq
x = Exp -> m Exp
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Lit -> Exp
LitE (Uniq -> Lit
IntegerL Uniq
x))

instance Lift Int where
  liftTyped :: forall (m :: * -> *). Quote m => Int -> Code m Int
liftTyped Int
x = m Exp -> Code m Int
forall a (m :: * -> *). Quote m => m Exp -> Code m a
unsafeCodeCoerce (Int -> m Exp
forall t (m :: * -> *). (Lift t, Quote m) => t -> m Exp
forall (m :: * -> *). Quote m => Int -> m Exp
lift Int
x)
  lift :: forall (m :: * -> *). Quote m => Int -> m Exp
lift Int
x = Exp -> m Exp
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Lit -> Exp
LitE (Uniq -> Lit
IntegerL (Int -> Uniq
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
x)))

-- | @since 2.16.0.0
instance Lift Int# where
  liftTyped :: forall (m :: * -> *). Quote m => Int# -> Code m Int#
liftTyped Int#
x = m Exp -> Code m Int#
forall a (m :: * -> *). Quote m => m Exp -> Code m a
unsafeCodeCoerce (Int# -> m Exp
forall t (m :: * -> *). (Lift t, Quote m) => t -> m Exp
forall (m :: * -> *). Quote m => Int# -> m Exp
lift Int#
x)
  lift :: forall (m :: * -> *). Quote m => Int# -> m Exp
lift Int#
x = Exp -> m Exp
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Lit -> Exp
LitE (Uniq -> Lit
IntPrimL (Int -> Uniq
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int# -> Int
I# Int#
x))))

instance Lift Int8 where
  liftTyped :: forall (m :: * -> *). Quote m => Int8 -> Code m Int8
liftTyped Int8
x = m Exp -> Code m Int8
forall a (m :: * -> *). Quote m => m Exp -> Code m a
unsafeCodeCoerce (Int8 -> m Exp
forall t (m :: * -> *). (Lift t, Quote m) => t -> m Exp
forall (m :: * -> *). Quote m => Int8 -> m Exp
lift Int8
x)
  lift :: forall (m :: * -> *). Quote m => Int8 -> m Exp
lift Int8
x = Exp -> m Exp
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Lit -> Exp
LitE (Uniq -> Lit
IntegerL (Int8 -> Uniq
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int8
x)))

instance Lift Int16 where
  liftTyped :: forall (m :: * -> *). Quote m => Int16 -> Code m Int16
liftTyped Int16
x = m Exp -> Code m Int16
forall a (m :: * -> *). Quote m => m Exp -> Code m a
unsafeCodeCoerce (Int16 -> m Exp
forall t (m :: * -> *). (Lift t, Quote m) => t -> m Exp
forall (m :: * -> *). Quote m => Int16 -> m Exp
lift Int16
x)
  lift :: forall (m :: * -> *). Quote m => Int16 -> m Exp
lift Int16
x = Exp -> m Exp
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Lit -> Exp
LitE (Uniq -> Lit
IntegerL (Int16 -> Uniq
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int16
x)))

instance Lift Int32 where
  liftTyped :: forall (m :: * -> *). Quote m => Int32 -> Code m Int32
liftTyped Int32
x = m Exp -> Code m Int32
forall a (m :: * -> *). Quote m => m Exp -> Code m a
unsafeCodeCoerce (Int32 -> m Exp
forall t (m :: * -> *). (Lift t, Quote m) => t -> m Exp
forall (m :: * -> *). Quote m => Int32 -> m Exp
lift Int32
x)
  lift :: forall (m :: * -> *). Quote m => Int32 -> m Exp
lift Int32
x = Exp -> m Exp
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Lit -> Exp
LitE (Uniq -> Lit
IntegerL (Int32 -> Uniq
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int32
x)))

instance Lift Int64 where
  liftTyped :: forall (m :: * -> *). Quote m => Int64 -> Code m Int64
liftTyped Int64
x = m Exp -> Code m Int64
forall a (m :: * -> *). Quote m => m Exp -> Code m a
unsafeCodeCoerce (Int64 -> m Exp
forall t (m :: * -> *). (Lift t, Quote m) => t -> m Exp
forall (m :: * -> *). Quote m => Int64 -> m Exp
lift Int64
x)
  lift :: forall (m :: * -> *). Quote m => Int64 -> m Exp
lift Int64
x = Exp -> m Exp
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Lit -> Exp
LitE (Uniq -> Lit
IntegerL (Int64 -> Uniq
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int64
x)))

-- | @since 2.16.0.0
instance Lift Word# where
  liftTyped :: forall (m :: * -> *). Quote m => Word# -> Code m Word#
liftTyped Word#
x = m Exp -> Code m Word#
forall a (m :: * -> *). Quote m => m Exp -> Code m a
unsafeCodeCoerce (Word# -> m Exp
forall t (m :: * -> *). (Lift t, Quote m) => t -> m Exp
forall (m :: * -> *). Quote m => Word# -> m Exp
lift Word#
x)
  lift :: forall (m :: * -> *). Quote m => Word# -> m Exp
lift Word#
x = Exp -> m Exp
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Lit -> Exp
LitE (Uniq -> Lit
WordPrimL (Word -> Uniq
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Word# -> Word
W# Word#
x))))

instance Lift Word where
  liftTyped :: forall (m :: * -> *). Quote m => Word -> Code m Word
liftTyped Word
x = m Exp -> Code m Word
forall a (m :: * -> *). Quote m => m Exp -> Code m a
unsafeCodeCoerce (Word -> m Exp
forall t (m :: * -> *). (Lift t, Quote m) => t -> m Exp
forall (m :: * -> *). Quote m => Word -> m Exp
lift Word
x)
  lift :: forall (m :: * -> *). Quote m => Word -> m Exp
lift Word
x = Exp -> m Exp
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Lit -> Exp
LitE (Uniq -> Lit
IntegerL (Word -> Uniq
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word
x)))

instance Lift Word8 where
  liftTyped :: forall (m :: * -> *). Quote m => Word8 -> Code m Word8
liftTyped Word8
x = m Exp -> Code m Word8
forall a (m :: * -> *). Quote m => m Exp -> Code m a
unsafeCodeCoerce (Word8 -> m Exp
forall t (m :: * -> *). (Lift t, Quote m) => t -> m Exp
forall (m :: * -> *). Quote m => Word8 -> m Exp
lift Word8
x)
  lift :: forall (m :: * -> *). Quote m => Word8 -> m Exp
lift Word8
x = Exp -> m Exp
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Lit -> Exp
LitE (Uniq -> Lit
IntegerL (Word8 -> Uniq
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
x)))

instance Lift Word16 where
  liftTyped :: forall (m :: * -> *). Quote m => Word16 -> Code m Word16
liftTyped Word16
x = m Exp -> Code m Word16
forall a (m :: * -> *). Quote m => m Exp -> Code m a
unsafeCodeCoerce (Word16 -> m Exp
forall t (m :: * -> *). (Lift t, Quote m) => t -> m Exp
forall (m :: * -> *). Quote m => Word16 -> m Exp
lift Word16
x)
  lift :: forall (m :: * -> *). Quote m => Word16 -> m Exp
lift Word16
x = Exp -> m Exp
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Lit -> Exp
LitE (Uniq -> Lit
IntegerL (Word16 -> Uniq
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word16
x)))

instance Lift Word32 where
  liftTyped :: forall (m :: * -> *). Quote m => Word32 -> Code m Word32
liftTyped Word32
x = m Exp -> Code m Word32
forall a (m :: * -> *). Quote m => m Exp -> Code m a
unsafeCodeCoerce (Word32 -> m Exp
forall t (m :: * -> *). (Lift t, Quote m) => t -> m Exp
forall (m :: * -> *). Quote m => Word32 -> m Exp
lift Word32
x)
  lift :: forall (m :: * -> *). Quote m => Word32 -> m Exp
lift Word32
x = Exp -> m Exp
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Lit -> Exp
LitE (Uniq -> Lit
IntegerL (Word32 -> Uniq
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word32
x)))

instance Lift Word64 where
  liftTyped :: forall (m :: * -> *). Quote m => Word64 -> Code m Word64
liftTyped Word64
x = m Exp -> Code m Word64
forall a (m :: * -> *). Quote m => m Exp -> Code m a
unsafeCodeCoerce (Word64 -> m Exp
forall t (m :: * -> *). (Lift t, Quote m) => t -> m Exp
forall (m :: * -> *). Quote m => Word64 -> m Exp
lift Word64
x)
  lift :: forall (m :: * -> *). Quote m => Word64 -> m Exp
lift Word64
x = Exp -> m Exp
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Lit -> Exp
LitE (Uniq -> Lit
IntegerL (Word64 -> Uniq
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word64
x)))

instance Lift Natural where
  liftTyped :: forall (m :: * -> *). Quote m => Natural -> Code m Natural
liftTyped Natural
x = m Exp -> Code m Natural
forall a (m :: * -> *). Quote m => m Exp -> Code m a
unsafeCodeCoerce (Natural -> m Exp
forall t (m :: * -> *). (Lift t, Quote m) => t -> m Exp
forall (m :: * -> *). Quote m => Natural -> m Exp
lift Natural
x)
  lift :: forall (m :: * -> *). Quote m => Natural -> m Exp
lift Natural
x = Exp -> m Exp
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Lit -> Exp
LitE (Uniq -> Lit
IntegerL (Natural -> Uniq
forall a b. (Integral a, Num b) => a -> b
fromIntegral Natural
x)))

instance Integral a => Lift (Ratio a) where
  liftTyped :: forall (m :: * -> *). Quote m => Ratio a -> Code m (Ratio a)
liftTyped Ratio a
x = m Exp -> Code m (Ratio a)
forall a (m :: * -> *). Quote m => m Exp -> Code m a
unsafeCodeCoerce (Ratio a -> m Exp
forall t (m :: * -> *). (Lift t, Quote m) => t -> m Exp
forall (m :: * -> *). Quote m => Ratio a -> m Exp
lift Ratio a
x)
  lift :: forall (m :: * -> *). Quote m => Ratio a -> m Exp
lift Ratio a
x = Exp -> m Exp
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Lit -> Exp
LitE (Rational -> Lit
RationalL (Ratio a -> Rational
forall a. Real a => a -> Rational
toRational Ratio a
x)))

instance Lift Float where
  liftTyped :: forall (m :: * -> *). Quote m => Float -> Code m Float
liftTyped Float
x = m Exp -> Code m Float
forall a (m :: * -> *). Quote m => m Exp -> Code m a
unsafeCodeCoerce (Float -> m Exp
forall t (m :: * -> *). (Lift t, Quote m) => t -> m Exp
forall (m :: * -> *). Quote m => Float -> m Exp
lift Float
x)
  lift :: forall (m :: * -> *). Quote m => Float -> m Exp
lift Float
x = Exp -> m Exp
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Lit -> Exp
LitE (Rational -> Lit
RationalL (Float -> Rational
forall a. Real a => a -> Rational
toRational Float
x)))

-- | @since 2.16.0.0
instance Lift Float# where
  liftTyped :: forall (m :: * -> *). Quote m => Float# -> Code m Float#
liftTyped Float#
x = m Exp -> Code m Float#
forall a (m :: * -> *). Quote m => m Exp -> Code m a
unsafeCodeCoerce (Float# -> m Exp
forall t (m :: * -> *). (Lift t, Quote m) => t -> m Exp
forall (m :: * -> *). Quote m => Float# -> m Exp
lift Float#
x)
  lift :: forall (m :: * -> *). Quote m => Float# -> m Exp
lift Float#
x = Exp -> m Exp
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Lit -> Exp
LitE (Rational -> Lit
FloatPrimL (Float -> Rational
forall a. Real a => a -> Rational
toRational (Float# -> Float
F# Float#
x))))

instance Lift Double where
  liftTyped :: forall (m :: * -> *). Quote m => Double -> Code m Double
liftTyped Double
x = m Exp -> Code m Double
forall a (m :: * -> *). Quote m => m Exp -> Code m a
unsafeCodeCoerce (Double -> m Exp
forall t (m :: * -> *). (Lift t, Quote m) => t -> m Exp
forall (m :: * -> *). Quote m => Double -> m Exp
lift Double
x)
  lift :: forall (m :: * -> *). Quote m => Double -> m Exp
lift Double
x = Exp -> m Exp
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Lit -> Exp
LitE (Rational -> Lit
RationalL (Double -> Rational
forall a. Real a => a -> Rational
toRational Double
x)))

-- | @since 2.16.0.0
instance Lift Double# where
  liftTyped :: forall (m :: * -> *). Quote m => Double# -> Code m Double#
liftTyped Double#
x = m Exp -> Code m Double#
forall a (m :: * -> *). Quote m => m Exp -> Code m a
unsafeCodeCoerce (Double# -> m Exp
forall t (m :: * -> *). (Lift t, Quote m) => t -> m Exp
forall (m :: * -> *). Quote m => Double# -> m Exp
lift Double#
x)
  lift :: forall (m :: * -> *). Quote m => Double# -> m Exp
lift Double#
x = Exp -> m Exp
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Lit -> Exp
LitE (Rational -> Lit
DoublePrimL (Double -> Rational
forall a. Real a => a -> Rational
toRational (Double# -> Double
D# Double#
x))))

instance Lift Char where
  liftTyped :: forall (m :: * -> *). Quote m => Char -> Code m Char
liftTyped Char
x = m Exp -> Code m Char
forall a (m :: * -> *). Quote m => m Exp -> Code m a
unsafeCodeCoerce (Char -> m Exp
forall t (m :: * -> *). (Lift t, Quote m) => t -> m Exp
forall (m :: * -> *). Quote m => Char -> m Exp
lift Char
x)
  lift :: forall (m :: * -> *). Quote m => Char -> m Exp
lift Char
x = Exp -> m Exp
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Lit -> Exp
LitE (Char -> Lit
CharL Char
x))

-- | @since 2.16.0.0
instance Lift Char# where
  liftTyped :: forall (m :: * -> *). Quote m => Char# -> Code m Char#
liftTyped Char#
x = m Exp -> Code m Char#
forall a (m :: * -> *). Quote m => m Exp -> Code m a
unsafeCodeCoerce (Char# -> m Exp
forall t (m :: * -> *). (Lift t, Quote m) => t -> m Exp
forall (m :: * -> *). Quote m => Char# -> m Exp
lift Char#
x)
  lift :: forall (m :: * -> *). Quote m => Char# -> m Exp
lift Char#
x = Exp -> m Exp
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Lit -> Exp
LitE (Char -> Lit
CharPrimL (Char# -> Char
C# Char#
x)))

instance Lift Bool where
  liftTyped :: forall (m :: * -> *). Quote m => Bool -> Code m Bool
liftTyped Bool
x = m Exp -> Code m Bool
forall a (m :: * -> *). Quote m => m Exp -> Code m a
unsafeCodeCoerce (Bool -> m Exp
forall t (m :: * -> *). (Lift t, Quote m) => t -> m Exp
forall (m :: * -> *). Quote m => Bool -> m Exp
lift Bool
x)

  lift :: forall (m :: * -> *). Quote m => Bool -> m Exp
lift Bool
True  = Exp -> m Exp
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Name -> Exp
ConE Name
trueName)
  lift Bool
False = Exp -> m Exp
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Name -> Exp
ConE Name
falseName)

-- | Produces an 'Addr#' literal from the NUL-terminated C-string starting at
-- the given memory address.
--
-- @since 2.16.0.0
instance Lift Addr# where
  liftTyped :: forall (m :: * -> *). Quote m => Addr# -> Code m Addr#
liftTyped Addr#
x = m Exp -> Code m Addr#
forall a (m :: * -> *). Quote m => m Exp -> Code m a
unsafeCodeCoerce (Addr# -> m Exp
forall t (m :: * -> *). (Lift t, Quote m) => t -> m Exp
forall (m :: * -> *). Quote m => Addr# -> m Exp
lift Addr#
x)
  lift :: forall (m :: * -> *). Quote m => Addr# -> m Exp
lift Addr#
x
    = Exp -> m Exp
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Lit -> Exp
LitE ([Word8] -> Lit
StringPrimL ((Char -> Word8) -> FilePath -> [Word8]
forall a b. (a -> b) -> [a] -> [b]
map (Int -> Word8
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int -> Word8) -> (Char -> Int) -> Char -> Word8
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Char -> Int
ord) (Addr# -> FilePath
unpackCString# Addr#
x))))

instance Lift a => Lift (Maybe a) where
  liftTyped :: forall (m :: * -> *). Quote m => Maybe a -> Code m (Maybe a)
liftTyped Maybe a
x = m Exp -> Code m (Maybe a)
forall a (m :: * -> *). Quote m => m Exp -> Code m a
unsafeCodeCoerce (Maybe a -> m Exp
forall t (m :: * -> *). (Lift t, Quote m) => t -> m Exp
forall (m :: * -> *). Quote m => Maybe a -> m Exp
lift Maybe a
x)

  lift :: forall (m :: * -> *). Quote m => Maybe a -> m Exp
lift Maybe a
Nothing  = Exp -> m Exp
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Name -> Exp
ConE Name
nothingName)
  lift (Just a
x) = (Exp -> Exp) -> m Exp -> m Exp
forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
liftM (Name -> Exp
ConE Name
justName Exp -> Exp -> Exp
`AppE`) (a -> m Exp
forall t (m :: * -> *). (Lift t, Quote m) => t -> m Exp
forall (m :: * -> *). Quote m => a -> m Exp
lift a
x)

instance (Lift a, Lift b) => Lift (Either a b) where
  liftTyped :: forall (m :: * -> *). Quote m => Either a b -> Code m (Either a b)
liftTyped Either a b
x = m Exp -> Code m (Either a b)
forall a (m :: * -> *). Quote m => m Exp -> Code m a
unsafeCodeCoerce (Either a b -> m Exp
forall t (m :: * -> *). (Lift t, Quote m) => t -> m Exp
forall (m :: * -> *). Quote m => Either a b -> m Exp
lift Either a b
x)

  lift :: forall (m :: * -> *). Quote m => Either a b -> m Exp
lift (Left a
x)  = (Exp -> Exp) -> m Exp -> m Exp
forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
liftM (Name -> Exp
ConE Name
leftName  Exp -> Exp -> Exp
`AppE`) (a -> m Exp
forall t (m :: * -> *). (Lift t, Quote m) => t -> m Exp
forall (m :: * -> *). Quote m => a -> m Exp
lift a
x)
  lift (Right b
y) = (Exp -> Exp) -> m Exp -> m Exp
forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
liftM (Name -> Exp
ConE Name
rightName Exp -> Exp -> Exp
`AppE`) (b -> m Exp
forall t (m :: * -> *). (Lift t, Quote m) => t -> m Exp
forall (m :: * -> *). Quote m => b -> m Exp
lift b
y)

instance Lift a => Lift [a] where
  liftTyped :: forall (m :: * -> *). Quote m => [a] -> Code m [a]
liftTyped [a]
x = m Exp -> Code m [a]
forall a (m :: * -> *). Quote m => m Exp -> Code m a
unsafeCodeCoerce ([a] -> m Exp
forall t (m :: * -> *). (Lift t, Quote m) => t -> m Exp
forall (m :: * -> *). Quote m => [a] -> m Exp
lift [a]
x)
  lift :: forall (m :: * -> *). Quote m => [a] -> m Exp
lift [a]
xs = do { [Exp]
xs' <- (a -> m Exp) -> [a] -> m [Exp]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> [a] -> m [b]
mapM a -> m Exp
forall t (m :: * -> *). (Lift t, Quote m) => t -> m Exp
forall (m :: * -> *). Quote m => a -> m Exp
lift [a]
xs; Exp -> m Exp
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return ([Exp] -> Exp
ListE [Exp]
xs') }

liftString :: Quote m => String -> m Exp
-- Used in GHC.Tc.Gen.Expr to short-circuit the lifting for strings
liftString :: forall (m :: * -> *). Quote m => FilePath -> m Exp
liftString FilePath
s = Exp -> m Exp
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Lit -> Exp
LitE (FilePath -> Lit
StringL FilePath
s))

-- | @since 2.15.0.0
instance Lift a => Lift (NonEmpty a) where
  liftTyped :: forall (m :: * -> *). Quote m => NonEmpty a -> Code m (NonEmpty a)
liftTyped NonEmpty a
x = m Exp -> Code m (NonEmpty a)
forall a (m :: * -> *). Quote m => m Exp -> Code m a
unsafeCodeCoerce (NonEmpty a -> m Exp
forall t (m :: * -> *). (Lift t, Quote m) => t -> m Exp
forall (m :: * -> *). Quote m => NonEmpty a -> m Exp
lift NonEmpty a
x)

  lift :: forall (m :: * -> *). Quote m => NonEmpty a -> m Exp
lift (a
x :| [a]
xs) = do
    Exp
x' <- a -> m Exp
forall t (m :: * -> *). (Lift t, Quote m) => t -> m Exp
forall (m :: * -> *). Quote m => a -> m Exp
lift a
x
    Exp
xs' <- [a] -> m Exp
forall t (m :: * -> *). (Lift t, Quote m) => t -> m Exp
forall (m :: * -> *). Quote m => [a] -> m Exp
lift [a]
xs
    Exp -> m Exp
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe Exp -> Exp -> Maybe Exp -> Exp
InfixE (Exp -> Maybe Exp
forall a. a -> Maybe a
Just Exp
x') (Name -> Exp
ConE Name
nonemptyName) (Exp -> Maybe Exp
forall a. a -> Maybe a
Just Exp
xs'))

-- | @since 2.15.0.0
instance Lift Void where
  liftTyped :: forall (m :: * -> *). Quote m => Void -> Code m Void
liftTyped = m (TExp Void) -> Code m Void
forall a (m :: * -> *). m (TExp a) -> Code m a
liftCode (m (TExp Void) -> Code m Void)
-> (Void -> m (TExp Void)) -> Void -> Code m Void
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Void -> m (TExp Void)
forall a. Void -> a
absurd
  lift :: forall (m :: * -> *). Quote m => Void -> m Exp
lift = Exp -> m Exp
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Exp -> m Exp) -> (Void -> Exp) -> Void -> m Exp
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Void -> Exp
forall a. Void -> a
absurd

instance Lift () where
  liftTyped :: forall (m :: * -> *). Quote m => () -> Code m ()
liftTyped ()
x = m Exp -> Code m ()
forall a (m :: * -> *). Quote m => m Exp -> Code m a
unsafeCodeCoerce (() -> m Exp
forall t (m :: * -> *). (Lift t, Quote m) => t -> m Exp
forall (m :: * -> *). Quote m => () -> m Exp
lift ()
x)
  lift :: forall (m :: * -> *). Quote m => () -> m Exp
lift () = Exp -> m Exp
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Name -> Exp
ConE (Int -> Name
tupleDataName Int
0))

instance (Lift a, Lift b) => Lift (a, b) where
  liftTyped :: forall (m :: * -> *). Quote m => (a, b) -> Code m (a, b)
liftTyped (a, b)
x = m Exp -> Code m (a, b)
forall a (m :: * -> *). Quote m => m Exp -> Code m a
unsafeCodeCoerce ((a, b) -> m Exp
forall t (m :: * -> *). (Lift t, Quote m) => t -> m Exp
forall (m :: * -> *). Quote m => (a, b) -> m Exp
lift (a, b)
x)
  lift :: forall (m :: * -> *). Quote m => (a, b) -> m Exp
lift (a
a, b
b)
    = ([Maybe Exp] -> Exp) -> m [Maybe Exp] -> m Exp
forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
liftM [Maybe Exp] -> Exp
TupE (m [Maybe Exp] -> m Exp) -> m [Maybe Exp] -> m Exp
forall a b. (a -> b) -> a -> b
$ [m (Maybe Exp)] -> m [Maybe Exp]
forall (t :: * -> *) (m :: * -> *) a.
(Traversable t, Monad m) =>
t (m a) -> m (t a)
forall (m :: * -> *) a. Monad m => [m a] -> m [a]
sequence ([m (Maybe Exp)] -> m [Maybe Exp])
-> [m (Maybe Exp)] -> m [Maybe Exp]
forall a b. (a -> b) -> a -> b
$ (m Exp -> m (Maybe Exp)) -> [m Exp] -> [m (Maybe Exp)]
forall a b. (a -> b) -> [a] -> [b]
map ((Exp -> Maybe Exp) -> m Exp -> m (Maybe Exp)
forall a b. (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Exp -> Maybe Exp
forall a. a -> Maybe a
Just) [a -> m Exp
forall t (m :: * -> *). (Lift t, Quote m) => t -> m Exp
forall (m :: * -> *). Quote m => a -> m Exp
lift a
a, b -> m Exp
forall t (m :: * -> *). (Lift t, Quote m) => t -> m Exp
forall (m :: * -> *). Quote m => b -> m Exp
lift b
b]

instance (Lift a, Lift b, Lift c) => Lift (a, b, c) where
  liftTyped :: forall (m :: * -> *). Quote m => (a, b, c) -> Code m (a, b, c)
liftTyped (a, b, c)
x = m Exp -> Code m (a, b, c)
forall a (m :: * -> *). Quote m => m Exp -> Code m a
unsafeCodeCoerce ((a, b, c) -> m Exp
forall t (m :: * -> *). (Lift t, Quote m) => t -> m Exp
forall (m :: * -> *). Quote m => (a, b, c) -> m Exp
lift (a, b, c)
x)
  lift :: forall (m :: * -> *). Quote m => (a, b, c) -> m Exp
lift (a
a, b
b, c
c)
    = ([Maybe Exp] -> Exp) -> m [Maybe Exp] -> m Exp
forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
liftM [Maybe Exp] -> Exp
TupE (m [Maybe Exp] -> m Exp) -> m [Maybe Exp] -> m Exp
forall a b. (a -> b) -> a -> b
$ [m (Maybe Exp)] -> m [Maybe Exp]
forall (t :: * -> *) (m :: * -> *) a.
(Traversable t, Monad m) =>
t (m a) -> m (t a)
forall (m :: * -> *) a. Monad m => [m a] -> m [a]
sequence ([m (Maybe Exp)] -> m [Maybe Exp])
-> [m (Maybe Exp)] -> m [Maybe Exp]
forall a b. (a -> b) -> a -> b
$ (m Exp -> m (Maybe Exp)) -> [m Exp] -> [m (Maybe Exp)]
forall a b. (a -> b) -> [a] -> [b]
map ((Exp -> Maybe Exp) -> m Exp -> m (Maybe Exp)
forall a b. (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Exp -> Maybe Exp
forall a. a -> Maybe a
Just) [a -> m Exp
forall t (m :: * -> *). (Lift t, Quote m) => t -> m Exp
forall (m :: * -> *). Quote m => a -> m Exp
lift a
a, b -> m Exp
forall t (m :: * -> *). (Lift t, Quote m) => t -> m Exp
forall (m :: * -> *). Quote m => b -> m Exp
lift b
b, c -> m Exp
forall t (m :: * -> *). (Lift t, Quote m) => t -> m Exp
forall (m :: * -> *). Quote m => c -> m Exp
lift c
c]

instance (Lift a, Lift b, Lift c, Lift d) => Lift (a, b, c, d) where
  liftTyped :: forall (m :: * -> *).
Quote m =>
(a, b, c, d) -> Code m (a, b, c, d)
liftTyped (a, b, c, d)
x = m Exp -> Code m (a, b, c, d)
forall a (m :: * -> *). Quote m => m Exp -> Code m a
unsafeCodeCoerce ((a, b, c, d) -> m Exp
forall t (m :: * -> *). (Lift t, Quote m) => t -> m Exp
forall (m :: * -> *). Quote m => (a, b, c, d) -> m Exp
lift (a, b, c, d)
x)
  lift :: forall (m :: * -> *). Quote m => (a, b, c, d) -> m Exp
lift (a
a, b
b, c
c, d
d)
    = ([Maybe Exp] -> Exp) -> m [Maybe Exp] -> m Exp
forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
liftM [Maybe Exp] -> Exp
TupE (m [Maybe Exp] -> m Exp) -> m [Maybe Exp] -> m Exp
forall a b. (a -> b) -> a -> b
$ [m (Maybe Exp)] -> m [Maybe Exp]
forall (t :: * -> *) (m :: * -> *) a.
(Traversable t, Monad m) =>
t (m a) -> m (t a)
forall (m :: * -> *) a. Monad m => [m a] -> m [a]
sequence ([m (Maybe Exp)] -> m [Maybe Exp])
-> [m (Maybe Exp)] -> m [Maybe Exp]
forall a b. (a -> b) -> a -> b
$ (m Exp -> m (Maybe Exp)) -> [m Exp] -> [m (Maybe Exp)]
forall a b. (a -> b) -> [a] -> [b]
map ((Exp -> Maybe Exp) -> m Exp -> m (Maybe Exp)
forall a b. (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Exp -> Maybe Exp
forall a. a -> Maybe a
Just) [a -> m Exp
forall t (m :: * -> *). (Lift t, Quote m) => t -> m Exp
forall (m :: * -> *). Quote m => a -> m Exp
lift a
a, b -> m Exp
forall t (m :: * -> *). (Lift t, Quote m) => t -> m Exp
forall (m :: * -> *). Quote m => b -> m Exp
lift b
b, c -> m Exp
forall t (m :: * -> *). (Lift t, Quote m) => t -> m Exp
forall (m :: * -> *). Quote m => c -> m Exp
lift c
c, d -> m Exp
forall t (m :: * -> *). (Lift t, Quote m) => t -> m Exp
forall (m :: * -> *). Quote m => d -> m Exp
lift d
d]

instance (Lift a, Lift b, Lift c, Lift d, Lift e)
      => Lift (a, b, c, d, e) where
  liftTyped :: forall (m :: * -> *).
Quote m =>
(a, b, c, d, e) -> Code m (a, b, c, d, e)
liftTyped (a, b, c, d, e)
x = m Exp -> Code m (a, b, c, d, e)
forall a (m :: * -> *). Quote m => m Exp -> Code m a
unsafeCodeCoerce ((a, b, c, d, e) -> m Exp
forall t (m :: * -> *). (Lift t, Quote m) => t -> m Exp
forall (m :: * -> *). Quote m => (a, b, c, d, e) -> m Exp
lift (a, b, c, d, e)
x)
  lift :: forall (m :: * -> *). Quote m => (a, b, c, d, e) -> m Exp
lift (a
a, b
b, c
c, d
d, e
e)
    = ([Maybe Exp] -> Exp) -> m [Maybe Exp] -> m Exp
forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
liftM [Maybe Exp] -> Exp
TupE (m [Maybe Exp] -> m Exp) -> m [Maybe Exp] -> m Exp
forall a b. (a -> b) -> a -> b
$ [m (Maybe Exp)] -> m [Maybe Exp]
forall (t :: * -> *) (m :: * -> *) a.
(Traversable t, Monad m) =>
t (m a) -> m (t a)
forall (m :: * -> *) a. Monad m => [m a] -> m [a]
sequence ([m (Maybe Exp)] -> m [Maybe Exp])
-> [m (Maybe Exp)] -> m [Maybe Exp]
forall a b. (a -> b) -> a -> b
$ (m Exp -> m (Maybe Exp)) -> [m Exp] -> [m (Maybe Exp)]
forall a b. (a -> b) -> [a] -> [b]
map ((Exp -> Maybe Exp) -> m Exp -> m (Maybe Exp)
forall a b. (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Exp -> Maybe Exp
forall a. a -> Maybe a
Just) [ a -> m Exp
forall t (m :: * -> *). (Lift t, Quote m) => t -> m Exp
forall (m :: * -> *). Quote m => a -> m Exp
lift a
a, b -> m Exp
forall t (m :: * -> *). (Lift t, Quote m) => t -> m Exp
forall (m :: * -> *). Quote m => b -> m Exp
lift b
b
                                              , c -> m Exp
forall t (m :: * -> *). (Lift t, Quote m) => t -> m Exp
forall (m :: * -> *). Quote m => c -> m Exp
lift c
c, d -> m Exp
forall t (m :: * -> *). (Lift t, Quote m) => t -> m Exp
forall (m :: * -> *). Quote m => d -> m Exp
lift d
d, e -> m Exp
forall t (m :: * -> *). (Lift t, Quote m) => t -> m Exp
forall (m :: * -> *). Quote m => e -> m Exp
lift e
e ]

instance (Lift a, Lift b, Lift c, Lift d, Lift e, Lift f)
      => Lift (a, b, c, d, e, f) where
  liftTyped :: forall (m :: * -> *).
Quote m =>
(a, b, c, d, e, f) -> Code m (a, b, c, d, e, f)
liftTyped (a, b, c, d, e, f)
x = m Exp -> Code m (a, b, c, d, e, f)
forall a (m :: * -> *). Quote m => m Exp -> Code m a
unsafeCodeCoerce ((a, b, c, d, e, f) -> m Exp
forall t (m :: * -> *). (Lift t, Quote m) => t -> m Exp
forall (m :: * -> *). Quote m => (a, b, c, d, e, f) -> m Exp
lift (a, b, c, d, e, f)
x)
  lift :: forall (m :: * -> *). Quote m => (a, b, c, d, e, f) -> m Exp
lift (a
a, b
b, c
c, d
d, e
e, f
f)
    = ([Maybe Exp] -> Exp) -> m [Maybe Exp] -> m Exp
forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
liftM [Maybe Exp] -> Exp
TupE (m [Maybe Exp] -> m Exp) -> m [Maybe Exp] -> m Exp
forall a b. (a -> b) -> a -> b
$ [m (Maybe Exp)] -> m [Maybe Exp]
forall (t :: * -> *) (m :: * -> *) a.
(Traversable t, Monad m) =>
t (m a) -> m (t a)
forall (m :: * -> *) a. Monad m => [m a] -> m [a]
sequence ([m (Maybe Exp)] -> m [Maybe Exp])
-> [m (Maybe Exp)] -> m [Maybe Exp]
forall a b. (a -> b) -> a -> b
$ (m Exp -> m (Maybe Exp)) -> [m Exp] -> [m (Maybe Exp)]
forall a b. (a -> b) -> [a] -> [b]
map ((Exp -> Maybe Exp) -> m Exp -> m (Maybe Exp)
forall a b. (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Exp -> Maybe Exp
forall a. a -> Maybe a
Just) [ a -> m Exp
forall t (m :: * -> *). (Lift t, Quote m) => t -> m Exp
forall (m :: * -> *). Quote m => a -> m Exp
lift a
a, b -> m Exp
forall t (m :: * -> *). (Lift t, Quote m) => t -> m Exp
forall (m :: * -> *). Quote m => b -> m Exp
lift b
b, c -> m Exp
forall t (m :: * -> *). (Lift t, Quote m) => t -> m Exp
forall (m :: * -> *). Quote m => c -> m Exp
lift c
c
                                              , d -> m Exp
forall t (m :: * -> *). (Lift t, Quote m) => t -> m Exp
forall (m :: * -> *). Quote m => d -> m Exp
lift d
d, e -> m Exp
forall t (m :: * -> *). (Lift t, Quote m) => t -> m Exp
forall (m :: * -> *). Quote m => e -> m Exp
lift e
e, f -> m Exp
forall t (m :: * -> *). (Lift t, Quote m) => t -> m Exp
forall (m :: * -> *). Quote m => f -> m Exp
lift f
f ]

instance (Lift a, Lift b, Lift c, Lift d, Lift e, Lift f, Lift g)
      => Lift (a, b, c, d, e, f, g) where
  liftTyped :: forall (m :: * -> *).
Quote m =>
(a, b, c, d, e, f, g) -> Code m (a, b, c, d, e, f, g)
liftTyped (a, b, c, d, e, f, g)
x = m Exp -> Code m (a, b, c, d, e, f, g)
forall a (m :: * -> *). Quote m => m Exp -> Code m a
unsafeCodeCoerce ((a, b, c, d, e, f, g) -> m Exp
forall t (m :: * -> *). (Lift t, Quote m) => t -> m Exp
forall (m :: * -> *). Quote m => (a, b, c, d, e, f, g) -> m Exp
lift (a, b, c, d, e, f, g)
x)
  lift :: forall (m :: * -> *). Quote m => (a, b, c, d, e, f, g) -> m Exp
lift (a
a, b
b, c
c, d
d, e
e, f
f, g
g)
    = ([Maybe Exp] -> Exp) -> m [Maybe Exp] -> m Exp
forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
liftM [Maybe Exp] -> Exp
TupE (m [Maybe Exp] -> m Exp) -> m [Maybe Exp] -> m Exp
forall a b. (a -> b) -> a -> b
$ [m (Maybe Exp)] -> m [Maybe Exp]
forall (t :: * -> *) (m :: * -> *) a.
(Traversable t, Monad m) =>
t (m a) -> m (t a)
forall (m :: * -> *) a. Monad m => [m a] -> m [a]
sequence ([m (Maybe Exp)] -> m [Maybe Exp])
-> [m (Maybe Exp)] -> m [Maybe Exp]
forall a b. (a -> b) -> a -> b
$ (m Exp -> m (Maybe Exp)) -> [m Exp] -> [m (Maybe Exp)]
forall a b. (a -> b) -> [a] -> [b]
map ((Exp -> Maybe Exp) -> m Exp -> m (Maybe Exp)
forall a b. (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Exp -> Maybe Exp
forall a. a -> Maybe a
Just) [ a -> m Exp
forall t (m :: * -> *). (Lift t, Quote m) => t -> m Exp
forall (m :: * -> *). Quote m => a -> m Exp
lift a
a, b -> m Exp
forall t (m :: * -> *). (Lift t, Quote m) => t -> m Exp
forall (m :: * -> *). Quote m => b -> m Exp
lift b
b, c -> m Exp
forall t (m :: * -> *). (Lift t, Quote m) => t -> m Exp
forall (m :: * -> *). Quote m => c -> m Exp
lift c
c
                                              , d -> m Exp
forall t (m :: * -> *). (Lift t, Quote m) => t -> m Exp
forall (m :: * -> *). Quote m => d -> m Exp
lift d
d, e -> m Exp
forall t (m :: * -> *). (Lift t, Quote m) => t -> m Exp
forall (m :: * -> *). Quote m => e -> m Exp
lift e
e, f -> m Exp
forall t (m :: * -> *). (Lift t, Quote m) => t -> m Exp
forall (m :: * -> *). Quote m => f -> m Exp
lift f
f, g -> m Exp
forall t (m :: * -> *). (Lift t, Quote m) => t -> m Exp
forall (m :: * -> *). Quote m => g -> m Exp
lift g
g ]

-- | @since 2.16.0.0
instance Lift (# #) where
  liftTyped :: forall (m :: * -> *). Quote m => (# #) -> Code m (# #)
liftTyped (# #)
x = m Exp -> Code m (# #)
forall a (m :: * -> *). Quote m => m Exp -> Code m a
unsafeCodeCoerce ((# #) -> m Exp
forall t (m :: * -> *). (Lift t, Quote m) => t -> m Exp
forall (m :: * -> *). Quote m => (# #) -> m Exp
lift (# #)
x)
  lift :: forall (m :: * -> *). Quote m => (# #) -> m Exp
lift (# #) = Exp -> m Exp
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Name -> Exp
ConE (Int -> Name
unboxedTupleTypeName Int
0))

-- | @since 2.16.0.0
instance (Lift a) => Lift (# a #) where
  liftTyped :: forall (m :: * -> *). Quote m => (# a #) -> Code m (# a #)
liftTyped (# a #)
x = m Exp -> Code m (# a #)
forall a (m :: * -> *). Quote m => m Exp -> Code m a
unsafeCodeCoerce ((# a #) -> m Exp
forall t (m :: * -> *). (Lift t, Quote m) => t -> m Exp
forall (m :: * -> *). Quote m => (# a #) -> m Exp
lift (# a #)
x)
  lift :: forall (m :: * -> *). Quote m => (# a #) -> m Exp
lift (# a
a #)
    = ([Maybe Exp] -> Exp) -> m [Maybe Exp] -> m Exp
forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
liftM [Maybe Exp] -> Exp
UnboxedTupE (m [Maybe Exp] -> m Exp) -> m [Maybe Exp] -> m Exp
forall a b. (a -> b) -> a -> b
$ [m (Maybe Exp)] -> m [Maybe Exp]
forall (t :: * -> *) (m :: * -> *) a.
(Traversable t, Monad m) =>
t (m a) -> m (t a)
forall (m :: * -> *) a. Monad m => [m a] -> m [a]
sequence ([m (Maybe Exp)] -> m [Maybe Exp])
-> [m (Maybe Exp)] -> m [Maybe Exp]
forall a b. (a -> b) -> a -> b
$ (m Exp -> m (Maybe Exp)) -> [m Exp] -> [m (Maybe Exp)]
forall a b. (a -> b) -> [a] -> [b]
map ((Exp -> Maybe Exp) -> m Exp -> m (Maybe Exp)
forall a b. (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Exp -> Maybe Exp
forall a. a -> Maybe a
Just) [a -> m Exp
forall t (m :: * -> *). (Lift t, Quote m) => t -> m Exp
forall (m :: * -> *). Quote m => a -> m Exp
lift a
a]

-- | @since 2.16.0.0
instance (Lift a, Lift b) => Lift (# a, b #) where
  liftTyped :: forall (m :: * -> *). Quote m => (# a, b #) -> Code m (# a, b #)
liftTyped (# a, b #)
x = m Exp -> Code m (# a, b #)
forall a (m :: * -> *). Quote m => m Exp -> Code m a
unsafeCodeCoerce ((# a, b #) -> m Exp
forall t (m :: * -> *). (Lift t, Quote m) => t -> m Exp
forall (m :: * -> *). Quote m => (# a, b #) -> m Exp
lift (# a, b #)
x)
  lift :: forall (m :: * -> *). Quote m => (# a, b #) -> m Exp
lift (# a
a, b
b #)
    = ([Maybe Exp] -> Exp) -> m [Maybe Exp] -> m Exp
forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
liftM [Maybe Exp] -> Exp
UnboxedTupE (m [Maybe Exp] -> m Exp) -> m [Maybe Exp] -> m Exp
forall a b. (a -> b) -> a -> b
$ [m (Maybe Exp)] -> m [Maybe Exp]
forall (t :: * -> *) (m :: * -> *) a.
(Traversable t, Monad m) =>
t (m a) -> m (t a)
forall (m :: * -> *) a. Monad m => [m a] -> m [a]
sequence ([m (Maybe Exp)] -> m [Maybe Exp])
-> [m (Maybe Exp)] -> m [Maybe Exp]
forall a b. (a -> b) -> a -> b
$ (m Exp -> m (Maybe Exp)) -> [m Exp] -> [m (Maybe Exp)]
forall a b. (a -> b) -> [a] -> [b]
map ((Exp -> Maybe Exp) -> m Exp -> m (Maybe Exp)
forall a b. (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Exp -> Maybe Exp
forall a. a -> Maybe a
Just) [a -> m Exp
forall t (m :: * -> *). (Lift t, Quote m) => t -> m Exp
forall (m :: * -> *). Quote m => a -> m Exp
lift a
a, b -> m Exp
forall t (m :: * -> *). (Lift t, Quote m) => t -> m Exp
forall (m :: * -> *). Quote m => b -> m Exp
lift b
b]

-- | @since 2.16.0.0
instance (Lift a, Lift b, Lift c)
      => Lift (# a, b, c #) where
  liftTyped :: forall (m :: * -> *).
Quote m =>
(# a, b, c #) -> Code m (# a, b, c #)
liftTyped (# a, b, c #)
x = m Exp -> Code m (# a, b, c #)
forall a (m :: * -> *). Quote m => m Exp -> Code m a
unsafeCodeCoerce ((# a, b, c #) -> m Exp
forall t (m :: * -> *). (Lift t, Quote m) => t -> m Exp
forall (m :: * -> *). Quote m => (# a, b, c #) -> m Exp
lift (# a, b, c #)
x)
  lift :: forall (m :: * -> *). Quote m => (# a, b, c #) -> m Exp
lift (# a
a, b
b, c
c #)
    = ([Maybe Exp] -> Exp) -> m [Maybe Exp] -> m Exp
forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
liftM [Maybe Exp] -> Exp
UnboxedTupE (m [Maybe Exp] -> m Exp) -> m [Maybe Exp] -> m Exp
forall a b. (a -> b) -> a -> b
$ [m (Maybe Exp)] -> m [Maybe Exp]
forall (t :: * -> *) (m :: * -> *) a.
(Traversable t, Monad m) =>
t (m a) -> m (t a)
forall (m :: * -> *) a. Monad m => [m a] -> m [a]
sequence ([m (Maybe Exp)] -> m [Maybe Exp])
-> [m (Maybe Exp)] -> m [Maybe Exp]
forall a b. (a -> b) -> a -> b
$ (m Exp -> m (Maybe Exp)) -> [m Exp] -> [m (Maybe Exp)]
forall a b. (a -> b) -> [a] -> [b]
map ((Exp -> Maybe Exp) -> m Exp -> m (Maybe Exp)
forall a b. (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Exp -> Maybe Exp
forall a. a -> Maybe a
Just) [a -> m Exp
forall t (m :: * -> *). (Lift t, Quote m) => t -> m Exp
forall (m :: * -> *). Quote m => a -> m Exp
lift a
a, b -> m Exp
forall t (m :: * -> *). (Lift t, Quote m) => t -> m Exp
forall (m :: * -> *). Quote m => b -> m Exp
lift b
b, c -> m Exp
forall t (m :: * -> *). (Lift t, Quote m) => t -> m Exp
forall (m :: * -> *). Quote m => c -> m Exp
lift c
c]

-- | @since 2.16.0.0
instance (Lift a, Lift b, Lift c, Lift d)
      => Lift (# a, b, c, d #) where
  liftTyped :: forall (m :: * -> *).
Quote m =>
(# a, b, c, d #) -> Code m (# a, b, c, d #)
liftTyped (# a, b, c, d #)
x = m Exp -> Code m (# a, b, c, d #)
forall a (m :: * -> *). Quote m => m Exp -> Code m a
unsafeCodeCoerce ((# a, b, c, d #) -> m Exp
forall t (m :: * -> *). (Lift t, Quote m) => t -> m Exp
forall (m :: * -> *). Quote m => (# a, b, c, d #) -> m Exp
lift (# a, b, c, d #)
x)
  lift :: forall (m :: * -> *). Quote m => (# a, b, c, d #) -> m Exp
lift (# a
a, b
b, c
c, d
d #)
    = ([Maybe Exp] -> Exp) -> m [Maybe Exp] -> m Exp
forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
liftM [Maybe Exp] -> Exp
UnboxedTupE (m [Maybe Exp] -> m Exp) -> m [Maybe Exp] -> m Exp
forall a b. (a -> b) -> a -> b
$ [m (Maybe Exp)] -> m [Maybe Exp]
forall (t :: * -> *) (m :: * -> *) a.
(Traversable t, Monad m) =>
t (m a) -> m (t a)
forall (m :: * -> *) a. Monad m => [m a] -> m [a]
sequence ([m (Maybe Exp)] -> m [Maybe Exp])
-> [m (Maybe Exp)] -> m [Maybe Exp]
forall a b. (a -> b) -> a -> b
$ (m Exp -> m (Maybe Exp)) -> [m Exp] -> [m (Maybe Exp)]
forall a b. (a -> b) -> [a] -> [b]
map ((Exp -> Maybe Exp) -> m Exp -> m (Maybe Exp)
forall a b. (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Exp -> Maybe Exp
forall a. a -> Maybe a
Just) [ a -> m Exp
forall t (m :: * -> *). (Lift t, Quote m) => t -> m Exp
forall (m :: * -> *). Quote m => a -> m Exp
lift a
a, b -> m Exp
forall t (m :: * -> *). (Lift t, Quote m) => t -> m Exp
forall (m :: * -> *). Quote m => b -> m Exp
lift b
b
                                                     , c -> m Exp
forall t (m :: * -> *). (Lift t, Quote m) => t -> m Exp
forall (m :: * -> *). Quote m => c -> m Exp
lift c
c, d -> m Exp
forall t (m :: * -> *). (Lift t, Quote m) => t -> m Exp
forall (m :: * -> *). Quote m => d -> m Exp
lift d
d ]

-- | @since 2.16.0.0
instance (Lift a, Lift b, Lift c, Lift d, Lift e)
      => Lift (# a, b, c, d, e #) where
  liftTyped :: forall (m :: * -> *).
Quote m =>
(# a, b, c, d, e #) -> Code m (# a, b, c, d, e #)
liftTyped (# a, b, c, d, e #)
x = m Exp -> Code m (# a, b, c, d, e #)
forall a (m :: * -> *). Quote m => m Exp -> Code m a
unsafeCodeCoerce ((# a, b, c, d, e #) -> m Exp
forall t (m :: * -> *). (Lift t, Quote m) => t -> m Exp
forall (m :: * -> *). Quote m => (# a, b, c, d, e #) -> m Exp
lift (# a, b, c, d, e #)
x)
  lift :: forall (m :: * -> *). Quote m => (# a, b, c, d, e #) -> m Exp
lift (# a
a, b
b, c
c, d
d, e
e #)
    = ([Maybe Exp] -> Exp) -> m [Maybe Exp] -> m Exp
forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
liftM [Maybe Exp] -> Exp
UnboxedTupE (m [Maybe Exp] -> m Exp) -> m [Maybe Exp] -> m Exp
forall a b. (a -> b) -> a -> b
$ [m (Maybe Exp)] -> m [Maybe Exp]
forall (t :: * -> *) (m :: * -> *) a.
(Traversable t, Monad m) =>
t (m a) -> m (t a)
forall (m :: * -> *) a. Monad m => [m a] -> m [a]
sequence ([m (Maybe Exp)] -> m [Maybe Exp])
-> [m (Maybe Exp)] -> m [Maybe Exp]
forall a b. (a -> b) -> a -> b
$ (m Exp -> m (Maybe Exp)) -> [m Exp] -> [m (Maybe Exp)]
forall a b. (a -> b) -> [a] -> [b]
map ((Exp -> Maybe Exp) -> m Exp -> m (Maybe Exp)
forall a b. (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Exp -> Maybe Exp
forall a. a -> Maybe a
Just) [ a -> m Exp
forall t (m :: * -> *). (Lift t, Quote m) => t -> m Exp
forall (m :: * -> *). Quote m => a -> m Exp
lift a
a, b -> m Exp
forall t (m :: * -> *). (Lift t, Quote m) => t -> m Exp
forall (m :: * -> *). Quote m => b -> m Exp
lift b
b
                                                     , c -> m Exp
forall t (m :: * -> *). (Lift t, Quote m) => t -> m Exp
forall (m :: * -> *). Quote m => c -> m Exp
lift c
c, d -> m Exp
forall t (m :: * -> *). (Lift t, Quote m) => t -> m Exp
forall (m :: * -> *). Quote m => d -> m Exp
lift d
d, e -> m Exp
forall t (m :: * -> *). (Lift t, Quote m) => t -> m Exp
forall (m :: * -> *). Quote m => e -> m Exp
lift e
e ]

-- | @since 2.16.0.0
instance (Lift a, Lift b, Lift c, Lift d, Lift e, Lift f)
      => Lift (# a, b, c, d, e, f #) where
  liftTyped :: forall (m :: * -> *).
Quote m =>
(# a, b, c, d, e, f #) -> Code m (# a, b, c, d, e, f #)
liftTyped (# a, b, c, d, e, f #)
x = m Exp -> Code m (# a, b, c, d, e, f #)
forall a (m :: * -> *). Quote m => m Exp -> Code m a
unsafeCodeCoerce ((# a, b, c, d, e, f #) -> m Exp
forall t (m :: * -> *). (Lift t, Quote m) => t -> m Exp
forall (m :: * -> *). Quote m => (# a, b, c, d, e, f #) -> m Exp
lift (# a, b, c, d, e, f #)
x)
  lift :: forall (m :: * -> *). Quote m => (# a, b, c, d, e, f #) -> m Exp
lift (# a
a, b
b, c
c, d
d, e
e, f
f #)
    = ([Maybe Exp] -> Exp) -> m [Maybe Exp] -> m Exp
forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
liftM [Maybe Exp] -> Exp
UnboxedTupE (m [Maybe Exp] -> m Exp) -> m [Maybe Exp] -> m Exp
forall a b. (a -> b) -> a -> b
$ [m (Maybe Exp)] -> m [Maybe Exp]
forall (t :: * -> *) (m :: * -> *) a.
(Traversable t, Monad m) =>
t (m a) -> m (t a)
forall (m :: * -> *) a. Monad m => [m a] -> m [a]
sequence ([m (Maybe Exp)] -> m [Maybe Exp])
-> [m (Maybe Exp)] -> m [Maybe Exp]
forall a b. (a -> b) -> a -> b
$ (m Exp -> m (Maybe Exp)) -> [m Exp] -> [m (Maybe Exp)]
forall a b. (a -> b) -> [a] -> [b]
map ((Exp -> Maybe Exp) -> m Exp -> m (Maybe Exp)
forall a b. (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Exp -> Maybe Exp
forall a. a -> Maybe a
Just) [ a -> m Exp
forall t (m :: * -> *). (Lift t, Quote m) => t -> m Exp
forall (m :: * -> *). Quote m => a -> m Exp
lift a
a, b -> m Exp
forall t (m :: * -> *). (Lift t, Quote m) => t -> m Exp
forall (m :: * -> *). Quote m => b -> m Exp
lift b
b, c -> m Exp
forall t (m :: * -> *). (Lift t, Quote m) => t -> m Exp
forall (m :: * -> *). Quote m => c -> m Exp
lift c
c
                                                     , d -> m Exp
forall t (m :: * -> *). (Lift t, Quote m) => t -> m Exp
forall (m :: * -> *). Quote m => d -> m Exp
lift d
d, e -> m Exp
forall t (m :: * -> *). (Lift t, Quote m) => t -> m Exp
forall (m :: * -> *). Quote m => e -> m Exp
lift e
e, f -> m Exp
forall t (m :: * -> *). (Lift t, Quote m) => t -> m Exp
forall (m :: * -> *). Quote m => f -> m Exp
lift f
f ]

-- | @since 2.16.0.0
instance (Lift a, Lift b, Lift c, Lift d, Lift e, Lift f, Lift g)
      => Lift (# a, b, c, d, e, f, g #) where
  liftTyped :: forall (m :: * -> *).
Quote m =>
(# a, b, c, d, e, f, g #) -> Code m (# a, b, c, d, e, f, g #)
liftTyped (# a, b, c, d, e, f, g #)
x = m Exp -> Code m (# a, b, c, d, e, f, g #)
forall a (m :: * -> *). Quote m => m Exp -> Code m a
unsafeCodeCoerce ((# a, b, c, d, e, f, g #) -> m Exp
forall t (m :: * -> *). (Lift t, Quote m) => t -> m Exp
forall (m :: * -> *). Quote m => (# a, b, c, d, e, f, g #) -> m Exp
lift (# a, b, c, d, e, f, g #)
x)
  lift :: forall (m :: * -> *). Quote m => (# a, b, c, d, e, f, g #) -> m Exp
lift (# a
a, b
b, c
c, d
d, e
e, f
f, g
g #)
    = ([Maybe Exp] -> Exp) -> m [Maybe Exp] -> m Exp
forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
liftM [Maybe Exp] -> Exp
UnboxedTupE (m [Maybe Exp] -> m Exp) -> m [Maybe Exp] -> m Exp
forall a b. (a -> b) -> a -> b
$ [m (Maybe Exp)] -> m [Maybe Exp]
forall (t :: * -> *) (m :: * -> *) a.
(Traversable t, Monad m) =>
t (m a) -> m (t a)
forall (m :: * -> *) a. Monad m => [m a] -> m [a]
sequence ([m (Maybe Exp)] -> m [Maybe Exp])
-> [m (Maybe Exp)] -> m [Maybe Exp]
forall a b. (a -> b) -> a -> b
$ (m Exp -> m (Maybe Exp)) -> [m Exp] -> [m (Maybe Exp)]
forall a b. (a -> b) -> [a] -> [b]
map ((Exp -> Maybe Exp) -> m Exp -> m (Maybe Exp)
forall a b. (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Exp -> Maybe Exp
forall a. a -> Maybe a
Just) [ a -> m Exp
forall t (m :: * -> *). (Lift t, Quote m) => t -> m Exp
forall (m :: * -> *). Quote m => a -> m Exp
lift a
a, b -> m Exp
forall t (m :: * -> *). (Lift t, Quote m) => t -> m Exp
forall (m :: * -> *). Quote m => b -> m Exp
lift b
b, c -> m Exp
forall t (m :: * -> *). (Lift t, Quote m) => t -> m Exp
forall (m :: * -> *). Quote m => c -> m Exp
lift c
c
                                                     , d -> m Exp
forall t (m :: * -> *). (Lift t, Quote m) => t -> m Exp
forall (m :: * -> *). Quote m => d -> m Exp
lift d
d, e -> m Exp
forall t (m :: * -> *). (Lift t, Quote m) => t -> m Exp
forall (m :: * -> *). Quote m => e -> m Exp
lift e
e, f -> m Exp
forall t (m :: * -> *). (Lift t, Quote m) => t -> m Exp
forall (m :: * -> *). Quote m => f -> m Exp
lift f
f
                                                     , g -> m Exp
forall t (m :: * -> *). (Lift t, Quote m) => t -> m Exp
forall (m :: * -> *). Quote m => g -> m Exp
lift g
g ]

-- | @since 2.16.0.0
instance (Lift a, Lift b) => Lift (# a | b #) where
  liftTyped :: forall (m :: * -> *). Quote m => (# a | b #) -> Code m (# a | b #)
liftTyped (# a | b #)
x = m Exp -> Code m (# a | b #)
forall a (m :: * -> *). Quote m => m Exp -> Code m a
unsafeCodeCoerce ((# a | b #) -> m Exp
forall t (m :: * -> *). (Lift t, Quote m) => t -> m Exp
forall (m :: * -> *). Quote m => (# a | b #) -> m Exp
lift (# a | b #)
x)
  lift :: forall (m :: * -> *). Quote m => (# a | b #) -> m Exp
lift (# a | b #)
x
    = case (# a | b #)
x of
        (# a
y | #) -> Exp -> Int -> Int -> Exp
UnboxedSumE (Exp -> Int -> Int -> Exp) -> m Exp -> m (Int -> Int -> Exp)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> a -> m Exp
forall t (m :: * -> *). (Lift t, Quote m) => t -> m Exp
forall (m :: * -> *). Quote m => a -> m Exp
lift a
y m (Int -> Int -> Exp) -> m Int -> m (Int -> Exp)
forall a b. m (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Int -> m Int
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Int
1 m (Int -> Exp) -> m Int -> m Exp
forall a b. m (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Int -> m Int
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Int
2
        (# | b
y #) -> Exp -> Int -> Int -> Exp
UnboxedSumE (Exp -> Int -> Int -> Exp) -> m Exp -> m (Int -> Int -> Exp)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> b -> m Exp
forall t (m :: * -> *). (Lift t, Quote m) => t -> m Exp
forall (m :: * -> *). Quote m => b -> m Exp
lift b
y m (Int -> Int -> Exp) -> m Int -> m (Int -> Exp)
forall a b. m (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Int -> m Int
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Int
2 m (Int -> Exp) -> m Int -> m Exp
forall a b. m (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Int -> m Int
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Int
2

-- | @since 2.16.0.0
instance (Lift a, Lift b, Lift c)
      => Lift (# a | b | c #) where
  liftTyped :: forall (m :: * -> *).
Quote m =>
(# a | b | c #) -> Code m (# a | b | c #)
liftTyped (# a | b | c #)
x = m Exp -> Code m (# a | b | c #)
forall a (m :: * -> *). Quote m => m Exp -> Code m a
unsafeCodeCoerce ((# a | b | c #) -> m Exp
forall t (m :: * -> *). (Lift t, Quote m) => t -> m Exp
forall (m :: * -> *). Quote m => (# a | b | c #) -> m Exp
lift (# a | b | c #)
x)
  lift :: forall (m :: * -> *). Quote m => (# a | b | c #) -> m Exp
lift (# a | b | c #)
x
    = case (# a | b | c #)
x of
        (# a
y | | #) -> Exp -> Int -> Int -> Exp
UnboxedSumE (Exp -> Int -> Int -> Exp) -> m Exp -> m (Int -> Int -> Exp)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> a -> m Exp
forall t (m :: * -> *). (Lift t, Quote m) => t -> m Exp
forall (m :: * -> *). Quote m => a -> m Exp
lift a
y m (Int -> Int -> Exp) -> m Int -> m (Int -> Exp)
forall a b. m (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Int -> m Int
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Int
1 m (Int -> Exp) -> m Int -> m Exp
forall a b. m (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Int -> m Int
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Int
3
        (# | b
y | #) -> Exp -> Int -> Int -> Exp
UnboxedSumE (Exp -> Int -> Int -> Exp) -> m Exp -> m (Int -> Int -> Exp)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> b -> m Exp
forall t (m :: * -> *). (Lift t, Quote m) => t -> m Exp
forall (m :: * -> *). Quote m => b -> m Exp
lift b
y m (Int -> Int -> Exp) -> m Int -> m (Int -> Exp)
forall a b. m (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Int -> m Int
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Int
2 m (Int -> Exp) -> m Int -> m Exp
forall a b. m (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Int -> m Int
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Int
3
        (# | | c
y #) -> Exp -> Int -> Int -> Exp
UnboxedSumE (Exp -> Int -> Int -> Exp) -> m Exp -> m (Int -> Int -> Exp)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> c -> m Exp
forall t (m :: * -> *). (Lift t, Quote m) => t -> m Exp
forall (m :: * -> *). Quote m => c -> m Exp
lift c
y m (Int -> Int -> Exp) -> m Int -> m (Int -> Exp)
forall a b. m (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Int -> m Int
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Int
3 m (Int -> Exp) -> m Int -> m Exp
forall a b. m (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Int -> m Int
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Int
3

-- | @since 2.16.0.0
instance (Lift a, Lift b, Lift c, Lift d)
      => Lift (# a | b | c | d #) where
  liftTyped :: forall (m :: * -> *).
Quote m =>
(# a | b | c | d #) -> Code m (# a | b | c | d #)
liftTyped (# a | b | c | d #)
x = m Exp -> Code m (# a | b | c | d #)
forall a (m :: * -> *). Quote m => m Exp -> Code m a
unsafeCodeCoerce ((# a | b | c | d #) -> m Exp
forall t (m :: * -> *). (Lift t, Quote m) => t -> m Exp
forall (m :: * -> *). Quote m => (# a | b | c | d #) -> m Exp
lift (# a | b | c | d #)
x)
  lift :: forall (m :: * -> *). Quote m => (# a | b | c | d #) -> m Exp
lift (# a | b | c | d #)
x
    = case (# a | b | c | d #)
x of
        (# a
y | | | #) -> Exp -> Int -> Int -> Exp
UnboxedSumE (Exp -> Int -> Int -> Exp) -> m Exp -> m (Int -> Int -> Exp)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> a -> m Exp
forall t (m :: * -> *). (Lift t, Quote m) => t -> m Exp
forall (m :: * -> *). Quote m => a -> m Exp
lift a
y m (Int -> Int -> Exp) -> m Int -> m (Int -> Exp)
forall a b. m (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Int -> m Int
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Int
1 m (Int -> Exp) -> m Int -> m Exp
forall a b. m (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Int -> m Int
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Int
4
        (# | b
y | | #) -> Exp -> Int -> Int -> Exp
UnboxedSumE (Exp -> Int -> Int -> Exp) -> m Exp -> m (Int -> Int -> Exp)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> b -> m Exp
forall t (m :: * -> *). (Lift t, Quote m) => t -> m Exp
forall (m :: * -> *). Quote m => b -> m Exp
lift b
y m (Int -> Int -> Exp) -> m Int -> m (Int -> Exp)
forall a b. m (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Int -> m Int
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Int
2 m (Int -> Exp) -> m Int -> m Exp
forall a b. m (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Int -> m Int
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Int
4
        (# | | c
y | #) -> Exp -> Int -> Int -> Exp
UnboxedSumE (Exp -> Int -> Int -> Exp) -> m Exp -> m (Int -> Int -> Exp)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> c -> m Exp
forall t (m :: * -> *). (Lift t, Quote m) => t -> m Exp
forall (m :: * -> *). Quote m => c -> m Exp
lift c
y m (Int -> Int -> Exp) -> m Int -> m (Int -> Exp)
forall a b. m (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Int -> m Int
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Int
3 m (Int -> Exp) -> m Int -> m Exp
forall a b. m (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Int -> m Int
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Int
4
        (# | | | d
y #) -> Exp -> Int -> Int -> Exp
UnboxedSumE (Exp -> Int -> Int -> Exp) -> m Exp -> m (Int -> Int -> Exp)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> d -> m Exp
forall t (m :: * -> *). (Lift t, Quote m) => t -> m Exp
forall (m :: * -> *). Quote m => d -> m Exp
lift d
y m (Int -> Int -> Exp) -> m Int -> m (Int -> Exp)
forall a b. m (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Int -> m Int
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Int
4 m (Int -> Exp) -> m Int -> m Exp
forall a b. m (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Int -> m Int
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Int
4

-- | @since 2.16.0.0
instance (Lift a, Lift b, Lift c, Lift d, Lift e)
      => Lift (# a | b | c | d | e #) where
  liftTyped :: forall (m :: * -> *).
Quote m =>
(# a | b | c | d | e #) -> Code m (# a | b | c | d | e #)
liftTyped (# a | b | c | d | e #)
x = m Exp -> Code m (# a | b | c | d | e #)
forall a (m :: * -> *). Quote m => m Exp -> Code m a
unsafeCodeCoerce ((# a | b | c | d | e #) -> m Exp
forall t (m :: * -> *). (Lift t, Quote m) => t -> m Exp
forall (m :: * -> *). Quote m => (# a | b | c | d | e #) -> m Exp
lift (# a | b | c | d | e #)
x)
  lift :: forall (m :: * -> *). Quote m => (# a | b | c | d | e #) -> m Exp
lift (# a | b | c | d | e #)
x
    = case (# a | b | c | d | e #)
x of
        (# a
y | | | | #) -> Exp -> Int -> Int -> Exp
UnboxedSumE (Exp -> Int -> Int -> Exp) -> m Exp -> m (Int -> Int -> Exp)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> a -> m Exp
forall t (m :: * -> *). (Lift t, Quote m) => t -> m Exp
forall (m :: * -> *). Quote m => a -> m Exp
lift a
y m (Int -> Int -> Exp) -> m Int -> m (Int -> Exp)
forall a b. m (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Int -> m Int
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Int
1 m (Int -> Exp) -> m Int -> m Exp
forall a b. m (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Int -> m Int
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Int
5
        (# | b
y | | | #) -> Exp -> Int -> Int -> Exp
UnboxedSumE (Exp -> Int -> Int -> Exp) -> m Exp -> m (Int -> Int -> Exp)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> b -> m Exp
forall t (m :: * -> *). (Lift t, Quote m) => t -> m Exp
forall (m :: * -> *). Quote m => b -> m Exp
lift b
y m (Int -> Int -> Exp) -> m Int -> m (Int -> Exp)
forall a b. m (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Int -> m Int
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Int
2 m (Int -> Exp) -> m Int -> m Exp
forall a b. m (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Int -> m Int
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Int
5
        (# | | c
y | | #) -> Exp -> Int -> Int -> Exp
UnboxedSumE (Exp -> Int -> Int -> Exp) -> m Exp -> m (Int -> Int -> Exp)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> c -> m Exp
forall t (m :: * -> *). (Lift t, Quote m) => t -> m Exp
forall (m :: * -> *). Quote m => c -> m Exp
lift c
y m (Int -> Int -> Exp) -> m Int -> m (Int -> Exp)
forall a b. m (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Int -> m Int
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Int
3 m (Int -> Exp) -> m Int -> m Exp
forall a b. m (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Int -> m Int
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Int
5
        (# | | | d
y | #) -> Exp -> Int -> Int -> Exp
UnboxedSumE (Exp -> Int -> Int -> Exp) -> m Exp -> m (Int -> Int -> Exp)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> d -> m Exp
forall t (m :: * -> *). (Lift t, Quote m) => t -> m Exp
forall (m :: * -> *). Quote m => d -> m Exp
lift d
y m (Int -> Int -> Exp) -> m Int -> m (Int -> Exp)
forall a b. m (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Int -> m Int
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Int
4 m (Int -> Exp) -> m Int -> m Exp
forall a b. m (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Int -> m Int
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Int
5
        (# | | | | e
y #) -> Exp -> Int -> Int -> Exp
UnboxedSumE (Exp -> Int -> Int -> Exp) -> m Exp -> m (Int -> Int -> Exp)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> e -> m Exp
forall t (m :: * -> *). (Lift t, Quote m) => t -> m Exp
forall (m :: * -> *). Quote m => e -> m Exp
lift e
y m (Int -> Int -> Exp) -> m Int -> m (Int -> Exp)
forall a b. m (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Int -> m Int
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Int
5 m (Int -> Exp) -> m Int -> m Exp
forall a b. m (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Int -> m Int
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Int
5

-- | @since 2.16.0.0
instance (Lift a, Lift b, Lift c, Lift d, Lift e, Lift f)
      => Lift (# a | b | c | d | e | f #) where
  liftTyped :: forall (m :: * -> *).
Quote m =>
(# a | b | c | d | e | f #) -> Code m (# a | b | c | d | e | f #)
liftTyped (# a | b | c | d | e | f #)
x = m Exp -> Code m (# a | b | c | d | e | f #)
forall a (m :: * -> *). Quote m => m Exp -> Code m a
unsafeCodeCoerce ((# a | b | c | d | e | f #) -> m Exp
forall t (m :: * -> *). (Lift t, Quote m) => t -> m Exp
forall (m :: * -> *).
Quote m =>
(# a | b | c | d | e | f #) -> m Exp
lift (# a | b | c | d | e | f #)
x)
  lift :: forall (m :: * -> *).
Quote m =>
(# a | b | c | d | e | f #) -> m Exp
lift (# a | b | c | d | e | f #)
x
    = case (# a | b | c | d | e | f #)
x of
        (# a
y | | | | | #) -> Exp -> Int -> Int -> Exp
UnboxedSumE (Exp -> Int -> Int -> Exp) -> m Exp -> m (Int -> Int -> Exp)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> a -> m Exp
forall t (m :: * -> *). (Lift t, Quote m) => t -> m Exp
forall (m :: * -> *). Quote m => a -> m Exp
lift a
y m (Int -> Int -> Exp) -> m Int -> m (Int -> Exp)
forall a b. m (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Int -> m Int
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Int
1 m (Int -> Exp) -> m Int -> m Exp
forall a b. m (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Int -> m Int
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Int
6
        (# | b
y | | | | #) -> Exp -> Int -> Int -> Exp
UnboxedSumE (Exp -> Int -> Int -> Exp) -> m Exp -> m (Int -> Int -> Exp)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> b -> m Exp
forall t (m :: * -> *). (Lift t, Quote m) => t -> m Exp
forall (m :: * -> *). Quote m => b -> m Exp
lift b
y m (Int -> Int -> Exp) -> m Int -> m (Int -> Exp)
forall a b. m (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Int -> m Int
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Int
2 m (Int -> Exp) -> m Int -> m Exp
forall a b. m (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Int -> m Int
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Int
6
        (# | | c
y | | | #) -> Exp -> Int -> Int -> Exp
UnboxedSumE (Exp -> Int -> Int -> Exp) -> m Exp -> m (Int -> Int -> Exp)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> c -> m Exp
forall t (m :: * -> *). (Lift t, Quote m) => t -> m Exp
forall (m :: * -> *). Quote m => c -> m Exp
lift c
y m (Int -> Int -> Exp) -> m Int -> m (Int -> Exp)
forall a b. m (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Int -> m Int
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Int
3 m (Int -> Exp) -> m Int -> m Exp
forall a b. m (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Int -> m Int
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Int
6
        (# | | | d
y | | #) -> Exp -> Int -> Int -> Exp
UnboxedSumE (Exp -> Int -> Int -> Exp) -> m Exp -> m (Int -> Int -> Exp)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> d -> m Exp
forall t (m :: * -> *). (Lift t, Quote m) => t -> m Exp
forall (m :: * -> *). Quote m => d -> m Exp
lift d
y m (Int -> Int -> Exp) -> m Int -> m (Int -> Exp)
forall a b. m (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Int -> m Int
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Int
4 m (Int -> Exp) -> m Int -> m Exp
forall a b. m (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Int -> m Int
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Int
6
        (# | | | | e
y | #) -> Exp -> Int -> Int -> Exp
UnboxedSumE (Exp -> Int -> Int -> Exp) -> m Exp -> m (Int -> Int -> Exp)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> e -> m Exp
forall t (m :: * -> *). (Lift t, Quote m) => t -> m Exp
forall (m :: * -> *). Quote m => e -> m Exp
lift e
y m (Int -> Int -> Exp) -> m Int -> m (Int -> Exp)
forall a b. m (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Int -> m Int
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Int
5 m (Int -> Exp) -> m Int -> m Exp
forall a b. m (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Int -> m Int
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Int
6
        (# | | | | | f
y #) -> Exp -> Int -> Int -> Exp
UnboxedSumE (Exp -> Int -> Int -> Exp) -> m Exp -> m (Int -> Int -> Exp)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> f -> m Exp
forall t (m :: * -> *). (Lift t, Quote m) => t -> m Exp
forall (m :: * -> *). Quote m => f -> m Exp
lift f
y m (Int -> Int -> Exp) -> m Int -> m (Int -> Exp)
forall a b. m (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Int -> m Int
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Int
6 m (Int -> Exp) -> m Int -> m Exp
forall a b. m (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Int -> m Int
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Int
6

-- | @since 2.16.0.0
instance (Lift a, Lift b, Lift c, Lift d, Lift e, Lift f, Lift g)
      => Lift (# a | b | c | d | e | f | g #) where
  liftTyped :: forall (m :: * -> *).
Quote m =>
(# a | b | c | d | e | f | g #)
-> Code m (# a | b | c | d | e | f | g #)
liftTyped (# a | b | c | d | e | f | g #)
x = m Exp -> Code m (# a | b | c | d | e | f | g #)
forall a (m :: * -> *). Quote m => m Exp -> Code m a
unsafeCodeCoerce ((# a | b | c | d | e | f | g #) -> m Exp
forall t (m :: * -> *). (Lift t, Quote m) => t -> m Exp
forall (m :: * -> *).
Quote m =>
(# a | b | c | d | e | f | g #) -> m Exp
lift (# a | b | c | d | e | f | g #)
x)
  lift :: forall (m :: * -> *).
Quote m =>
(# a | b | c | d | e | f | g #) -> m Exp
lift (# a | b | c | d | e | f | g #)
x
    = case (# a | b | c | d | e | f | g #)
x of
        (# a
y | | | | | | #) -> Exp -> Int -> Int -> Exp
UnboxedSumE (Exp -> Int -> Int -> Exp) -> m Exp -> m (Int -> Int -> Exp)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> a -> m Exp
forall t (m :: * -> *). (Lift t, Quote m) => t -> m Exp
forall (m :: * -> *). Quote m => a -> m Exp
lift a
y m (Int -> Int -> Exp) -> m Int -> m (Int -> Exp)
forall a b. m (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Int -> m Int
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Int
1 m (Int -> Exp) -> m Int -> m Exp
forall a b. m (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Int -> m Int
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Int
7
        (# | b
y | | | | | #) -> Exp -> Int -> Int -> Exp
UnboxedSumE (Exp -> Int -> Int -> Exp) -> m Exp -> m (Int -> Int -> Exp)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> b -> m Exp
forall t (m :: * -> *). (Lift t, Quote m) => t -> m Exp
forall (m :: * -> *). Quote m => b -> m Exp
lift b
y m (Int -> Int -> Exp) -> m Int -> m (Int -> Exp)
forall a b. m (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Int -> m Int
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Int
2 m (Int -> Exp) -> m Int -> m Exp
forall a b. m (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Int -> m Int
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Int
7
        (# | | c
y | | | | #) -> Exp -> Int -> Int -> Exp
UnboxedSumE (Exp -> Int -> Int -> Exp) -> m Exp -> m (Int -> Int -> Exp)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> c -> m Exp
forall t (m :: * -> *). (Lift t, Quote m) => t -> m Exp
forall (m :: * -> *). Quote m => c -> m Exp
lift c
y m (Int -> Int -> Exp) -> m Int -> m (Int -> Exp)
forall a b. m (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Int -> m Int
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Int
3 m (Int -> Exp) -> m Int -> m Exp
forall a b. m (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Int -> m Int
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Int
7
        (# | | | d
y | | | #) -> Exp -> Int -> Int -> Exp
UnboxedSumE (Exp -> Int -> Int -> Exp) -> m Exp -> m (Int -> Int -> Exp)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> d -> m Exp
forall t (m :: * -> *). (Lift t, Quote m) => t -> m Exp
forall (m :: * -> *). Quote m => d -> m Exp
lift d
y m (Int -> Int -> Exp) -> m Int -> m (Int -> Exp)
forall a b. m (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Int -> m Int
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Int
4 m (Int -> Exp) -> m Int -> m Exp
forall a b. m (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Int -> m Int
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Int
7
        (# | | | | e
y | | #) -> Exp -> Int -> Int -> Exp
UnboxedSumE (Exp -> Int -> Int -> Exp) -> m Exp -> m (Int -> Int -> Exp)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> e -> m Exp
forall t (m :: * -> *). (Lift t, Quote m) => t -> m Exp
forall (m :: * -> *). Quote m => e -> m Exp
lift e
y m (Int -> Int -> Exp) -> m Int -> m (Int -> Exp)
forall a b. m (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Int -> m Int
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Int
5 m (Int -> Exp) -> m Int -> m Exp
forall a b. m (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Int -> m Int
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Int
7
        (# | | | | | f
y | #) -> Exp -> Int -> Int -> Exp
UnboxedSumE (Exp -> Int -> Int -> Exp) -> m Exp -> m (Int -> Int -> Exp)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> f -> m Exp
forall t (m :: * -> *). (Lift t, Quote m) => t -> m Exp
forall (m :: * -> *). Quote m => f -> m Exp
lift f
y m (Int -> Int -> Exp) -> m Int -> m (Int -> Exp)
forall a b. m (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Int -> m Int
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Int
6 m (Int -> Exp) -> m Int -> m Exp
forall a b. m (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Int -> m Int
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Int
7
        (# | | | | | | g
y #) -> Exp -> Int -> Int -> Exp
UnboxedSumE (Exp -> Int -> Int -> Exp) -> m Exp -> m (Int -> Int -> Exp)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> g -> m Exp
forall t (m :: * -> *). (Lift t, Quote m) => t -> m Exp
forall (m :: * -> *). Quote m => g -> m Exp
lift g
y m (Int -> Int -> Exp) -> m Int -> m (Int -> Exp)
forall a b. m (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Int -> m Int
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Int
7 m (Int -> Exp) -> m Int -> m Exp
forall a b. m (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Int -> m Int
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Int
7

-- TH has a special form for literal strings,
-- which we should take advantage of.
-- NB: the lhs of the rule has no args, so that
--     the rule will apply to a 'lift' all on its own
--     which happens to be the way the type checker
--     creates it.
{-# RULES "TH:liftString" lift = \s -> return (LitE (StringL s)) #-}


trueName, falseName :: Name
trueName :: Name
trueName  = NameSpace -> FilePath -> FilePath -> FilePath -> Name
mkNameG NameSpace
DataName FilePath
"ghc-prim" FilePath
"GHC.Types" FilePath
"True"
falseName :: Name
falseName = NameSpace -> FilePath -> FilePath -> FilePath -> Name
mkNameG NameSpace
DataName FilePath
"ghc-prim" FilePath
"GHC.Types" FilePath
"False"

nothingName, justName :: Name
nothingName :: Name
nothingName = NameSpace -> FilePath -> FilePath -> FilePath -> Name
mkNameG NameSpace
DataName FilePath
"base" FilePath
"GHC.Maybe" FilePath
"Nothing"
justName :: Name
justName    = NameSpace -> FilePath -> FilePath -> FilePath -> Name
mkNameG NameSpace
DataName FilePath
"base" FilePath
"GHC.Maybe" FilePath
"Just"

leftName, rightName :: Name
leftName :: Name
leftName  = NameSpace -> FilePath -> FilePath -> FilePath -> Name
mkNameG NameSpace
DataName FilePath
"base" FilePath
"Data.Either" FilePath
"Left"
rightName :: Name
rightName = NameSpace -> FilePath -> FilePath -> FilePath -> Name
mkNameG NameSpace
DataName FilePath
"base" FilePath
"Data.Either" FilePath
"Right"

nonemptyName :: Name
nonemptyName :: Name
nonemptyName = NameSpace -> FilePath -> FilePath -> FilePath -> Name
mkNameG NameSpace
DataName FilePath
"base" FilePath
"GHC.Base" FilePath
":|"

oneName, manyName :: Name
oneName :: Name
oneName  = NameSpace -> FilePath -> FilePath -> FilePath -> Name
mkNameG NameSpace
DataName FilePath
"ghc-prim" FilePath
"GHC.Types" FilePath
"One"
manyName :: Name
manyName = NameSpace -> FilePath -> FilePath -> FilePath -> Name
mkNameG NameSpace
DataName FilePath
"ghc-prim" FilePath
"GHC.Types" FilePath
"Many"
-----------------------------------------------------
--
--              Generic Lift implementations
--
-----------------------------------------------------

-- | 'dataToQa' is an internal utility function for constructing generic
-- conversion functions from types with 'Data' instances to various
-- quasi-quoting representations.  See the source of 'dataToExpQ' and
-- 'dataToPatQ' for two example usages: @mkCon@, @mkLit@
-- and @appQ@ are overloadable to account for different syntax for
-- expressions and patterns; @antiQ@ allows you to override type-specific
-- cases, a common usage is just @const Nothing@, which results in
-- no overloading.
dataToQa  ::  forall m a k q. (Quote m, Data a)
          =>  (Name -> k)
          ->  (Lit -> m q)
          ->  (k -> [m q] -> m q)
          ->  (forall b . Data b => b -> Maybe (m q))
          ->  a
          ->  m q
dataToQa :: forall (m :: * -> *) a k q.
(Quote m, Data a) =>
(Name -> k)
-> (Lit -> m q)
-> (k -> [m q] -> m q)
-> (forall b. Data b => b -> Maybe (m q))
-> a
-> m q
dataToQa Name -> k
mkCon Lit -> m q
mkLit k -> [m q] -> m q
appCon forall b. Data b => b -> Maybe (m q)
antiQ a
t =
    case a -> Maybe (m q)
forall b. Data b => b -> Maybe (m q)
antiQ a
t of
      Maybe (m q)
Nothing ->
          case Constr -> ConstrRep
constrRep Constr
constr of
            AlgConstr Int
_ ->
                k -> [m q] -> m q
appCon (Name -> k
mkCon Name
funOrConName) [m q]
conArgs
              where
                funOrConName :: Name
                funOrConName :: Name
funOrConName =
                    case Constr -> FilePath
showConstr Constr
constr of
                      FilePath
"(:)"       -> OccName -> NameFlavour -> Name
Name (FilePath -> OccName
mkOccName FilePath
":")
                                          (NameSpace -> PkgName -> ModName -> NameFlavour
NameG NameSpace
DataName
                                                (FilePath -> PkgName
mkPkgName FilePath
"ghc-prim")
                                                (FilePath -> ModName
mkModName FilePath
"GHC.Types"))
                      con :: FilePath
con@FilePath
"[]"    -> OccName -> NameFlavour -> Name
Name (FilePath -> OccName
mkOccName FilePath
con)
                                          (NameSpace -> PkgName -> ModName -> NameFlavour
NameG NameSpace
DataName
                                                (FilePath -> PkgName
mkPkgName FilePath
"ghc-prim")
                                                (FilePath -> ModName
mkModName FilePath
"GHC.Types"))
                      con :: FilePath
con@(Char
'(':FilePath
_) -> OccName -> NameFlavour -> Name
Name (FilePath -> OccName
mkOccName FilePath
con)
                                          (NameSpace -> PkgName -> ModName -> NameFlavour
NameG NameSpace
DataName
                                                (FilePath -> PkgName
mkPkgName FilePath
"ghc-prim")
                                                (FilePath -> ModName
mkModName FilePath
"GHC.Tuple"))

                      -- Tricky case: see Note [Data for non-algebraic types]
                      fun :: FilePath
fun@(Char
x:FilePath
_)   | Char -> Bool
startsVarSym Char
x Bool -> Bool -> Bool
|| Char -> Bool
startsVarId Char
x
                                  -> FilePath -> FilePath -> FilePath -> Name
mkNameG_v FilePath
tyconPkg FilePath
tyconMod FilePath
fun
                      FilePath
con         -> FilePath -> FilePath -> FilePath -> Name
mkNameG_d FilePath
tyconPkg FilePath
tyconMod FilePath
con

                  where
                    tycon :: TyCon
                    tycon :: TyCon
tycon = (TypeRep -> TyCon
typeRepTyCon (TypeRep -> TyCon) -> (a -> TypeRep) -> a -> TyCon
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> TypeRep
forall a. Typeable a => a -> TypeRep
typeOf) a
t

                    tyconPkg, tyconMod :: String
                    tyconPkg :: FilePath
tyconPkg = TyCon -> FilePath
tyConPackage TyCon
tycon
                    tyconMod :: FilePath
tyconMod = TyCon -> FilePath
tyConModule  TyCon
tycon

                conArgs :: [m q]
                conArgs :: [m q]
conArgs = (forall d. Data d => d -> m q) -> a -> [m q]
forall a u. Data a => (forall d. Data d => d -> u) -> a -> [u]
forall u. (forall d. Data d => d -> u) -> a -> [u]
gmapQ ((Name -> k)
-> (Lit -> m q)
-> (k -> [m q] -> m q)
-> (forall b. Data b => b -> Maybe (m q))
-> d
-> m q
forall (m :: * -> *) a k q.
(Quote m, Data a) =>
(Name -> k)
-> (Lit -> m q)
-> (k -> [m q] -> m q)
-> (forall b. Data b => b -> Maybe (m q))
-> a
-> m q
dataToQa Name -> k
mkCon Lit -> m q
mkLit k -> [m q] -> m q
appCon b -> Maybe (m q)
forall b. Data b => b -> Maybe (m q)
antiQ) a
t
            IntConstr Uniq
n ->
                Lit -> m q
mkLit (Lit -> m q) -> Lit -> m q
forall a b. (a -> b) -> a -> b
$ Uniq -> Lit
IntegerL Uniq
n
            FloatConstr Rational
n ->
                Lit -> m q
mkLit (Lit -> m q) -> Lit -> m q
forall a b. (a -> b) -> a -> b
$ Rational -> Lit
RationalL Rational
n
            CharConstr Char
c ->
                Lit -> m q
mkLit (Lit -> m q) -> Lit -> m q
forall a b. (a -> b) -> a -> b
$ Char -> Lit
CharL Char
c
        where
          constr :: Constr
          constr :: Constr
constr = a -> Constr
forall a. Data a => a -> Constr
toConstr a
t

      Just m q
y -> m q
y


{- Note [Data for non-algebraic types]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Class Data was originally intended for algebraic data types.  But
it is possible to use it for abstract types too.  For example, in
package `text` we find

  instance Data Text where
    ...
    toConstr _ = packConstr

  packConstr :: Constr
  packConstr = mkConstr textDataType "pack" [] Prefix

Here `packConstr` isn't a real data constructor, it's an ordinary
function.  Two complications

* In such a case, we must take care to build the Name using
  mkNameG_v (for values), not mkNameG_d (for data constructors).
  See #10796.

* The pseudo-constructor is named only by its string, here "pack".
  But 'dataToQa' needs the TyCon of its defining module, and has
  to assume it's defined in the same module as the TyCon itself.
  But nothing enforces that; #12596 shows what goes wrong if
  "pack" is defined in a different module than the data type "Text".
  -}

-- | 'dataToExpQ' converts a value to a 'Exp' representation of the
-- same value, in the SYB style. It is generalized to take a function
-- override type-specific cases; see 'liftData' for a more commonly
-- used variant.
dataToExpQ  ::  (Quote m, Data a)
            =>  (forall b . Data b => b -> Maybe (m Exp))
            ->  a
            ->  m Exp
dataToExpQ :: forall (m :: * -> *) a.
(Quote m, Data a) =>
(forall b. Data b => b -> Maybe (m Exp)) -> a -> m Exp
dataToExpQ = (Name -> m Exp)
-> (Lit -> m Exp)
-> (m Exp -> [m Exp] -> m Exp)
-> (forall b. Data b => b -> Maybe (m Exp))
-> a
-> m Exp
forall (m :: * -> *) a k q.
(Quote m, Data a) =>
(Name -> k)
-> (Lit -> m q)
-> (k -> [m q] -> m q)
-> (forall b. Data b => b -> Maybe (m q))
-> a
-> m q
dataToQa Name -> m Exp
forall {m :: * -> *}. Monad m => Name -> m Exp
varOrConE Lit -> m Exp
forall {m :: * -> *}. Monad m => Lit -> m Exp
litE ((m Exp -> m Exp -> m Exp) -> m Exp -> [m Exp] -> m Exp
forall b a. (b -> a -> b) -> b -> [a] -> b
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl m Exp -> m Exp -> m Exp
forall {m :: * -> *}. Monad m => m Exp -> m Exp -> m Exp
appE)
    where
          -- Make sure that VarE is used if the Constr value relies on a
          -- function underneath the surface (instead of a constructor).
          -- See #10796.
          varOrConE :: Name -> m Exp
varOrConE Name
s =
            case Name -> Maybe NameSpace
nameSpace Name
s of
                 Just NameSpace
VarName  -> Exp -> m Exp
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Name -> Exp
VarE Name
s)
                 Just NameSpace
DataName -> Exp -> m Exp
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Name -> Exp
ConE Name
s)
                 Maybe NameSpace
_ -> FilePath -> m Exp
forall a. HasCallStack => FilePath -> a
error (FilePath -> m Exp) -> FilePath -> m Exp
forall a b. (a -> b) -> a -> b
$ FilePath
"Can't construct an expression from name "
                           FilePath -> FilePath -> FilePath
forall a. [a] -> [a] -> [a]
++ Name -> FilePath
showName Name
s
          appE :: m Exp -> m Exp -> m Exp
appE m Exp
x m Exp
y = do { Exp
a <- m Exp
x; Exp
b <- m Exp
y; Exp -> m Exp
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Exp -> Exp -> Exp
AppE Exp
a Exp
b)}
          litE :: Lit -> m Exp
litE Lit
c = Exp -> m Exp
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Lit -> Exp
LitE Lit
c)

-- | 'liftData' is a variant of 'lift' in the 'Lift' type class which
-- works for any type with a 'Data' instance.
liftData :: (Quote m, Data a) => a -> m Exp
liftData :: forall (m :: * -> *) a. (Quote m, Data a) => a -> m Exp
liftData = (forall b. Data b => b -> Maybe (m Exp)) -> a -> m Exp
forall (m :: * -> *) a.
(Quote m, Data a) =>
(forall b. Data b => b -> Maybe (m Exp)) -> a -> m Exp
dataToExpQ (Maybe (m Exp) -> b -> Maybe (m Exp)
forall a b. a -> b -> a
const Maybe (m Exp)
forall a. Maybe a
Nothing)

-- | 'dataToPatQ' converts a value to a 'Pat' representation of the same
-- value, in the SYB style. It takes a function to handle type-specific cases,
-- alternatively, pass @const Nothing@ to get default behavior.
dataToPatQ  ::  (Quote m, Data a)
            =>  (forall b . Data b => b -> Maybe (m Pat))
            ->  a
            ->  m Pat
dataToPatQ :: forall (m :: * -> *) a.
(Quote m, Data a) =>
(forall b. Data b => b -> Maybe (m Pat)) -> a -> m Pat
dataToPatQ = (Name -> Name)
-> (Lit -> m Pat)
-> (Name -> [m Pat] -> m Pat)
-> (forall b. Data b => b -> Maybe (m Pat))
-> a
-> m Pat
forall (m :: * -> *) a k q.
(Quote m, Data a) =>
(Name -> k)
-> (Lit -> m q)
-> (k -> [m q] -> m q)
-> (forall b. Data b => b -> Maybe (m q))
-> a
-> m q
dataToQa Name -> Name
forall a. a -> a
id Lit -> m Pat
forall {m :: * -> *}. Monad m => Lit -> m Pat
litP Name -> [m Pat] -> m Pat
forall {m :: * -> *}. Monad m => Name -> [m Pat] -> m Pat
conP
    where litP :: Lit -> m Pat
litP Lit
l = Pat -> m Pat
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Lit -> Pat
LitP Lit
l)
          conP :: Name -> [m Pat] -> m Pat
conP Name
n [m Pat]
ps =
            case Name -> Maybe NameSpace
nameSpace Name
n of
                Just NameSpace
DataName -> do
                    [Pat]
ps' <- [m Pat] -> m [Pat]
forall (t :: * -> *) (m :: * -> *) a.
(Traversable t, Monad m) =>
t (m a) -> m (t a)
forall (m :: * -> *) a. Monad m => [m a] -> m [a]
sequence [m Pat]
ps
                    Pat -> m Pat
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Name -> [Type] -> [Pat] -> Pat
ConP Name
n [] [Pat]
ps')
                Maybe NameSpace
_ -> FilePath -> m Pat
forall a. HasCallStack => FilePath -> a
error (FilePath -> m Pat) -> FilePath -> m Pat
forall a b. (a -> b) -> a -> b
$ FilePath
"Can't construct a pattern from name "
                          FilePath -> FilePath -> FilePath
forall a. [a] -> [a] -> [a]
++ Name -> FilePath
showName Name
n

-----------------------------------------------------
--              Names and uniques
-----------------------------------------------------

newtype ModName = ModName String        -- Module name
 deriving (Int -> ModName -> FilePath -> FilePath
[ModName] -> FilePath -> FilePath
ModName -> FilePath
(Int -> ModName -> FilePath -> FilePath)
-> (ModName -> FilePath)
-> ([ModName] -> FilePath -> FilePath)
-> Show ModName
forall a.
(Int -> a -> FilePath -> FilePath)
-> (a -> FilePath) -> ([a] -> FilePath -> FilePath) -> Show a
$cshowsPrec :: Int -> ModName -> FilePath -> FilePath
showsPrec :: Int -> ModName -> FilePath -> FilePath
$cshow :: ModName -> FilePath
show :: ModName -> FilePath
$cshowList :: [ModName] -> FilePath -> FilePath
showList :: [ModName] -> FilePath -> FilePath
Show,ModName -> ModName -> Bool
(ModName -> ModName -> Bool)
-> (ModName -> ModName -> Bool) -> Eq ModName
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ModName -> ModName -> Bool
== :: ModName -> ModName -> Bool
$c/= :: ModName -> ModName -> Bool
/= :: ModName -> ModName -> Bool
Eq,Eq ModName
Eq ModName
-> (ModName -> ModName -> Ordering)
-> (ModName -> ModName -> Bool)
-> (ModName -> ModName -> Bool)
-> (ModName -> ModName -> Bool)
-> (ModName -> ModName -> Bool)
-> (ModName -> ModName -> ModName)
-> (ModName -> ModName -> ModName)
-> Ord ModName
ModName -> ModName -> Bool
ModName -> ModName -> Ordering
ModName -> ModName -> ModName
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: ModName -> ModName -> Ordering
compare :: ModName -> ModName -> Ordering
$c< :: ModName -> ModName -> Bool
< :: ModName -> ModName -> Bool
$c<= :: ModName -> ModName -> Bool
<= :: ModName -> ModName -> Bool
$c> :: ModName -> ModName -> Bool
> :: ModName -> ModName -> Bool
$c>= :: ModName -> ModName -> Bool
>= :: ModName -> ModName -> Bool
$cmax :: ModName -> ModName -> ModName
max :: ModName -> ModName -> ModName
$cmin :: ModName -> ModName -> ModName
min :: ModName -> ModName -> ModName
Ord,Typeable ModName
Typeable ModName
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> ModName -> c ModName)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c ModName)
-> (ModName -> Constr)
-> (ModName -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c ModName))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c ModName))
-> ((forall b. Data b => b -> b) -> ModName -> ModName)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> ModName -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> ModName -> r)
-> (forall u. (forall d. Data d => d -> u) -> ModName -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> ModName -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> ModName -> m ModName)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> ModName -> m ModName)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> ModName -> m ModName)
-> Data ModName
ModName -> Constr
ModName -> DataType
(forall b. Data b => b -> b) -> ModName -> ModName
forall a.
Typeable a
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> ModName -> u
forall u. (forall d. Data d => d -> u) -> ModName -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> ModName -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> ModName -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> ModName -> m ModName
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> ModName -> m ModName
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c ModName
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> ModName -> c ModName
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c ModName)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c ModName)
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> ModName -> c ModName
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> ModName -> c ModName
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c ModName
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c ModName
$ctoConstr :: ModName -> Constr
toConstr :: ModName -> Constr
$cdataTypeOf :: ModName -> DataType
dataTypeOf :: ModName -> DataType
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c ModName)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c ModName)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c ModName)
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c ModName)
$cgmapT :: (forall b. Data b => b -> b) -> ModName -> ModName
gmapT :: (forall b. Data b => b -> b) -> ModName -> ModName
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> ModName -> r
gmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> ModName -> r
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> ModName -> r
gmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> ModName -> r
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> ModName -> [u]
gmapQ :: forall u. (forall d. Data d => d -> u) -> ModName -> [u]
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> ModName -> u
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> ModName -> u
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> ModName -> m ModName
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> ModName -> m ModName
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> ModName -> m ModName
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> ModName -> m ModName
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> ModName -> m ModName
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> ModName -> m ModName
Data,(forall x. ModName -> Rep ModName x)
-> (forall x. Rep ModName x -> ModName) -> Generic ModName
forall x. Rep ModName x -> ModName
forall x. ModName -> Rep ModName x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. ModName -> Rep ModName x
$cto :: forall x. Rep ModName x -> ModName
Generic)

newtype PkgName = PkgName String        -- package name
 deriving (Int -> PkgName -> FilePath -> FilePath
[PkgName] -> FilePath -> FilePath
PkgName -> FilePath
(Int -> PkgName -> FilePath -> FilePath)
-> (PkgName -> FilePath)
-> ([PkgName] -> FilePath -> FilePath)
-> Show PkgName
forall a.
(Int -> a -> FilePath -> FilePath)
-> (a -> FilePath) -> ([a] -> FilePath -> FilePath) -> Show a
$cshowsPrec :: Int -> PkgName -> FilePath -> FilePath
showsPrec :: Int -> PkgName -> FilePath -> FilePath
$cshow :: PkgName -> FilePath
show :: PkgName -> FilePath
$cshowList :: [PkgName] -> FilePath -> FilePath
showList :: [PkgName] -> FilePath -> FilePath
Show,PkgName -> PkgName -> Bool
(PkgName -> PkgName -> Bool)
-> (PkgName -> PkgName -> Bool) -> Eq PkgName
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: PkgName -> PkgName -> Bool
== :: PkgName -> PkgName -> Bool
$c/= :: PkgName -> PkgName -> Bool
/= :: PkgName -> PkgName -> Bool
Eq,Eq PkgName
Eq PkgName
-> (PkgName -> PkgName -> Ordering)
-> (PkgName -> PkgName -> Bool)
-> (PkgName -> PkgName -> Bool)
-> (PkgName -> PkgName -> Bool)
-> (PkgName -> PkgName -> Bool)
-> (PkgName -> PkgName -> PkgName)
-> (PkgName -> PkgName -> PkgName)
-> Ord PkgName
PkgName -> PkgName -> Bool
PkgName -> PkgName -> Ordering
PkgName -> PkgName -> PkgName
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: PkgName -> PkgName -> Ordering
compare :: PkgName -> PkgName -> Ordering
$c< :: PkgName -> PkgName -> Bool
< :: PkgName -> PkgName -> Bool
$c<= :: PkgName -> PkgName -> Bool
<= :: PkgName -> PkgName -> Bool
$c> :: PkgName -> PkgName -> Bool
> :: PkgName -> PkgName -> Bool
$c>= :: PkgName -> PkgName -> Bool
>= :: PkgName -> PkgName -> Bool
$cmax :: PkgName -> PkgName -> PkgName
max :: PkgName -> PkgName -> PkgName
$cmin :: PkgName -> PkgName -> PkgName
min :: PkgName -> PkgName -> PkgName
Ord,Typeable PkgName
Typeable PkgName
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> PkgName -> c PkgName)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c PkgName)
-> (PkgName -> Constr)
-> (PkgName -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c PkgName))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c PkgName))
-> ((forall b. Data b => b -> b) -> PkgName -> PkgName)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> PkgName -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> PkgName -> r)
-> (forall u. (forall d. Data d => d -> u) -> PkgName -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> PkgName -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> PkgName -> m PkgName)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> PkgName -> m PkgName)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> PkgName -> m PkgName)
-> Data PkgName
PkgName -> Constr
PkgName -> DataType
(forall b. Data b => b -> b) -> PkgName -> PkgName
forall a.
Typeable a
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> PkgName -> u
forall u. (forall d. Data d => d -> u) -> PkgName -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> PkgName -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> PkgName -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> PkgName -> m PkgName
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> PkgName -> m PkgName
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c PkgName
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> PkgName -> c PkgName
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c PkgName)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c PkgName)
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> PkgName -> c PkgName
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> PkgName -> c PkgName
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c PkgName
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c PkgName
$ctoConstr :: PkgName -> Constr
toConstr :: PkgName -> Constr
$cdataTypeOf :: PkgName -> DataType
dataTypeOf :: PkgName -> DataType
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c PkgName)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c PkgName)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c PkgName)
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c PkgName)
$cgmapT :: (forall b. Data b => b -> b) -> PkgName -> PkgName
gmapT :: (forall b. Data b => b -> b) -> PkgName -> PkgName
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> PkgName -> r
gmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> PkgName -> r
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> PkgName -> r
gmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> PkgName -> r
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> PkgName -> [u]
gmapQ :: forall u. (forall d. Data d => d -> u) -> PkgName -> [u]
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> PkgName -> u
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> PkgName -> u
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> PkgName -> m PkgName
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> PkgName -> m PkgName
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> PkgName -> m PkgName
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> PkgName -> m PkgName
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> PkgName -> m PkgName
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> PkgName -> m PkgName
Data,(forall x. PkgName -> Rep PkgName x)
-> (forall x. Rep PkgName x -> PkgName) -> Generic PkgName
forall x. Rep PkgName x -> PkgName
forall x. PkgName -> Rep PkgName x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. PkgName -> Rep PkgName x
$cto :: forall x. Rep PkgName x -> PkgName
Generic)

-- | Obtained from 'reifyModule' and 'Language.Haskell.TH.Lib.thisModule'.
data Module = Module PkgName ModName -- package qualified module name
 deriving (Int -> Module -> FilePath -> FilePath
[Module] -> FilePath -> FilePath
Module -> FilePath
(Int -> Module -> FilePath -> FilePath)
-> (Module -> FilePath)
-> ([Module] -> FilePath -> FilePath)
-> Show Module
forall a.
(Int -> a -> FilePath -> FilePath)
-> (a -> FilePath) -> ([a] -> FilePath -> FilePath) -> Show a
$cshowsPrec :: Int -> Module -> FilePath -> FilePath
showsPrec :: Int -> Module -> FilePath -> FilePath
$cshow :: Module -> FilePath
show :: Module -> FilePath
$cshowList :: [Module] -> FilePath -> FilePath
showList :: [Module] -> FilePath -> FilePath
Show,Module -> Module -> Bool
(Module -> Module -> Bool)
-> (Module -> Module -> Bool) -> Eq Module
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Module -> Module -> Bool
== :: Module -> Module -> Bool
$c/= :: Module -> Module -> Bool
/= :: Module -> Module -> Bool
Eq,Eq Module
Eq Module
-> (Module -> Module -> Ordering)
-> (Module -> Module -> Bool)
-> (Module -> Module -> Bool)
-> (Module -> Module -> Bool)
-> (Module -> Module -> Bool)
-> (Module -> Module -> Module)
-> (Module -> Module -> Module)
-> Ord Module
Module -> Module -> Bool
Module -> Module -> Ordering
Module -> Module -> Module
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: Module -> Module -> Ordering
compare :: Module -> Module -> Ordering
$c< :: Module -> Module -> Bool
< :: Module -> Module -> Bool
$c<= :: Module -> Module -> Bool
<= :: Module -> Module -> Bool
$c> :: Module -> Module -> Bool
> :: Module -> Module -> Bool
$c>= :: Module -> Module -> Bool
>= :: Module -> Module -> Bool
$cmax :: Module -> Module -> Module
max :: Module -> Module -> Module
$cmin :: Module -> Module -> Module
min :: Module -> Module -> Module
Ord,Typeable Module
Typeable Module
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> Module -> c Module)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c Module)
-> (Module -> Constr)
-> (Module -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c Module))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Module))
-> ((forall b. Data b => b -> b) -> Module -> Module)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> Module -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> Module -> r)
-> (forall u. (forall d. Data d => d -> u) -> Module -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> Module -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> Module -> m Module)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> Module -> m Module)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> Module -> m Module)
-> Data Module
Module -> Constr
Module -> DataType
(forall b. Data b => b -> b) -> Module -> Module
forall a.
Typeable a
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> Module -> u
forall u. (forall d. Data d => d -> u) -> Module -> [u]
forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Module -> r
forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Module -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Module -> m Module
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Module -> m Module
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Module
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Module -> c Module
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c Module)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Module)
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Module -> c Module
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Module -> c Module
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Module
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Module
$ctoConstr :: Module -> Constr
toConstr :: Module -> Constr
$cdataTypeOf :: Module -> DataType
dataTypeOf :: Module -> DataType
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c Module)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c Module)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Module)
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Module)
$cgmapT :: (forall b. Data b => b -> b) -> Module -> Module
gmapT :: (forall b. Data b => b -> b) -> Module -> Module
$cgmapQl :: forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Module -> r
gmapQl :: forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Module -> r
$cgmapQr :: forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Module -> r
gmapQr :: forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Module -> r
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> Module -> [u]
gmapQ :: forall u. (forall d. Data d => d -> u) -> Module -> [u]
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> Module -> u
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> Module -> u
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Module -> m Module
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Module -> m Module
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Module -> m Module
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Module -> m Module
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Module -> m Module
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Module -> m Module
Data,(forall x. Module -> Rep Module x)
-> (forall x. Rep Module x -> Module) -> Generic Module
forall x. Rep Module x -> Module
forall x. Module -> Rep Module x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. Module -> Rep Module x
$cto :: forall x. Rep Module x -> Module
Generic)

newtype OccName = OccName String
 deriving (Int -> OccName -> FilePath -> FilePath
[OccName] -> FilePath -> FilePath
OccName -> FilePath
(Int -> OccName -> FilePath -> FilePath)
-> (OccName -> FilePath)
-> ([OccName] -> FilePath -> FilePath)
-> Show OccName
forall a.
(Int -> a -> FilePath -> FilePath)
-> (a -> FilePath) -> ([a] -> FilePath -> FilePath) -> Show a
$cshowsPrec :: Int -> OccName -> FilePath -> FilePath
showsPrec :: Int -> OccName -> FilePath -> FilePath
$cshow :: OccName -> FilePath
show :: OccName -> FilePath
$cshowList :: [OccName] -> FilePath -> FilePath
showList :: [OccName] -> FilePath -> FilePath
Show,OccName -> OccName -> Bool
(OccName -> OccName -> Bool)
-> (OccName -> OccName -> Bool) -> Eq OccName
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: OccName -> OccName -> Bool
== :: OccName -> OccName -> Bool
$c/= :: OccName -> OccName -> Bool
/= :: OccName -> OccName -> Bool
Eq,Eq OccName
Eq OccName
-> (OccName -> OccName -> Ordering)
-> (OccName -> OccName -> Bool)
-> (OccName -> OccName -> Bool)
-> (OccName -> OccName -> Bool)
-> (OccName -> OccName -> Bool)
-> (OccName -> OccName -> OccName)
-> (OccName -> OccName -> OccName)
-> Ord OccName
OccName -> OccName -> Bool
OccName -> OccName -> Ordering
OccName -> OccName -> OccName
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: OccName -> OccName -> Ordering
compare :: OccName -> OccName -> Ordering
$c< :: OccName -> OccName -> Bool
< :: OccName -> OccName -> Bool
$c<= :: OccName -> OccName -> Bool
<= :: OccName -> OccName -> Bool
$c> :: OccName -> OccName -> Bool
> :: OccName -> OccName -> Bool
$c>= :: OccName -> OccName -> Bool
>= :: OccName -> OccName -> Bool
$cmax :: OccName -> OccName -> OccName
max :: OccName -> OccName -> OccName
$cmin :: OccName -> OccName -> OccName
min :: OccName -> OccName -> OccName
Ord,Typeable OccName
Typeable OccName
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> OccName -> c OccName)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c OccName)
-> (OccName -> Constr)
-> (OccName -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c OccName))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c OccName))
-> ((forall b. Data b => b -> b) -> OccName -> OccName)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> OccName -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> OccName -> r)
-> (forall u. (forall d. Data d => d -> u) -> OccName -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> OccName -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> OccName -> m OccName)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> OccName -> m OccName)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> OccName -> m OccName)
-> Data OccName
OccName -> Constr
OccName -> DataType
(forall b. Data b => b -> b) -> OccName -> OccName
forall a.
Typeable a
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> OccName -> u
forall u. (forall d. Data d => d -> u) -> OccName -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> OccName -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> OccName -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> OccName -> m OccName
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> OccName -> m OccName
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c OccName
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> OccName -> c OccName
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c OccName)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c OccName)
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> OccName -> c OccName
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> OccName -> c OccName
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c OccName
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c OccName
$ctoConstr :: OccName -> Constr
toConstr :: OccName -> Constr
$cdataTypeOf :: OccName -> DataType
dataTypeOf :: OccName -> DataType
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c OccName)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c OccName)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c OccName)
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c OccName)
$cgmapT :: (forall b. Data b => b -> b) -> OccName -> OccName
gmapT :: (forall b. Data b => b -> b) -> OccName -> OccName
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> OccName -> r
gmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> OccName -> r
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> OccName -> r
gmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> OccName -> r
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> OccName -> [u]
gmapQ :: forall u. (forall d. Data d => d -> u) -> OccName -> [u]
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> OccName -> u
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> OccName -> u
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> OccName -> m OccName
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> OccName -> m OccName
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> OccName -> m OccName
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> OccName -> m OccName
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> OccName -> m OccName
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> OccName -> m OccName
Data,(forall x. OccName -> Rep OccName x)
-> (forall x. Rep OccName x -> OccName) -> Generic OccName
forall x. Rep OccName x -> OccName
forall x. OccName -> Rep OccName x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. OccName -> Rep OccName x
$cto :: forall x. Rep OccName x -> OccName
Generic)

mkModName :: String -> ModName
mkModName :: FilePath -> ModName
mkModName FilePath
s = FilePath -> ModName
ModName FilePath
s

modString :: ModName -> String
modString :: ModName -> FilePath
modString (ModName FilePath
m) = FilePath
m


mkPkgName :: String -> PkgName
mkPkgName :: FilePath -> PkgName
mkPkgName FilePath
s = FilePath -> PkgName
PkgName FilePath
s

pkgString :: PkgName -> String
pkgString :: PkgName -> FilePath
pkgString (PkgName FilePath
m) = FilePath
m


-----------------------------------------------------
--              OccName
-----------------------------------------------------

mkOccName :: String -> OccName
mkOccName :: FilePath -> OccName
mkOccName FilePath
s = FilePath -> OccName
OccName FilePath
s

occString :: OccName -> String
occString :: OccName -> FilePath
occString (OccName FilePath
occ) = FilePath
occ


-----------------------------------------------------
--               Names
-----------------------------------------------------
--
-- For "global" names ('NameG') we need a totally unique name,
-- so we must include the name-space of the thing
--
-- For unique-numbered things ('NameU'), we've got a unique reference
-- anyway, so no need for name space
--
-- For dynamically bound thing ('NameS') we probably want them to
-- in a context-dependent way, so again we don't want the name
-- space.  For example:
--
-- > let v = mkName "T" in [| data $v = $v |]
--
-- Here we use the same Name for both type constructor and data constructor
--
--
-- NameL and NameG are bound *outside* the TH syntax tree
-- either globally (NameG) or locally (NameL). Ex:
--
-- > f x = $(h [| (map, x) |])
--
-- The 'map' will be a NameG, and 'x' wil be a NameL
--
-- These Names should never appear in a binding position in a TH syntax tree

{- $namecapture #namecapture#
Much of 'Name' API is concerned with the problem of /name capture/, which
can be seen in the following example.

> f expr = [| let x = 0 in $expr |]
> ...
> g x = $( f [| x |] )
> h y = $( f [| y |] )

A naive desugaring of this would yield:

> g x = let x = 0 in x
> h y = let x = 0 in y

All of a sudden, @g@ and @h@ have different meanings! In this case,
we say that the @x@ in the RHS of @g@ has been /captured/
by the binding of @x@ in @f@.

What we actually want is for the @x@ in @f@ to be distinct from the
@x@ in @g@, so we get the following desugaring:

> g x = let x' = 0 in x
> h y = let x' = 0 in y

which avoids name capture as desired.

In the general case, we say that a @Name@ can be captured if
the thing it refers to can be changed by adding new declarations.
-}

{- |
An abstract type representing names in the syntax tree.

'Name's can be constructed in several ways, which come with different
name-capture guarantees (see "Language.Haskell.TH.Syntax#namecapture" for
an explanation of name capture):

  * the built-in syntax @'f@ and @''T@ can be used to construct names,
    The expression @'f@ gives a @Name@ which refers to the value @f@
    currently in scope, and @''T@ gives a @Name@ which refers to the
    type @T@ currently in scope. These names can never be captured.

  * 'lookupValueName' and 'lookupTypeName' are similar to @'f@ and
     @''T@ respectively, but the @Name@s are looked up at the point
     where the current splice is being run. These names can never be
     captured.

  * 'newName' monadically generates a new name, which can never
     be captured.

  * 'mkName' generates a capturable name.

Names constructed using @newName@ and @mkName@ may be used in bindings
(such as @let x = ...@ or @\x -> ...@), but names constructed using
@lookupValueName@, @lookupTypeName@, @'f@, @''T@ may not.
-}
data Name = Name OccName NameFlavour deriving (Typeable Name
Typeable Name
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> Name -> c Name)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c Name)
-> (Name -> Constr)
-> (Name -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c Name))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Name))
-> ((forall b. Data b => b -> b) -> Name -> Name)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Name -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Name -> r)
-> (forall u. (forall d. Data d => d -> u) -> Name -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> Name -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> Name -> m Name)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> Name -> m Name)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> Name -> m Name)
-> Data Name
Name -> Constr
Name -> DataType
(forall b. Data b => b -> b) -> Name -> Name
forall a.
Typeable a
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> Name -> u
forall u. (forall d. Data d => d -> u) -> Name -> [u]
forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Name -> r
forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Name -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Name -> m Name
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Name -> m Name
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Name
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Name -> c Name
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c Name)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Name)
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Name -> c Name
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Name -> c Name
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Name
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Name
$ctoConstr :: Name -> Constr
toConstr :: Name -> Constr
$cdataTypeOf :: Name -> DataType
dataTypeOf :: Name -> DataType
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c Name)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c Name)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Name)
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Name)
$cgmapT :: (forall b. Data b => b -> b) -> Name -> Name
gmapT :: (forall b. Data b => b -> b) -> Name -> Name
$cgmapQl :: forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Name -> r
gmapQl :: forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Name -> r
$cgmapQr :: forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Name -> r
gmapQr :: forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Name -> r
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> Name -> [u]
gmapQ :: forall u. (forall d. Data d => d -> u) -> Name -> [u]
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> Name -> u
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> Name -> u
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Name -> m Name
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Name -> m Name
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Name -> m Name
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Name -> m Name
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Name -> m Name
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Name -> m Name
Data, Name -> Name -> Bool
(Name -> Name -> Bool) -> (Name -> Name -> Bool) -> Eq Name
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Name -> Name -> Bool
== :: Name -> Name -> Bool
$c/= :: Name -> Name -> Bool
/= :: Name -> Name -> Bool
Eq, (forall x. Name -> Rep Name x)
-> (forall x. Rep Name x -> Name) -> Generic Name
forall x. Rep Name x -> Name
forall x. Name -> Rep Name x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. Name -> Rep Name x
$cto :: forall x. Rep Name x -> Name
Generic)

instance Ord Name where
    -- check if unique is different before looking at strings
  (Name OccName
o1 NameFlavour
f1) compare :: Name -> Name -> Ordering
`compare` (Name OccName
o2 NameFlavour
f2) = (NameFlavour
f1 NameFlavour -> NameFlavour -> Ordering
forall a. Ord a => a -> a -> Ordering
`compare` NameFlavour
f2)   Ordering -> Ordering -> Ordering
`thenCmp`
                                        (OccName
o1 OccName -> OccName -> Ordering
forall a. Ord a => a -> a -> Ordering
`compare` OccName
o2)

data NameFlavour
  = NameS           -- ^ An unqualified name; dynamically bound
  | NameQ ModName   -- ^ A qualified name; dynamically bound
  | NameU !Uniq     -- ^ A unique local name
  | NameL !Uniq     -- ^ Local name bound outside of the TH AST
  | NameG NameSpace PkgName ModName -- ^ Global name bound outside of the TH AST:
                -- An original name (occurrences only, not binders)
                -- Need the namespace too to be sure which
                -- thing we are naming
  deriving ( Typeable NameFlavour
Typeable NameFlavour
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> NameFlavour -> c NameFlavour)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c NameFlavour)
-> (NameFlavour -> Constr)
-> (NameFlavour -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c NameFlavour))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e))
    -> Maybe (c NameFlavour))
-> ((forall b. Data b => b -> b) -> NameFlavour -> NameFlavour)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> NameFlavour -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> NameFlavour -> r)
-> (forall u. (forall d. Data d => d -> u) -> NameFlavour -> [u])
-> (forall u.
    Int -> (forall d. Data d => d -> u) -> NameFlavour -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> NameFlavour -> m NameFlavour)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> NameFlavour -> m NameFlavour)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> NameFlavour -> m NameFlavour)
-> Data NameFlavour
NameFlavour -> Constr
NameFlavour -> DataType
(forall b. Data b => b -> b) -> NameFlavour -> NameFlavour
forall a.
Typeable a
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> NameFlavour -> u
forall u. (forall d. Data d => d -> u) -> NameFlavour -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> NameFlavour -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> NameFlavour -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> NameFlavour -> m NameFlavour
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> NameFlavour -> m NameFlavour
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c NameFlavour
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> NameFlavour -> c NameFlavour
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c NameFlavour)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c NameFlavour)
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> NameFlavour -> c NameFlavour
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> NameFlavour -> c NameFlavour
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c NameFlavour
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c NameFlavour
$ctoConstr :: NameFlavour -> Constr
toConstr :: NameFlavour -> Constr
$cdataTypeOf :: NameFlavour -> DataType
dataTypeOf :: NameFlavour -> DataType
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c NameFlavour)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c NameFlavour)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c NameFlavour)
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c NameFlavour)
$cgmapT :: (forall b. Data b => b -> b) -> NameFlavour -> NameFlavour
gmapT :: (forall b. Data b => b -> b) -> NameFlavour -> NameFlavour
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> NameFlavour -> r
gmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> NameFlavour -> r
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> NameFlavour -> r
gmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> NameFlavour -> r
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> NameFlavour -> [u]
gmapQ :: forall u. (forall d. Data d => d -> u) -> NameFlavour -> [u]
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> NameFlavour -> u
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> NameFlavour -> u
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> NameFlavour -> m NameFlavour
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> NameFlavour -> m NameFlavour
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> NameFlavour -> m NameFlavour
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> NameFlavour -> m NameFlavour
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> NameFlavour -> m NameFlavour
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> NameFlavour -> m NameFlavour
Data, NameFlavour -> NameFlavour -> Bool
(NameFlavour -> NameFlavour -> Bool)
-> (NameFlavour -> NameFlavour -> Bool) -> Eq NameFlavour
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: NameFlavour -> NameFlavour -> Bool
== :: NameFlavour -> NameFlavour -> Bool
$c/= :: NameFlavour -> NameFlavour -> Bool
/= :: NameFlavour -> NameFlavour -> Bool
Eq, Eq NameFlavour
Eq NameFlavour
-> (NameFlavour -> NameFlavour -> Ordering)
-> (NameFlavour -> NameFlavour -> Bool)
-> (NameFlavour -> NameFlavour -> Bool)
-> (NameFlavour -> NameFlavour -> Bool)
-> (NameFlavour -> NameFlavour -> Bool)
-> (NameFlavour -> NameFlavour -> NameFlavour)
-> (NameFlavour -> NameFlavour -> NameFlavour)
-> Ord NameFlavour
NameFlavour -> NameFlavour -> Bool
NameFlavour -> NameFlavour -> Ordering
NameFlavour -> NameFlavour -> NameFlavour
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: NameFlavour -> NameFlavour -> Ordering
compare :: NameFlavour -> NameFlavour -> Ordering
$c< :: NameFlavour -> NameFlavour -> Bool
< :: NameFlavour -> NameFlavour -> Bool
$c<= :: NameFlavour -> NameFlavour -> Bool
<= :: NameFlavour -> NameFlavour -> Bool
$c> :: NameFlavour -> NameFlavour -> Bool
> :: NameFlavour -> NameFlavour -> Bool
$c>= :: NameFlavour -> NameFlavour -> Bool
>= :: NameFlavour -> NameFlavour -> Bool
$cmax :: NameFlavour -> NameFlavour -> NameFlavour
max :: NameFlavour -> NameFlavour -> NameFlavour
$cmin :: NameFlavour -> NameFlavour -> NameFlavour
min :: NameFlavour -> NameFlavour -> NameFlavour
Ord, Int -> NameFlavour -> FilePath -> FilePath
[NameFlavour] -> FilePath -> FilePath
NameFlavour -> FilePath
(Int -> NameFlavour -> FilePath -> FilePath)
-> (NameFlavour -> FilePath)
-> ([NameFlavour] -> FilePath -> FilePath)
-> Show NameFlavour
forall a.
(Int -> a -> FilePath -> FilePath)
-> (a -> FilePath) -> ([a] -> FilePath -> FilePath) -> Show a
$cshowsPrec :: Int -> NameFlavour -> FilePath -> FilePath
showsPrec :: Int -> NameFlavour -> FilePath -> FilePath
$cshow :: NameFlavour -> FilePath
show :: NameFlavour -> FilePath
$cshowList :: [NameFlavour] -> FilePath -> FilePath
showList :: [NameFlavour] -> FilePath -> FilePath
Show, (forall x. NameFlavour -> Rep NameFlavour x)
-> (forall x. Rep NameFlavour x -> NameFlavour)
-> Generic NameFlavour
forall x. Rep NameFlavour x -> NameFlavour
forall x. NameFlavour -> Rep NameFlavour x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. NameFlavour -> Rep NameFlavour x
$cto :: forall x. Rep NameFlavour x -> NameFlavour
Generic )

data NameSpace = VarName        -- ^ Variables
               | DataName       -- ^ Data constructors
               | TcClsName      -- ^ Type constructors and classes; Haskell has them
                                -- in the same name space for now.
               deriving( NameSpace -> NameSpace -> Bool
(NameSpace -> NameSpace -> Bool)
-> (NameSpace -> NameSpace -> Bool) -> Eq NameSpace
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: NameSpace -> NameSpace -> Bool
== :: NameSpace -> NameSpace -> Bool
$c/= :: NameSpace -> NameSpace -> Bool
/= :: NameSpace -> NameSpace -> Bool
Eq, Eq NameSpace
Eq NameSpace
-> (NameSpace -> NameSpace -> Ordering)
-> (NameSpace -> NameSpace -> Bool)
-> (NameSpace -> NameSpace -> Bool)
-> (NameSpace -> NameSpace -> Bool)
-> (NameSpace -> NameSpace -> Bool)
-> (NameSpace -> NameSpace -> NameSpace)
-> (NameSpace -> NameSpace -> NameSpace)
-> Ord NameSpace
NameSpace -> NameSpace -> Bool
NameSpace -> NameSpace -> Ordering
NameSpace -> NameSpace -> NameSpace
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: NameSpace -> NameSpace -> Ordering
compare :: NameSpace -> NameSpace -> Ordering
$c< :: NameSpace -> NameSpace -> Bool
< :: NameSpace -> NameSpace -> Bool
$c<= :: NameSpace -> NameSpace -> Bool
<= :: NameSpace -> NameSpace -> Bool
$c> :: NameSpace -> NameSpace -> Bool
> :: NameSpace -> NameSpace -> Bool
$c>= :: NameSpace -> NameSpace -> Bool
>= :: NameSpace -> NameSpace -> Bool
$cmax :: NameSpace -> NameSpace -> NameSpace
max :: NameSpace -> NameSpace -> NameSpace
$cmin :: NameSpace -> NameSpace -> NameSpace
min :: NameSpace -> NameSpace -> NameSpace
Ord, Int -> NameSpace -> FilePath -> FilePath
[NameSpace] -> FilePath -> FilePath
NameSpace -> FilePath
(Int -> NameSpace -> FilePath -> FilePath)
-> (NameSpace -> FilePath)
-> ([NameSpace] -> FilePath -> FilePath)
-> Show NameSpace
forall a.
(Int -> a -> FilePath -> FilePath)
-> (a -> FilePath) -> ([a] -> FilePath -> FilePath) -> Show a
$cshowsPrec :: Int -> NameSpace -> FilePath -> FilePath
showsPrec :: Int -> NameSpace -> FilePath -> FilePath
$cshow :: NameSpace -> FilePath
show :: NameSpace -> FilePath
$cshowList :: [NameSpace] -> FilePath -> FilePath
showList :: [NameSpace] -> FilePath -> FilePath
Show, Typeable NameSpace
Typeable NameSpace
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> NameSpace -> c NameSpace)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c NameSpace)
-> (NameSpace -> Constr)
-> (NameSpace -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c NameSpace))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c NameSpace))
-> ((forall b. Data b => b -> b) -> NameSpace -> NameSpace)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> NameSpace -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> NameSpace -> r)
-> (forall u. (forall d. Data d => d -> u) -> NameSpace -> [u])
-> (forall u.
    Int -> (forall d. Data d => d -> u) -> NameSpace -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> NameSpace -> m NameSpace)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> NameSpace -> m NameSpace)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> NameSpace -> m NameSpace)
-> Data NameSpace
NameSpace -> Constr
NameSpace -> DataType
(forall b. Data b => b -> b) -> NameSpace -> NameSpace
forall a.
Typeable a
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> NameSpace -> u
forall u. (forall d. Data d => d -> u) -> NameSpace -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> NameSpace -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> NameSpace -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> NameSpace -> m NameSpace
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> NameSpace -> m NameSpace
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c NameSpace
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> NameSpace -> c NameSpace
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c NameSpace)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c NameSpace)
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> NameSpace -> c NameSpace
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> NameSpace -> c NameSpace
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c NameSpace
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c NameSpace
$ctoConstr :: NameSpace -> Constr
toConstr :: NameSpace -> Constr
$cdataTypeOf :: NameSpace -> DataType
dataTypeOf :: NameSpace -> DataType
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c NameSpace)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c NameSpace)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c NameSpace)
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c NameSpace)
$cgmapT :: (forall b. Data b => b -> b) -> NameSpace -> NameSpace
gmapT :: (forall b. Data b => b -> b) -> NameSpace -> NameSpace
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> NameSpace -> r
gmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> NameSpace -> r
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> NameSpace -> r
gmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> NameSpace -> r
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> NameSpace -> [u]
gmapQ :: forall u. (forall d. Data d => d -> u) -> NameSpace -> [u]
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> NameSpace -> u
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> NameSpace -> u
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> NameSpace -> m NameSpace
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> NameSpace -> m NameSpace
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> NameSpace -> m NameSpace
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> NameSpace -> m NameSpace
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> NameSpace -> m NameSpace
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> NameSpace -> m NameSpace
Data, (forall x. NameSpace -> Rep NameSpace x)
-> (forall x. Rep NameSpace x -> NameSpace) -> Generic NameSpace
forall x. Rep NameSpace x -> NameSpace
forall x. NameSpace -> Rep NameSpace x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. NameSpace -> Rep NameSpace x
$cto :: forall x. Rep NameSpace x -> NameSpace
Generic )

-- | @Uniq@ is used by GHC to distinguish names from each other.
type Uniq = Integer

-- | The name without its module prefix.
--
-- ==== __Examples__
--
-- >>> nameBase ''Data.Either.Either
-- "Either"
-- >>> nameBase (mkName "foo")
-- "foo"
-- >>> nameBase (mkName "Module.foo")
-- "foo"
nameBase :: Name -> String
nameBase :: Name -> FilePath
nameBase (Name OccName
occ NameFlavour
_) = OccName -> FilePath
occString OccName
occ

-- | Module prefix of a name, if it exists.
--
-- ==== __Examples__
--
-- >>> nameModule ''Data.Either.Either
-- Just "Data.Either"
-- >>> nameModule (mkName "foo")
-- Nothing
-- >>> nameModule (mkName "Module.foo")
-- Just "Module"
nameModule :: Name -> Maybe String
nameModule :: Name -> Maybe FilePath
nameModule (Name OccName
_ (NameQ ModName
m))     = FilePath -> Maybe FilePath
forall a. a -> Maybe a
Just (ModName -> FilePath
modString ModName
m)
nameModule (Name OccName
_ (NameG NameSpace
_ PkgName
_ ModName
m)) = FilePath -> Maybe FilePath
forall a. a -> Maybe a
Just (ModName -> FilePath
modString ModName
m)
nameModule Name
_                      = Maybe FilePath
forall a. Maybe a
Nothing

-- | A name's package, if it exists.
--
-- ==== __Examples__
--
-- >>> namePackage ''Data.Either.Either
-- Just "base"
-- >>> namePackage (mkName "foo")
-- Nothing
-- >>> namePackage (mkName "Module.foo")
-- Nothing
namePackage :: Name -> Maybe String
namePackage :: Name -> Maybe FilePath
namePackage (Name OccName
_ (NameG NameSpace
_ PkgName
p ModName
_)) = FilePath -> Maybe FilePath
forall a. a -> Maybe a
Just (PkgName -> FilePath
pkgString PkgName
p)
namePackage Name
_                      = Maybe FilePath
forall a. Maybe a
Nothing

-- | Returns whether a name represents an occurrence of a top-level variable
-- ('VarName'), data constructor ('DataName'), type constructor, or type class
-- ('TcClsName'). If we can't be sure, it returns 'Nothing'.
--
-- ==== __Examples__
--
-- >>> nameSpace 'Prelude.id
-- Just VarName
-- >>> nameSpace (mkName "id")
-- Nothing -- only works for top-level variable names
-- >>> nameSpace 'Data.Maybe.Just
-- Just DataName
-- >>> nameSpace ''Data.Maybe.Maybe
-- Just TcClsName
-- >>> nameSpace ''Data.Ord.Ord
-- Just TcClsName
nameSpace :: Name -> Maybe NameSpace
nameSpace :: Name -> Maybe NameSpace
nameSpace (Name OccName
_ (NameG NameSpace
ns PkgName
_ ModName
_)) = NameSpace -> Maybe NameSpace
forall a. a -> Maybe a
Just NameSpace
ns
nameSpace Name
_                       = Maybe NameSpace
forall a. Maybe a
Nothing

{- |
Generate a capturable name. Occurrences of such names will be
resolved according to the Haskell scoping rules at the occurrence
site.

For example:

> f = [| pi + $(varE (mkName "pi")) |]
> ...
> g = let pi = 3 in $f

In this case, @g@ is desugared to

> g = Prelude.pi + 3

Note that @mkName@ may be used with qualified names:

> mkName "Prelude.pi"

See also 'Language.Haskell.TH.Lib.dyn' for a useful combinator. The above example could
be rewritten using 'Language.Haskell.TH.Lib.dyn' as

> f = [| pi + $(dyn "pi") |]
-}
mkName :: String -> Name
-- The string can have a '.', thus "Foo.baz",
-- giving a dynamically-bound qualified name,
-- in which case we want to generate a NameQ
--
-- Parse the string to see if it has a "." in it
-- so we know whether to generate a qualified or unqualified name
-- It's a bit tricky because we need to parse
--
-- > Foo.Baz.x   as    Qual Foo.Baz x
--
-- So we parse it from back to front
mkName :: FilePath -> Name
mkName FilePath
str
  = FilePath -> FilePath -> Name
split [] (FilePath -> FilePath
forall a. [a] -> [a]
reverse FilePath
str)
  where
    split :: FilePath -> FilePath -> Name
split FilePath
occ []        = OccName -> NameFlavour -> Name
Name (FilePath -> OccName
mkOccName FilePath
occ) NameFlavour
NameS
    split FilePath
occ (Char
'.':FilePath
rev) | Bool -> Bool
not (FilePath -> Bool
forall a. [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null FilePath
occ)
                        , FilePath -> Bool
is_rev_mod_name FilePath
rev
                        = OccName -> NameFlavour -> Name
Name (FilePath -> OccName
mkOccName FilePath
occ) (ModName -> NameFlavour
NameQ (FilePath -> ModName
mkModName (FilePath -> FilePath
forall a. [a] -> [a]
reverse FilePath
rev)))
        -- The 'not (null occ)' guard ensures that
        --      mkName "&." = Name "&." NameS
        -- The 'is_rev_mod' guards ensure that
        --      mkName ".&" = Name ".&" NameS
        --      mkName "^.." = Name "^.." NameS      -- #8633
        --      mkName "Data.Bits..&" = Name ".&" (NameQ "Data.Bits")
        -- This rather bizarre case actually happened; (.&.) is in Data.Bits
    split FilePath
occ (Char
c:FilePath
rev)   = FilePath -> FilePath -> Name
split (Char
cChar -> FilePath -> FilePath
forall a. a -> [a] -> [a]
:FilePath
occ) FilePath
rev

    -- Recognises a reversed module name xA.yB.C,
    -- with at least one component,
    -- and each component looks like a module name
    --   (i.e. non-empty, starts with capital, all alpha)
    is_rev_mod_name :: FilePath -> Bool
is_rev_mod_name FilePath
rev_mod_str
      | (FilePath
compt, FilePath
rest) <- (Char -> Bool) -> FilePath -> (FilePath, FilePath)
forall a. (a -> Bool) -> [a] -> ([a], [a])
break (Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
'.') FilePath
rev_mod_str
      , Bool -> Bool
not (FilePath -> Bool
forall a. [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null FilePath
compt), Char -> Bool
isUpper (FilePath -> Char
forall a. HasCallStack => [a] -> a
last FilePath
compt), (Char -> Bool) -> FilePath -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
all Char -> Bool
is_mod_char FilePath
compt
      = case FilePath
rest of
          []             -> Bool
True
          (Char
_dot : FilePath
rest') -> FilePath -> Bool
is_rev_mod_name FilePath
rest'
      | Bool
otherwise
      = Bool
False

    is_mod_char :: Char -> Bool
is_mod_char Char
c = Char -> Bool
isAlphaNum Char
c Bool -> Bool -> Bool
|| Char
c Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
'_' Bool -> Bool -> Bool
|| Char
c Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
'\''

-- | Only used internally
mkNameU :: String -> Uniq -> Name
mkNameU :: FilePath -> Uniq -> Name
mkNameU FilePath
s Uniq
u = OccName -> NameFlavour -> Name
Name (FilePath -> OccName
mkOccName FilePath
s) (Uniq -> NameFlavour
NameU Uniq
u)

-- | Only used internally
mkNameL :: String -> Uniq -> Name
mkNameL :: FilePath -> Uniq -> Name
mkNameL FilePath
s Uniq
u = OccName -> NameFlavour -> Name
Name (FilePath -> OccName
mkOccName FilePath
s) (Uniq -> NameFlavour
NameL Uniq
u)

-- | Used for 'x etc, but not available to the programmer
mkNameG :: NameSpace -> String -> String -> String -> Name
mkNameG :: NameSpace -> FilePath -> FilePath -> FilePath -> Name
mkNameG NameSpace
ns FilePath
pkg FilePath
modu FilePath
occ
  = OccName -> NameFlavour -> Name
Name (FilePath -> OccName
mkOccName FilePath
occ) (NameSpace -> PkgName -> ModName -> NameFlavour
NameG NameSpace
ns (FilePath -> PkgName
mkPkgName FilePath
pkg) (FilePath -> ModName
mkModName FilePath
modu))

mkNameS :: String -> Name
mkNameS :: FilePath -> Name
mkNameS FilePath
n = OccName -> NameFlavour -> Name
Name (FilePath -> OccName
mkOccName FilePath
n) NameFlavour
NameS

mkNameG_v, mkNameG_tc, mkNameG_d :: String -> String -> String -> Name
mkNameG_v :: FilePath -> FilePath -> FilePath -> Name
mkNameG_v  = NameSpace -> FilePath -> FilePath -> FilePath -> Name
mkNameG NameSpace
VarName
mkNameG_tc :: FilePath -> FilePath -> FilePath -> Name
mkNameG_tc = NameSpace -> FilePath -> FilePath -> FilePath -> Name
mkNameG NameSpace
TcClsName
mkNameG_d :: FilePath -> FilePath -> FilePath -> Name
mkNameG_d  = NameSpace -> FilePath -> FilePath -> FilePath -> Name
mkNameG NameSpace
DataName

data NameIs = Alone | Applied | Infix

showName :: Name -> String
showName :: Name -> FilePath
showName = NameIs -> Name -> FilePath
showName' NameIs
Alone

showName' :: NameIs -> Name -> String
showName' :: NameIs -> Name -> FilePath
showName' NameIs
ni Name
nm
 = case NameIs
ni of
       NameIs
Alone        -> FilePath
nms
       NameIs
Applied
        | Bool
pnam      -> FilePath
nms
        | Bool
otherwise -> FilePath
"(" FilePath -> FilePath -> FilePath
forall a. [a] -> [a] -> [a]
++ FilePath
nms FilePath -> FilePath -> FilePath
forall a. [a] -> [a] -> [a]
++ FilePath
")"
       NameIs
Infix
        | Bool
pnam      -> FilePath
"`" FilePath -> FilePath -> FilePath
forall a. [a] -> [a] -> [a]
++ FilePath
nms FilePath -> FilePath -> FilePath
forall a. [a] -> [a] -> [a]
++ FilePath
"`"
        | Bool
otherwise -> FilePath
nms
    where
        -- For now, we make the NameQ and NameG print the same, even though
        -- NameQ is a qualified name (so what it means depends on what the
        -- current scope is), and NameG is an original name (so its meaning
        -- should be independent of what's in scope.
        -- We may well want to distinguish them in the end.
        -- Ditto NameU and NameL
        nms :: FilePath
nms = case Name
nm of
                    Name OccName
occ NameFlavour
NameS         -> OccName -> FilePath
occString OccName
occ
                    Name OccName
occ (NameQ ModName
m)     -> ModName -> FilePath
modString ModName
m FilePath -> FilePath -> FilePath
forall a. [a] -> [a] -> [a]
++ FilePath
"." FilePath -> FilePath -> FilePath
forall a. [a] -> [a] -> [a]
++ OccName -> FilePath
occString OccName
occ
                    Name OccName
occ (NameG NameSpace
_ PkgName
_ ModName
m) -> ModName -> FilePath
modString ModName
m FilePath -> FilePath -> FilePath
forall a. [a] -> [a] -> [a]
++ FilePath
"." FilePath -> FilePath -> FilePath
forall a. [a] -> [a] -> [a]
++ OccName -> FilePath
occString OccName
occ
                    Name OccName
occ (NameU Uniq
u)     -> OccName -> FilePath
occString OccName
occ FilePath -> FilePath -> FilePath
forall a. [a] -> [a] -> [a]
++ FilePath
"_" FilePath -> FilePath -> FilePath
forall a. [a] -> [a] -> [a]
++ Uniq -> FilePath
forall a. Show a => a -> FilePath
show Uniq
u
                    Name OccName
occ (NameL Uniq
u)     -> OccName -> FilePath
occString OccName
occ FilePath -> FilePath -> FilePath
forall a. [a] -> [a] -> [a]
++ FilePath
"_" FilePath -> FilePath -> FilePath
forall a. [a] -> [a] -> [a]
++ Uniq -> FilePath
forall a. Show a => a -> FilePath
show Uniq
u

        pnam :: Bool
pnam = FilePath -> Bool
classify FilePath
nms

        -- True if we are function style, e.g. f, [], (,)
        -- False if we are operator style, e.g. +, :+
        classify :: FilePath -> Bool
classify FilePath
"" = Bool
False -- shouldn't happen; . operator is handled below
        classify (Char
x:FilePath
xs) | Char -> Bool
isAlpha Char
x Bool -> Bool -> Bool
|| (Char
x Char -> FilePath -> Bool
forall a. Eq a => a -> [a] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` FilePath
"_[]()") =
                            case (Char -> Bool) -> FilePath -> FilePath
forall a. (a -> Bool) -> [a] -> [a]
dropWhile (Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
/=Char
'.') FilePath
xs of
                                  (Char
_:FilePath
xs') -> FilePath -> Bool
classify FilePath
xs'
                                  []      -> Bool
True
                        | Bool
otherwise = Bool
False

instance Show Name where
  show :: Name -> FilePath
show = Name -> FilePath
showName

-- Tuple data and type constructors
-- | Tuple data constructor
tupleDataName :: Int -> Name
-- | Tuple type constructor
tupleTypeName :: Int -> Name

tupleDataName :: Int -> Name
tupleDataName Int
n = Int -> NameSpace -> Bool -> Name
mk_tup_name Int
n NameSpace
DataName  Bool
True
tupleTypeName :: Int -> Name
tupleTypeName Int
n = Int -> NameSpace -> Bool -> Name
mk_tup_name Int
n NameSpace
TcClsName Bool
True

-- Unboxed tuple data and type constructors
-- | Unboxed tuple data constructor
unboxedTupleDataName :: Int -> Name
-- | Unboxed tuple type constructor
unboxedTupleTypeName :: Int -> Name

unboxedTupleDataName :: Int -> Name
unboxedTupleDataName Int
n = Int -> NameSpace -> Bool -> Name
mk_tup_name Int
n NameSpace
DataName  Bool
False
unboxedTupleTypeName :: Int -> Name
unboxedTupleTypeName Int
n = Int -> NameSpace -> Bool -> Name
mk_tup_name Int
n NameSpace
TcClsName Bool
False

mk_tup_name :: Int -> NameSpace -> Bool -> Name
mk_tup_name :: Int -> NameSpace -> Bool -> Name
mk_tup_name Int
n NameSpace
space Bool
boxed
  = OccName -> NameFlavour -> Name
Name (FilePath -> OccName
mkOccName FilePath
tup_occ) (NameSpace -> PkgName -> ModName -> NameFlavour
NameG NameSpace
space (FilePath -> PkgName
mkPkgName FilePath
"ghc-prim") ModName
tup_mod)
  where
    withParens :: FilePath -> FilePath
withParens FilePath
thing
      | Bool
boxed     = FilePath
"("  FilePath -> FilePath -> FilePath
forall a. [a] -> [a] -> [a]
++ FilePath
thing FilePath -> FilePath -> FilePath
forall a. [a] -> [a] -> [a]
++ FilePath
")"
      | Bool
otherwise = FilePath
"(#" FilePath -> FilePath -> FilePath
forall a. [a] -> [a] -> [a]
++ FilePath
thing FilePath -> FilePath -> FilePath
forall a. [a] -> [a] -> [a]
++ FilePath
"#)"
    tup_occ :: FilePath
tup_occ | Int
n Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
1    = if Bool
boxed then FilePath
"Solo" else FilePath
"Solo#"
            | Bool
otherwise = FilePath -> FilePath
withParens (Int -> Char -> FilePath
forall a. Int -> a -> [a]
replicate Int
n_commas Char
',')
    n_commas :: Int
n_commas = Int
n Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1
    tup_mod :: ModName
tup_mod  = FilePath -> ModName
mkModName FilePath
"GHC.Tuple"

-- Unboxed sum data and type constructors
-- | Unboxed sum data constructor
unboxedSumDataName :: SumAlt -> SumArity -> Name
-- | Unboxed sum type constructor
unboxedSumTypeName :: SumArity -> Name

unboxedSumDataName :: Int -> Int -> Name
unboxedSumDataName Int
alt Int
arity
  | Int
alt Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
arity
  = FilePath -> Name
forall a. HasCallStack => FilePath -> a
error (FilePath -> Name) -> FilePath -> Name
forall a b. (a -> b) -> a -> b
$ FilePath
prefix FilePath -> FilePath -> FilePath
forall a. [a] -> [a] -> [a]
++ FilePath
"Index out of bounds." FilePath -> FilePath -> FilePath
forall a. [a] -> [a] -> [a]
++ FilePath
debug_info

  | Int
alt Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<= Int
0
  = FilePath -> Name
forall a. HasCallStack => FilePath -> a
error (FilePath -> Name) -> FilePath -> Name
forall a b. (a -> b) -> a -> b
$ FilePath
prefix FilePath -> FilePath -> FilePath
forall a. [a] -> [a] -> [a]
++ FilePath
"Alt must be > 0." FilePath -> FilePath -> FilePath
forall a. [a] -> [a] -> [a]
++ FilePath
debug_info

  | Int
arity Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
2
  = FilePath -> Name
forall a. HasCallStack => FilePath -> a
error (FilePath -> Name) -> FilePath -> Name
forall a b. (a -> b) -> a -> b
$ FilePath
prefix FilePath -> FilePath -> FilePath
forall a. [a] -> [a] -> [a]
++ FilePath
"Arity must be >= 2." FilePath -> FilePath -> FilePath
forall a. [a] -> [a] -> [a]
++ FilePath
debug_info

  | Bool
otherwise
  = OccName -> NameFlavour -> Name
Name (FilePath -> OccName
mkOccName FilePath
sum_occ)
         (NameSpace -> PkgName -> ModName -> NameFlavour
NameG NameSpace
DataName (FilePath -> PkgName
mkPkgName FilePath
"ghc-prim") (FilePath -> ModName
mkModName FilePath
"GHC.Prim"))

  where
    prefix :: FilePath
prefix     = FilePath
"unboxedSumDataName: "
    debug_info :: FilePath
debug_info = FilePath
" (alt: " FilePath -> FilePath -> FilePath
forall a. [a] -> [a] -> [a]
++ Int -> FilePath
forall a. Show a => a -> FilePath
show Int
alt FilePath -> FilePath -> FilePath
forall a. [a] -> [a] -> [a]
++ FilePath
", arity: " FilePath -> FilePath -> FilePath
forall a. [a] -> [a] -> [a]
++ Int -> FilePath
forall a. Show a => a -> FilePath
show Int
arity FilePath -> FilePath -> FilePath
forall a. [a] -> [a] -> [a]
++ FilePath
")"

    -- Synced with the definition of mkSumDataConOcc in GHC.Builtin.Types
    sum_occ :: FilePath
sum_occ = Char
'(' Char -> FilePath -> FilePath
forall a. a -> [a] -> [a]
: Char
'#' Char -> FilePath -> FilePath
forall a. a -> [a] -> [a]
: Int -> FilePath
bars Int
nbars_before FilePath -> FilePath -> FilePath
forall a. [a] -> [a] -> [a]
++ Char
'_' Char -> FilePath -> FilePath
forall a. a -> [a] -> [a]
: Int -> FilePath
bars Int
nbars_after FilePath -> FilePath -> FilePath
forall a. [a] -> [a] -> [a]
++ FilePath
"#)"
    bars :: Int -> FilePath
bars Int
i = Int -> Char -> FilePath
forall a. Int -> a -> [a]
replicate Int
i Char
'|'
    nbars_before :: Int
nbars_before = Int
alt Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1
    nbars_after :: Int
nbars_after  = Int
arity Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
alt

unboxedSumTypeName :: Int -> Name
unboxedSumTypeName Int
arity
  | Int
arity Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
2
  = FilePath -> Name
forall a. HasCallStack => FilePath -> a
error (FilePath -> Name) -> FilePath -> Name
forall a b. (a -> b) -> a -> b
$ FilePath
"unboxedSumTypeName: Arity must be >= 2."
         FilePath -> FilePath -> FilePath
forall a. [a] -> [a] -> [a]
++ FilePath
" (arity: " FilePath -> FilePath -> FilePath
forall a. [a] -> [a] -> [a]
++ Int -> FilePath
forall a. Show a => a -> FilePath
show Int
arity FilePath -> FilePath -> FilePath
forall a. [a] -> [a] -> [a]
++ FilePath
")"

  | Bool
otherwise
  = OccName -> NameFlavour -> Name
Name (FilePath -> OccName
mkOccName FilePath
sum_occ)
         (NameSpace -> PkgName -> ModName -> NameFlavour
NameG NameSpace
TcClsName (FilePath -> PkgName
mkPkgName FilePath
"ghc-prim") (FilePath -> ModName
mkModName FilePath
"GHC.Prim"))

  where
    -- Synced with the definition of mkSumTyConOcc in GHC.Builtin.Types
    sum_occ :: FilePath
sum_occ = Char
'(' Char -> FilePath -> FilePath
forall a. a -> [a] -> [a]
: Char
'#' Char -> FilePath -> FilePath
forall a. a -> [a] -> [a]
: Int -> Char -> FilePath
forall a. Int -> a -> [a]
replicate (Int
arity Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1) Char
'|' FilePath -> FilePath -> FilePath
forall a. [a] -> [a] -> [a]
++ FilePath
"#)"

-----------------------------------------------------
--              Locations
-----------------------------------------------------

data Loc
  = Loc { Loc -> FilePath
loc_filename :: String
        , Loc -> FilePath
loc_package  :: String
        , Loc -> FilePath
loc_module   :: String
        , Loc -> CharPos
loc_start    :: CharPos
        , Loc -> CharPos
loc_end      :: CharPos }
   deriving( Int -> Loc -> FilePath -> FilePath
[Loc] -> FilePath -> FilePath
Loc -> FilePath
(Int -> Loc -> FilePath -> FilePath)
-> (Loc -> FilePath) -> ([Loc] -> FilePath -> FilePath) -> Show Loc
forall a.
(Int -> a -> FilePath -> FilePath)
-> (a -> FilePath) -> ([a] -> FilePath -> FilePath) -> Show a
$cshowsPrec :: Int -> Loc -> FilePath -> FilePath
showsPrec :: Int -> Loc -> FilePath -> FilePath
$cshow :: Loc -> FilePath
show :: Loc -> FilePath
$cshowList :: [Loc] -> FilePath -> FilePath
showList :: [Loc] -> FilePath -> FilePath
Show, Loc -> Loc -> Bool
(Loc -> Loc -> Bool) -> (Loc -> Loc -> Bool) -> Eq Loc
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Loc -> Loc -> Bool
== :: Loc -> Loc -> Bool
$c/= :: Loc -> Loc -> Bool
/= :: Loc -> Loc -> Bool
Eq, Eq Loc
Eq Loc
-> (Loc -> Loc -> Ordering)
-> (Loc -> Loc -> Bool)
-> (Loc -> Loc -> Bool)
-> (Loc -> Loc -> Bool)
-> (Loc -> Loc -> Bool)
-> (Loc -> Loc -> Loc)
-> (Loc -> Loc -> Loc)
-> Ord Loc
Loc -> Loc -> Bool
Loc -> Loc -> Ordering
Loc -> Loc -> Loc
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: Loc -> Loc -> Ordering
compare :: Loc -> Loc -> Ordering
$c< :: Loc -> Loc -> Bool
< :: Loc -> Loc -> Bool
$c<= :: Loc -> Loc -> Bool
<= :: Loc -> Loc -> Bool
$c> :: Loc -> Loc -> Bool
> :: Loc -> Loc -> Bool
$c>= :: Loc -> Loc -> Bool
>= :: Loc -> Loc -> Bool
$cmax :: Loc -> Loc -> Loc
max :: Loc -> Loc -> Loc
$cmin :: Loc -> Loc -> Loc
min :: Loc -> Loc -> Loc
Ord, Typeable Loc
Typeable Loc
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> Loc -> c Loc)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c Loc)
-> (Loc -> Constr)
-> (Loc -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c Loc))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Loc))
-> ((forall b. Data b => b -> b) -> Loc -> Loc)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Loc -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Loc -> r)
-> (forall u. (forall d. Data d => d -> u) -> Loc -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> Loc -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> Loc -> m Loc)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> Loc -> m Loc)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> Loc -> m Loc)
-> Data Loc
Loc -> Constr
Loc -> DataType
(forall b. Data b => b -> b) -> Loc -> Loc
forall a.
Typeable a
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r'