Îõ³h$FÀEo-      !"#$%&'()*+, Trustworthy'(.>ÀÁÂÄÉÊÎÔÖ×ÙE#$ th-compat a is a type alias for: - a , if using template-haskell-2.17.0.0 or later, or- (. a), if using an older version of template-haskell.ÛThis should be used with caution, as its definition differs depending on which version of template-haskellÌ you are using. It is mostly useful for contexts in which one is writing a definition that is intended to be used directly in a typed Template Haskell splice, as the types of TH splices differ between template-haskell versions as well.Levity-polymorphic since template-haskell-2.16.0.0. th-compat m a is a type alias for: m a , if using template-haskell-2.17.0.0 or later, orm (. a), if using an older version of template-haskell.ÛThis should be used with caution, as its definition differs depending on which version of template-haskellÌ you are using. It is mostly useful for contexts in which one is writing a definition that is intended to be used directly in a typed Template Haskell splice, as the types of TH splices differ between template-haskell versions as well.Levity-polymorphic since template-haskell-2.16.0.0. th-compatLevity-polymorphic since template-haskell-2.16.0.0. th-compatUnderlying monadic value th-compatÀA class that allows one to smooth over the differences between  m a4 (the type of typed Template Haskell quotations on template-haskell-2.17.0.0 or later) and m (TExp a)Æ (the type of typed Template Haskell quotations on older versions of template-haskellÅ). Here are two examples that demonstrate how to use each method of : ){-# LANGUAGE TemplateHaskell #-} import Language.Haskell.TH import !Language.Haskell.TH.Syntax.Compat -- & will ensure that the end result is a 6, regardless of -- whether the quote itself returns a  or a TExp . myCode ::  - Int myCode =  [|| 42 ||] --  will ensure that the input 5 is suitable for splicing -- (i.e., it will return a  or a TExp depending on the -- template-haskell0 version in use). fortyTwo :: Int fortyTwo = $$( myCode) Levity-polymorphic since template-haskell-2.16.0.0. th-compatConvert something to a . th-compatConvert to something from a .  th-compatThe  Ö class implements the minimal interface which is necessary for desugaring quotations.The Monad mÆ superclass is needed to stitch together the different AST fragments. Õ 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 /Å to be extracted purely from the quotation without interacting with -.  th-compat0Generate 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 -> x0In 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 -> x0since the occurrence VarE nm2+ is captured by the innermost binding of x , namely VarP nm1.  th-compatÌDiscard the type annotation and produce a plain Template Haskell expressionLevity-polymorphic since template-haskell-2.16.0.0.This is a variant of the unTypeQ. function that is always guaranteed to use a  % constraint, even on old versions of template-haskell.ÚAs this function interacts with typed Template Haskell, this function is only defined on template-haskell-2.9.0.0 (GHC 7.8) or later.  th-compat4Annotate 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.Levity-polymorphic since template-haskell-2.16.0.0.This is a variant of the unsafeTExpCoerce. function that is always guaranteed to use a  & constraint, even on old versions of template-haskell.ÚAs this function interacts with typed Template Haskell, this function is only defined on template-haskell-2.9.0.0 (GHC 7.8) or later.  th-compatÏTurn a value into a Template Haskell expression, suitable for use in a splice.This is a variant of the 0 method of 1% that is always guaranteed to use a  & constraint, even on old versions of template-haskell.Levity-polymorphic since template-haskell-2.17.0.0. th-compatÛTurn a value into a Template Haskell typed expression, suitable for use in a typed splice.This is a variant of the 2 method of 1% that is always guaranteed to use a   constraint and return a , even on old versions of template-haskell.ÚAs this function interacts with typed Template Haskell, this function is only defined on template-haskell-2.9.0.0 (GHC 7.8) or later. While the 2 method of 1 was first introduced in template-haskell-2.16.0.0&, we are able to backport it back to template-haskell-2.9.0.0 by making use of the 0 method on older versions of template-haskell . This crucially relies on the 1 law that lift x áD unTypeQ ( liftTyped x) to work, so beware if you use  with an unlawful 1 instance.Levity-polymorphic since template-haskell-2.17.0.0. th-compatThis is a variant of the 3. function that is always guaranteed to use a  & constraint, even on old versions of template-haskell. th-compatUse a - computation in a  / context. This function is only safe when the -' computation performs actions from the   instance for - or any of  's subclasses (4, 5, and 6+). Attempting to perform actions from the 7, 8, or 9 instances for - will result in runtime errors."This is useful when you have some -3-valued functions that only performs actions from   and wish to generalise it from - to  ƒ without having to rewrite the internals of the function. This is especially handy for code defined in terms of combinators from Language.Haskell.TH.Lib , which were all hard-coded to - prior to template-haskell-2.17.0.0(. For instance, consider this function:  apply :: / -> / -> - / apply f x =  (return x) (return y) 6There are two ways to generalize this function to use  À in a backwards-compatible way. One way to do so is to rewrite apply to avoid the use of  , like so: applyQuote ::   m => / -> / -> m / applyQuote f x = return (: x y) For a small example like  applyQuoteå, there isn't much work involved. But this can become tiresome for larger examples. In such cases, 0 can do the heavy lifting for you. For example,  applyQuote can also be defined as: applyQuote ::   m => / -> / -> m / applyQuote f x =  (apply f x)  th-compatÒUnsafely convert an untyped code representation into a typed code representation.Levity-polymorphic since template-haskell-2.16.0.0. th-compat4Lift a monadic action producing code into the typed  representationLevity-polymorphic since template-haskell-2.16.0.0. th-compatÀExtract the untyped representation from the typed representationLevity-polymorphic since template-haskell-2.16.0.0. th-compatÐModify the ambient monad used during code generation. For example, you can use  to handle a state effect: Ý handleState :: Code (StateT Int Q) a -> Code Q a handleState = hoistCode (flip runState 0) Levity-polymorphic since template-haskell-2.16.0.0. th-compatÚVariant of (>>=) which allows effectful computations to be injected into code generation.Levity-polymorphic since template-haskell-2.16.0.0. th-compatÙVariant of (>>) which allows effectful computations to be injected into code generation.Levity-polymorphic since template-haskell-2.16.0.0. th-compat7A useful combinator for embedding monadic actions into  ç myCode :: ... => Code m a myCode = joinCode $ do x <- someSideEffect return (makeCodeWith x) Levity-polymorphic since template-haskell-2.16.0.0. th-compat A variant of  that works over s. Because this function uses Í, the type of this function will be different depending on which version of template-haskell' you are using. (See the Haddocks for % for more information on this point.)Levity-polymorphic since template-haskell-2.16.0.0. th-compat A variant of  that works over s. Because this function uses Í, the type of this function will be different depending on which version of template-haskell' you are using. (See the Haddocks for % for more information on this point.)Levity-polymorphic since template-haskell-2.16.0.0. th-compatLift a . a into a Ø. This is useful when splicing in the result of a computation into a typed QuasiQuoter.One example is ;Ëing over a list of elements and returning an expression from each element.  mkInt :: < -> - (. =/) mkInt str = [|| length $$str ||] mkInts :: [<] -> - [. =] mkInts = traverse mkInt This gives us a list of ., not a .Å of a list. We can push the list inside the type with this function:  listTE :: [. a] -> . [a] listTE = . . > . ? @ In a do block using , we can bind the resulting. [=] out of the expression. foo :: - (.ð Int) foo = do ints <- mkInts ["hello", "world", "goodybe", "bob"] [|| sum $$(pure (listTE ints)) ||] Prior to GHC 9, with the - type, we can write A :: . a -> - (. a)€, which is a valid thing to use in a typed quasiquoter. However, after GHC 9, this code will fail to type check. There is no 5 instance for  m a*, so we need another way to splice it in.A GHC 9 only solution can use  :: m (. a) -> Code m a and A together, like:  . A.With ö, we can splice it in a backwards compatible way. A fully backwards- and forwards-compatible example looks like this:  mkInt :: < -> - = mkInt str = " [|| length $$str ||] mkInts :: [<] -> - [. ="] mkInts = traverse mkInt foo ::  = foo = Ä $ do ints <- mkInts ["hello", "world", "goodybe", "bob"] + [|| sum $$(expToSplice (listTE ints)) ||]  th-compat A variant of  that takes a 0 as an argument. Because this function takes a Ü as an argyment, the type of this function will be different depending on which version of template-haskell' you are using. (See the Haddocks for % for more information on this point.)Levity-polymorphic since template-haskell-2.16.0.0. th-compat A variant of  that works over s. Because this function uses Í, the type of this function will be different depending on which version of template-haskell' you are using. (See the Haddocks for % for more information on this point.)Levity-polymorphic since template-haskell-2.16.0.0. th-compat A variant of  that works over s. Because this function uses Í, the type of this function will be different depending on which version of template-haskell' you are using. (See the Haddocks for % for more information on this point.)Levity-polymorphic since template-haskell-2.16.0.0. th-compat A variant of  that returns a #. Because this function returns a Ô, the return type of this function will be different depending on which version of template-haskell' you are using. (See the Haddocks for & for more information on this point.)Levity-polymorphic since template-haskell-2.16.0.0. th-compat A variant of  that is: Always implemented in terms of 0 behind the scenes, and Returns a ç. This means that the return type of this function will be different depending on which version of template-haskell* you are using. (See the Haddocks for ) for more information on this point.)×This is especially useful for minimizing CPP in one particular scenario: implementing 2 in hand-written 1$ instances where the corresponding 0Ñ implementation cannot be derived. For instance, consider this example from the text library:  instance 1 Text where 0Ó = appE (varE 'pack) . stringE . unpack #if MIN_VERSION_template_haskell(2,17,0) 2 =  . 0. #elif MIN_VERSION_template_haskell(2,16,0) 2 = B . 0 #endif  The precise details of how this 0É implementation works are not important, only that it is something that  DeriveLiftÿ could not generate. The main point of this example is to illustrate how tiresome it is to write the CPP necessary to define 22 in a way that works across multiple versions of template-haskell. With 3, however, this becomes slightly easier to manage:  instance 1 Text where 0Ó = appE (varE 'pack) . stringE . unpack #if MIN_VERSION_template_haskell(2,16,0) 2 =  #endif ÌNote that due to the way this function is defined, this will only work for 1 instances t such that  (t :: Type)". If you wish to manually define 29 for a type with a different kind, you will have to use  / to overcome levity polymorphism restrictions.  th-compat?Unsafely convert an untyped splice representation into a typed 2 representation. Because this function returns a Õ, the return type of this function will be different depending on which version of template-haskell& you are using. (See the Haddocks for & for more information on this point.)2This is especially useful for minimizing CPP when: You need to implement 2 in a hand-written 1& instance where the corresponding 0* implementation cannot be derived, andThe data type receiving a Lift instance has a kind besides Type.ÊCondition (2) is important because while it is possible to simply define 'Syntax.liftTyped =  for 1 instances t such that  (t :: Type)•, this will not work for types with different types, such as unboxed types or unlifted newtypes. This is because GHC restrictions prevent defining 3 in a levity polymorphic fashion, so one must use  Æ to work around these restrictions. Here is an example of how to use  :  instance 1 Int# where 0Ö x = litE (intPrimL (fromIntegral (I# x))) #if MIN_VERSION_template_haskell(2,16,0) 2 x =   (0 x) #endif Levity-polymorphic since template-haskell-2.16.0.0.! th-compat A variant of  that takes a 0 as an argument. Because this function takes a Ü as an argyment, the type of this function will be different depending on which version of template-haskell' you are using. (See the Haddocks for % for more information on this point.)Levity-polymorphic since template-haskell-2.16.0.0." th-compat²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.§This is best-effort compatibility implementation. This function looks at the source location of the Haskell file calling it, finds the first parent directory with a .cabalÉ file, and uses that as the root directory for fixing the relative path.# th-compatÉThe input is a filepath, which if relative is offset by the package root.( th-compatLevity-polymorphic since template-haskell-2.16.0.0.) th-compatLevity-polymorphic since template-haskell-2.16.0.0.$  !"#$   !"#Ã      !"#$%&'()*+,-./0120130140150160170189:;9:<9:=9>?9@A01B01C9DE9:FGHI01J9:K01L9:M01NÏ&th-compat-0.1.4-KrCixGbCmFXGyomLDmgsax!Language.Haskell.TH.Syntax.CompatLibappESpliceQSpliceCodeQCode examineCodeIsCodetoCodefromCodeQuotenewName unTypeQQuoteunsafeTExpCoerceQuote liftQuoteliftTypedQuoteliftStringQuoteunsafeQToQuoteunsafeCodeCoerceliftCode unTypeCode hoistCodebindCode bindCode_joinCode bindSplice bindSplice_ expToSplice examineSplice hoistSplice joinSplice liftSpliceliftTypedFromUntypedSpliceunsafeSpliceCoerce unTypeSplicegetPackageRootmakeRelativeToProject$fQuoteQ$fQuasiQuoteToQuasi$fMonadIOQuoteToQuasi$fMonadFailQuoteToQuasi $fIsCoderQaQ$fIsCoderqaCode$fFunctorQuoteToQuasi$fApplicativeQuoteToQuasi$fMonadQuoteToQuasitemplate-haskellLanguage.Haskell.TH.SyntaxQTExpExpliftLift liftTyped liftStringbaseGHC.BaseFunctor ApplicativeMonadControl.Monad.Fail MonadFailControl.Monad.IO.ClassMonadIOQuasiAppEData.TraversabletraverseStringghc-prim GHC.TypesIntListEmapunTypepureunsafeTExpCoerce