{-# LANGUAGE CPP                      #-}
{-# LANGUAGE DataKinds                #-}
{-# LANGUAGE FlexibleInstances        #-}
{-# LANGUAGE PolyKinds                #-}
{-# LANGUAGE RankNTypes               #-}
{-# LANGUAGE RoleAnnotations          #-}
{-# LANGUAGE ScopedTypeVariables      #-}
{-# LANGUAGE StandaloneKindSignatures #-}
{-# LANGUAGE TemplateHaskellQuotes    #-}
{-# LANGUAGE TypeApplications         #-}
{-# LANGUAGE Unsafe                   #-}
#if __GLASGOW_HASKELL__ <908
{-# LANGUAGE UndecidableInstances     #-}
#endif
{-# OPTIONS_HADDOCK not-home #-}
module Language.Haskell.TH.CodeT.Unsafe (
    -- * CodeT
    CodeT (..),
    unsafeCodeTCoerce,
    unTypeCodeT,
    appCodeT,
    sigCode,
    sigCodeT,
    CodeTQ,
    unsafeCodeTName,
    unsafeCodeTNameD,
    unsafeCodeTNameTC,
    -- * LiftT
    LiftT (..),
) where

import Data.Int     (Int16, Int32, Int64, Int8)
import Data.Proxy   (Proxy (..))
import Data.Word    (Word16, Word32, Word64, Word8)
import GHC.TypeLits (KnownNat, KnownSymbol, natVal, symbolVal)

#if MIN_VERSION_base(4,16,0)
import GHC.TypeLits (KnownChar, charVal)
#endif

import qualified GHC.Exts as Ki
import qualified Data.Kind as Ki

import Language.Haskell.TH
       (Code, Name, Q, Quote, TyLit (..), Type, appT, conT, litT, sigE, sigT, unTypeCode, unsafeCodeCoerce)
import Language.Haskell.TH.Syntax (mkNameG_d, mkNameG_tc)

-- instances
import qualified Data.ByteString
import qualified Data.ByteString.Builder
import qualified Data.ByteString.Lazy
import qualified Data.Functor.Compose
import qualified Data.Functor.Const
import qualified Data.Functor.Identity
import qualified Data.IntMap
import qualified Data.IntSet
import qualified Data.Map
import qualified Data.Sequence
import qualified Data.Set
import qualified Data.Text
import qualified Data.Text.Lazy
import qualified Data.Text.Lazy.Builder
import qualified Data.Time
import qualified Data.Tree

-- $setup
-- >>> :set -XTemplateHaskell -XTypeApplications
-- >>> import Language.Haskell.TH

-------------------------------------------------------------------------------
-- CodeT
-------------------------------------------------------------------------------

-- | 'CodeT' is to 'Type' what 'Code' is to 'Exp'.
--
-- Because current GHC Haskell doesn't have true dependent types,
-- we often use singletons pattern to emulate them.
-- To a first approximation @'CodeT' q a -> ...@ type emulates
-- dependent function @forall (a :: 'Code' q 'Data.Kind.Type') -> ...@.
--
-- There aren't typed type quotes, i.e. we cannot write @[t|| Int ||]@,
-- instead we have to resort to unsafe interface for now:
--
-- >>> let ty = UnsafeCodeT [t| Int |] :: Quote q => CodeT q Int
-- >>> unTypeCodeT ty >>= print . ppr
-- GHC.Types.Int
--
-- ... or we can "safely" create many 'CodeT' values using 'LiftT' type-class:
--
-- >>> let ty' = codeT :: Quote q => CodeT q Int
-- >>> unTypeCodeT ty' >>= print . ppr
-- GHC.Types.Int
--
type CodeT :: (Ki.Type -> Ki.Type) -> forall k. k -> Ki.Type
newtype CodeT q a =
    -- | Unsafely convert an untyped code representation into a typed code representation.
    --
    -- Prefer using 'unsafeCodeTCoerce'.
    UnsafeCodeT (q Type)

type role CodeT representational nominal

-- | Extract the untyped representation from the typed representation.
unTypeCodeT :: CodeT m a -> m Type
unTypeCodeT :: forall {k} (m :: * -> *) (a :: k). CodeT m a -> m Type
unTypeCodeT (UnsafeCodeT m Type
ty) = m Type
ty

-- | Unsafely convert an untyped code representation into a typed code representation.
unsafeCodeTCoerce :: Quote q => q Type -> CodeT q a
unsafeCodeTCoerce :: forall {k} (q :: * -> *) (a :: k). Quote q => q Type -> CodeT q a
unsafeCodeTCoerce = q Type -> CodeT q a
forall (q :: * -> *) k (a :: k). q Type -> CodeT q a
UnsafeCodeT

-- |
--
-- >>> let ty = appCodeT (codeT @Maybe) (codeT @Char)
-- >>> unTypeCodeT ty >>= print . ppr
-- GHC.Maybe.Maybe GHC.Types.Char
--
appCodeT :: Quote m => CodeT m f -> CodeT m x -> CodeT m (f x)
appCodeT :: forall {k} {k} (m :: * -> *) (f :: k -> k) (x :: k).
Quote m =>
CodeT m f -> CodeT m x -> CodeT m (f x)
appCodeT (UnsafeCodeT m Type
f) (UnsafeCodeT m Type
x) = m Type -> CodeT m (f x)
forall (q :: * -> *) k (a :: k). q Type -> CodeT q a
UnsafeCodeT (m Type -> m Type -> m Type
forall (m :: * -> *). Quote m => m Type -> m Type -> m Type
appT m Type
f m Type
x)

-- |
--
-- >>> let e = sigCode [|| 'x' ||] codeT
-- >>> unTypeCode e >>= print . ppr
-- 'x' :: GHC.Types.Char
--
sigCode :: Quote q => Code q a -> CodeT q a -> Code q a
sigCode :: forall (q :: * -> *) a.
Quote q =>
Code q a -> CodeT q a -> Code q a
sigCode Code q a
e CodeT q a
t = q Exp -> Code q a
forall a (m :: * -> *). Quote m => m Exp -> Code m a
unsafeCodeCoerce (q Exp -> q Type -> q Exp
forall (m :: * -> *). Quote m => m Exp -> m Type -> m Exp
sigE (Code q a -> q Exp
forall a (m :: * -> *). Quote m => Code m a -> m Exp
unTypeCode Code q a
e) (CodeT q a -> q Type
forall {k} (m :: * -> *) (a :: k). CodeT m a -> m Type
unTypeCodeT CodeT q a
t))

-- |
--
-- >>> let ty = sigCodeT (codeT @Bool) codeT
-- >>> unTypeCodeT ty >>= print . ppr
-- (GHC.Types.Bool :: GHC.Prim.TYPE (GHC.Types.BoxedRep GHC.Types.Lifted))
--
sigCodeT :: Quote q => CodeT q (a :: k) -> CodeT q k -> CodeT q a
sigCodeT :: forall (q :: * -> *) k (a :: k).
Quote q =>
CodeT q a -> CodeT q k -> CodeT q a
sigCodeT (UnsafeCodeT q Type
t) (UnsafeCodeT q Type
k) = q Type -> CodeT q a
forall (q :: * -> *) k (a :: k). q Type -> CodeT q a
UnsafeCodeT (q Type
k q Type -> (Type -> q Type) -> q Type
forall a b. q a -> (a -> q b) -> q b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= q Type -> Type -> q Type
forall (m :: * -> *). Quote m => m Type -> Type -> m Type
sigT q Type
t)

type CodeTQ :: forall k. k -> Ki.Type
type CodeTQ = CodeT Q

-- | Unsafely convert a (type) name into a typed code representation.
--
-- The namespace of 'Name' is not checked.
--
-- >>> let ty = unsafeCodeTName ''Bool
-- >>> unTypeCodeT ty >>= print . ppr
-- GHC.Types.Bool
--
unsafeCodeTName :: Quote m => Name -> CodeT m a
unsafeCodeTName :: forall {k} (m :: * -> *) (a :: k). Quote m => Name -> CodeT m a
unsafeCodeTName Name
n = m Type -> CodeT m a
forall (q :: * -> *) k (a :: k). q Type -> CodeT q a
UnsafeCodeT (Name -> m Type
forall (m :: * -> *). Quote m => Name -> m Type
conT Name
n)

-- | Unsafely create a data constructor name and convert it into a typed code representation.
unsafeCodeTNameD :: String -> String -> String -> forall m. Quote m => CodeT m a
unsafeCodeTNameD :: forall {k} (a :: k).
String
-> String -> String -> forall (m :: * -> *). Quote m => CodeT m a
unsafeCodeTNameD String
x String
y String
z = Name -> CodeT m a
forall {k} (m :: * -> *) (a :: k). Quote m => Name -> CodeT m a
unsafeCodeTName (String -> String -> String -> Name
mkNameG_d String
x String
y String
z)

-- | Unsafely create a type constructor name and convert it into a typed code representation.
unsafeCodeTNameTC :: String -> String -> String -> forall m. Quote m => CodeT m a
unsafeCodeTNameTC :: forall {k} (a :: k).
String
-> String -> String -> forall (m :: * -> *). Quote m => CodeT m a
unsafeCodeTNameTC String
x String
y String
z = Name -> CodeT m a
forall {k} (m :: * -> *) (a :: k). Quote m => Name -> CodeT m a
unsafeCodeTName (String -> String -> String -> Name
mkNameG_tc String
x String
y String
z)

-------------------------------------------------------------------------------
-- LiftT
-------------------------------------------------------------------------------

-- | Implicitly create 'CodeT' values.
--
-- This packages provides some 'LiftT' instances for types in GHC bundled libs.
--
-- There is no instance for 'Data.Kind.Constraint', as @Constraint@ is not apart from 'Data.Kind.Type'.
-- See the GHC issue https://gitlab.haskell.org/ghc/ghc/-/issues/24279.
--
-- The [codet-plugin](https://hackage.haskell.org/package/codet-plugin) can automatically
-- create instances for type constructors. (The provided @f x@ instance does most of the work).
--
type LiftT :: forall {k}. k -> Ki.Constraint
class LiftT a where
    codeT :: Quote m => CodeT m a

instance (LiftT f, LiftT x) => LiftT (f x) where
    codeT :: forall (m :: * -> *). Quote m => CodeT m (f x)
codeT = CodeT m f -> CodeT m x -> CodeT m (f x)
forall {k} {k} (m :: * -> *) (f :: k -> k) (x :: k).
Quote m =>
CodeT m f -> CodeT m x -> CodeT m (f x)
appCodeT CodeT m f
forall {k} (a :: k) (m :: * -> *). (LiftT a, Quote m) => CodeT m a
forall (m :: * -> *). Quote m => CodeT m f
codeT CodeT m x
forall {k} (a :: k) (m :: * -> *). (LiftT a, Quote m) => CodeT m a
forall (m :: * -> *). Quote m => CodeT m x
codeT

-------------------------------------------------------------------------------
-- instances: TypeLits
-------------------------------------------------------------------------------

instance KnownSymbol s => LiftT s where codeT :: forall (m :: * -> *). Quote m => CodeT m s
codeT = m Type -> CodeT m s
forall (q :: * -> *) k (a :: k). q Type -> CodeT q a
UnsafeCodeT (m Type -> CodeT m s) -> m Type -> CodeT m s
forall a b. (a -> b) -> a -> b
$ m TyLit -> m Type
forall (m :: * -> *). Quote m => m TyLit -> m Type
litT (m TyLit -> m Type) -> m TyLit -> m Type
forall a b. (a -> b) -> a -> b
$ TyLit -> m TyLit
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (TyLit -> m TyLit) -> TyLit -> m TyLit
forall a b. (a -> b) -> a -> b
$ String -> TyLit
StrTyLit  (String -> TyLit) -> String -> TyLit
forall a b. (a -> b) -> a -> b
$ Proxy s -> String
forall (n :: Symbol) (proxy :: Symbol -> *).
KnownSymbol n =>
proxy n -> String
symbolVal (forall {k} (t :: k). Proxy t
forall (t :: Symbol). Proxy t
Proxy @s)
instance KnownNat n    => LiftT n where codeT :: forall (m :: * -> *). Quote m => CodeT m n
codeT = m Type -> CodeT m n
forall (q :: * -> *) k (a :: k). q Type -> CodeT q a
UnsafeCodeT (m Type -> CodeT m n) -> m Type -> CodeT m n
forall a b. (a -> b) -> a -> b
$ m TyLit -> m Type
forall (m :: * -> *). Quote m => m TyLit -> m Type
litT (m TyLit -> m Type) -> m TyLit -> m Type
forall a b. (a -> b) -> a -> b
$ TyLit -> m TyLit
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (TyLit -> m TyLit) -> TyLit -> m TyLit
forall a b. (a -> b) -> a -> b
$ Integer -> TyLit
NumTyLit  (Integer -> TyLit) -> Integer -> TyLit
forall a b. (a -> b) -> a -> b
$ Proxy n -> Integer
forall (n :: Nat) (proxy :: Nat -> *).
KnownNat n =>
proxy n -> Integer
natVal (forall (t :: Nat). Proxy t
forall {k} (t :: k). Proxy t
Proxy @n)

#if MIN_VERSION_base(4,16,0)
instance KnownChar c   => LiftT c where codeT :: forall (m :: * -> *). Quote m => CodeT m c
codeT = m Type -> CodeT m c
forall (q :: * -> *) k (a :: k). q Type -> CodeT q a
UnsafeCodeT (m Type -> CodeT m c) -> m Type -> CodeT m c
forall a b. (a -> b) -> a -> b
$ m TyLit -> m Type
forall (m :: * -> *). Quote m => m TyLit -> m Type
litT (m TyLit -> m Type) -> m TyLit -> m Type
forall a b. (a -> b) -> a -> b
$ TyLit -> m TyLit
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (TyLit -> m TyLit) -> TyLit -> m TyLit
forall a b. (a -> b) -> a -> b
$ Char -> TyLit
CharTyLit (Char -> TyLit) -> Char -> TyLit
forall a b. (a -> b) -> a -> b
$ Proxy c -> Char
forall (n :: Char) (proxy :: Char -> *).
KnownChar n =>
proxy n -> Char
charVal (forall (t :: Char). Proxy t
forall {k} (t :: k). Proxy t
Proxy @c)
#endif

-------------------------------------------------------------------------------
-- instances: Type
-------------------------------------------------------------------------------

instance LiftT Int where codeT :: forall (m :: * -> *). Quote m => CodeT m Int
codeT = Name -> CodeT m Int
forall {k} (m :: * -> *) (a :: k). Quote m => Name -> CodeT m a
unsafeCodeTName ''Int
instance LiftT Word where codeT :: forall (m :: * -> *). Quote m => CodeT m Word
codeT = Name -> CodeT m Word
forall {k} (m :: * -> *) (a :: k). Quote m => Name -> CodeT m a
unsafeCodeTName ''Word
instance LiftT Float where codeT :: forall (m :: * -> *). Quote m => CodeT m Float
codeT = Name -> CodeT m Float
forall {k} (m :: * -> *) (a :: k). Quote m => Name -> CodeT m a
unsafeCodeTName ''Float
instance LiftT Double where codeT :: forall (m :: * -> *). Quote m => CodeT m Double
codeT = Name -> CodeT m Double
forall {k} (m :: * -> *) (a :: k). Quote m => Name -> CodeT m a
unsafeCodeTName ''Double

instance LiftT Int8  where codeT :: forall (m :: * -> *). Quote m => CodeT m Int8
codeT = Name -> CodeT m Int8
forall {k} (m :: * -> *) (a :: k). Quote m => Name -> CodeT m a
unsafeCodeTName ''Int8
instance LiftT Int16 where codeT :: forall (m :: * -> *). Quote m => CodeT m Int16
codeT = Name -> CodeT m Int16
forall {k} (m :: * -> *) (a :: k). Quote m => Name -> CodeT m a
unsafeCodeTName ''Int16
instance LiftT Int32 where codeT :: forall (m :: * -> *). Quote m => CodeT m Int32
codeT = Name -> CodeT m Int32
forall {k} (m :: * -> *) (a :: k). Quote m => Name -> CodeT m a
unsafeCodeTName ''Int32
instance LiftT Int64 where codeT :: forall (m :: * -> *). Quote m => CodeT m Int64
codeT = Name -> CodeT m Int64
forall {k} (m :: * -> *) (a :: k). Quote m => Name -> CodeT m a
unsafeCodeTName ''Int64

instance LiftT Word8  where codeT :: forall (m :: * -> *). Quote m => CodeT m Word8
codeT = Name -> CodeT m Word8
forall {k} (m :: * -> *) (a :: k). Quote m => Name -> CodeT m a
unsafeCodeTName ''Word8
instance LiftT Word16 where codeT :: forall (m :: * -> *). Quote m => CodeT m Word16
codeT = Name -> CodeT m Word16
forall {k} (m :: * -> *) (a :: k). Quote m => Name -> CodeT m a
unsafeCodeTName ''Word16
instance LiftT Word32 where codeT :: forall (m :: * -> *). Quote m => CodeT m Word32
codeT = Name -> CodeT m Word32
forall {k} (m :: * -> *) (a :: k). Quote m => Name -> CodeT m a
unsafeCodeTName ''Word32
instance LiftT Word64 where codeT :: forall (m :: * -> *). Quote m => CodeT m Word64
codeT = Name -> CodeT m Word64
forall {k} (m :: * -> *) (a :: k). Quote m => Name -> CodeT m a
unsafeCodeTName ''Word64

instance LiftT Bool where codeT :: forall (m :: * -> *). Quote m => CodeT m Bool
codeT = Name -> CodeT m Bool
forall {k} (m :: * -> *) (a :: k). Quote m => Name -> CodeT m a
unsafeCodeTName ''Bool
instance LiftT Ordering where codeT :: forall (m :: * -> *). Quote m => CodeT m Ordering
codeT = Name -> CodeT m Ordering
forall {k} (m :: * -> *) (a :: k). Quote m => Name -> CodeT m a
unsafeCodeTName ''Ordering
instance LiftT Char where codeT :: forall (m :: * -> *). Quote m => CodeT m Char
codeT = Name -> CodeT m Char
forall {k} (m :: * -> *) (a :: k). Quote m => Name -> CodeT m a
unsafeCodeTName ''Char

-------------------------------------------------------------------------------
-- instances: Tuples
-------------------------------------------------------------------------------

instance LiftT () where codeT :: forall (m :: * -> *). Quote m => CodeT m ()
codeT = Name -> CodeT m ()
forall {k} (m :: * -> *) (a :: k). Quote m => Name -> CodeT m a
unsafeCodeTName ''()
instance LiftT (,) where codeT :: forall (m :: * -> *). Quote m => CodeT m (,)
codeT = Name -> CodeT m (,)
forall {k} (m :: * -> *) (a :: k). Quote m => Name -> CodeT m a
unsafeCodeTName ''(,)
instance LiftT (,,) where codeT :: forall (m :: * -> *). Quote m => CodeT m (,,)
codeT = Name -> CodeT m (,,)
forall {k} (m :: * -> *) (a :: k). Quote m => Name -> CodeT m a
unsafeCodeTName ''(,,)
instance LiftT (,,,) where codeT :: forall (m :: * -> *). Quote m => CodeT m (,,,)
codeT = Name -> CodeT m (,,,)
forall {k} (m :: * -> *) (a :: k). Quote m => Name -> CodeT m a
unsafeCodeTName ''(,,,)
instance LiftT (,,,,) where codeT :: forall (m :: * -> *). Quote m => CodeT m (,,,,)
codeT = Name -> CodeT m (,,,,)
forall {k} (m :: * -> *) (a :: k). Quote m => Name -> CodeT m a
unsafeCodeTName ''(,,,,)
instance LiftT (,,,,,) where codeT :: forall (m :: * -> *). Quote m => CodeT m (,,,,,)
codeT = Name -> CodeT m (,,,,,)
forall {k} (m :: * -> *) (a :: k). Quote m => Name -> CodeT m a
unsafeCodeTName ''(,,,,,)
instance LiftT (,,,,,,) where codeT :: forall (m :: * -> *). Quote m => CodeT m (,,,,,,)
codeT = Name -> CodeT m (,,,,,,)
forall {k} (m :: * -> *) (a :: k). Quote m => Name -> CodeT m a
unsafeCodeTName ''(,,,,,,)

-------------------------------------------------------------------------------
-- instances: Type -> Type
-------------------------------------------------------------------------------

instance LiftT [] where codeT :: forall (m :: * -> *). Quote m => CodeT m []
codeT = Name -> CodeT m []
forall {k} (m :: * -> *) (a :: k). Quote m => Name -> CodeT m a
unsafeCodeTName ''[]
instance LiftT Maybe where codeT :: forall (m :: * -> *). Quote m => CodeT m Maybe
codeT = Name -> CodeT m Maybe
forall {k} (m :: * -> *) (a :: k). Quote m => Name -> CodeT m a
unsafeCodeTName ''Maybe
instance LiftT IO where codeT :: forall (m :: * -> *). Quote m => CodeT m IO
codeT = Name -> CodeT m IO
forall {k} (m :: * -> *) (a :: k). Quote m => Name -> CodeT m a
unsafeCodeTName ''IO

-------------------------------------------------------------------------------
-- instances: Type -> Type -> Type
-------------------------------------------------------------------------------

instance LiftT Either where codeT :: forall (m :: * -> *). Quote m => CodeT m Either
codeT = Name -> CodeT m Either
forall {k} (m :: * -> *) (a :: k). Quote m => Name -> CodeT m a
unsafeCodeTName ''Either

-------------------------------------------------------------------------------
-- instances: kinds
-------------------------------------------------------------------------------

instance LiftT (->) where codeT :: forall (m :: * -> *). Quote m => CodeT m (->)
codeT = Name -> CodeT m (->)
forall {k} (m :: * -> *) (a :: k). Quote m => Name -> CodeT m a
unsafeCodeTName ''(->) -- perfectly, we want LiftT.FUN
instance LiftT Ki.TYPE where codeT :: forall (m :: * -> *). Quote m => CodeT m TYPE
codeT = Name -> CodeT m TYPE
forall {k} (m :: * -> *) (a :: k). Quote m => Name -> CodeT m a
unsafeCodeTName ''Ki.TYPE

{-

We don't have an instance for Constraint. GHC is tricky.
https://gitlab.haskell.org/ghc/ghc/-/issues/24279

This works in GHC-9.8, but probably will be "fixed" in GHC-9.10,
so we don't bother with Constraint at all.

#if MIN_VERSION_base(4,18,0)
instance LiftT Ki.CONSTRAINT where codeT = unsafeCodeTName ''Ki.CONSTRAINT
#else
instance LiftT Ki.Constraint where codeT = unsafeCodeTName ''Ki.Constraint
#endif
-}

#if MIN_VERSION_base(4,16,0)
instance LiftT Ki.RuntimeRep where codeT :: forall (m :: * -> *). Quote m => CodeT m RuntimeRep
codeT = Name -> CodeT m RuntimeRep
forall {k} (m :: * -> *) (a :: k). Quote m => Name -> CodeT m a
unsafeCodeTName ''Ki.RuntimeRep
instance LiftT Ki.BoxedRep where codeT :: forall (m :: * -> *). Quote m => CodeT m 'BoxedRep
codeT = Name -> CodeT m 'BoxedRep
forall {k} (m :: * -> *) (a :: k). Quote m => Name -> CodeT m a
unsafeCodeTName 'Ki.BoxedRep

instance LiftT Ki.Levity where codeT :: forall (m :: * -> *). Quote m => CodeT m Levity
codeT = Name -> CodeT m Levity
forall {k} (m :: * -> *) (a :: k). Quote m => Name -> CodeT m a
unsafeCodeTName ''Ki.Levity
instance LiftT Ki.Lifted where codeT :: forall (m :: * -> *). Quote m => CodeT m 'Lifted
codeT = Name -> CodeT m 'Lifted
forall {k} (m :: * -> *) (a :: k). Quote m => Name -> CodeT m a
unsafeCodeTName 'Ki.Lifted
instance LiftT Ki.Unlifted where codeT :: forall (m :: * -> *). Quote m => CodeT m 'Unlifted
codeT = Name -> CodeT m 'Unlifted
forall {k} (m :: * -> *) (a :: k). Quote m => Name -> CodeT m a
unsafeCodeTName 'Ki.Unlifted
#else
instance LiftT Ki.LiftedRep where codeT = unsafeCodeTName 'Ki.LiftedRep
instance LiftT Ki.UnliftedRep where codeT = unsafeCodeTName 'Ki.UnliftedRep
#endif

-------------------------------------------------------------------------------
-- instances: bytestring
-------------------------------------------------------------------------------

instance LiftT Data.ByteString.ByteString where codeT :: forall (m :: * -> *). Quote m => CodeT m ByteString
codeT = Name -> CodeT m ByteString
forall {k} (m :: * -> *) (a :: k). Quote m => Name -> CodeT m a
unsafeCodeTName ''Data.ByteString.ByteString
instance LiftT Data.ByteString.Lazy.ByteString where codeT :: forall (m :: * -> *). Quote m => CodeT m ByteString
codeT = Name -> CodeT m ByteString
forall {k} (m :: * -> *) (a :: k). Quote m => Name -> CodeT m a
unsafeCodeTName ''Data.ByteString.Lazy.ByteString
instance LiftT Data.ByteString.Builder.Builder where codeT :: forall (m :: * -> *). Quote m => CodeT m Builder
codeT = Name -> CodeT m Builder
forall {k} (m :: * -> *) (a :: k). Quote m => Name -> CodeT m a
unsafeCodeTName ''Data.ByteString.Builder.Builder

-------------------------------------------------------------------------------
-- instances: containers
-------------------------------------------------------------------------------

instance LiftT Data.IntMap.IntMap where codeT :: forall (m :: * -> *). Quote m => CodeT m IntMap
codeT = Name -> CodeT m IntMap
forall {k} (m :: * -> *) (a :: k). Quote m => Name -> CodeT m a
unsafeCodeTName ''Data.IntMap.IntMap
instance LiftT Data.IntSet.IntSet where codeT :: forall (m :: * -> *). Quote m => CodeT m IntSet
codeT = Name -> CodeT m IntSet
forall {k} (m :: * -> *) (a :: k). Quote m => Name -> CodeT m a
unsafeCodeTName ''Data.IntSet.IntSet
instance LiftT Data.Map.Map where codeT :: forall (m :: * -> *). Quote m => CodeT m Map
codeT = Name -> CodeT m Map
forall {k} (m :: * -> *) (a :: k). Quote m => Name -> CodeT m a
unsafeCodeTName ''Data.Map.Map
instance LiftT Data.Sequence.Seq where codeT :: forall (m :: * -> *). Quote m => CodeT m Seq
codeT = Name -> CodeT m Seq
forall {k} (m :: * -> *) (a :: k). Quote m => Name -> CodeT m a
unsafeCodeTName ''Data.Sequence.Seq
instance LiftT Data.Set.Set where codeT :: forall (m :: * -> *). Quote m => CodeT m Set
codeT = Name -> CodeT m Set
forall {k} (m :: * -> *) (a :: k). Quote m => Name -> CodeT m a
unsafeCodeTName ''Data.IntSet.IntSet
instance LiftT Data.Tree.Tree where codeT :: forall (m :: * -> *). Quote m => CodeT m Tree
codeT = Name -> CodeT m Tree
forall {k} (m :: * -> *) (a :: k). Quote m => Name -> CodeT m a
unsafeCodeTName ''Data.Tree.Tree

-------------------------------------------------------------------------------
-- instances: text
-------------------------------------------------------------------------------

instance LiftT Data.Text.Text where codeT :: forall (m :: * -> *). Quote m => CodeT m Text
codeT = Name -> CodeT m Text
forall {k} (m :: * -> *) (a :: k). Quote m => Name -> CodeT m a
unsafeCodeTName ''Data.Text.Text
instance LiftT Data.Text.Lazy.Text where codeT :: forall (m :: * -> *). Quote m => CodeT m Text
codeT = Name -> CodeT m Text
forall {k} (m :: * -> *) (a :: k). Quote m => Name -> CodeT m a
unsafeCodeTName ''Data.Text.Lazy.Text
instance LiftT Data.Text.Lazy.Builder.Builder where codeT :: forall (m :: * -> *). Quote m => CodeT m Builder
codeT = Name -> CodeT m Builder
forall {k} (m :: * -> *) (a :: k). Quote m => Name -> CodeT m a
unsafeCodeTName ''Data.Text.Lazy.Builder.Builder

-------------------------------------------------------------------------------
-- instances: transformers
-------------------------------------------------------------------------------

instance LiftT Data.Functor.Identity.Identity where codeT :: forall (m :: * -> *). Quote m => CodeT m Identity
codeT = Name -> CodeT m Identity
forall {k} (m :: * -> *) (a :: k). Quote m => Name -> CodeT m a
unsafeCodeTName ''Data.Functor.Identity.Identity
instance LiftT Data.Functor.Compose.Compose where codeT :: forall (m :: * -> *). Quote m => CodeT m Compose
codeT = Name -> CodeT m Compose
forall {k} (m :: * -> *) (a :: k). Quote m => Name -> CodeT m a
unsafeCodeTName ''Data.Functor.Compose.Compose
instance LiftT Data.Functor.Const.Const where codeT :: forall (m :: * -> *). Quote m => CodeT m Const
codeT = Name -> CodeT m Const
forall {k} (m :: * -> *) (a :: k). Quote m => Name -> CodeT m a
unsafeCodeTName ''Data.Functor.Const.Const

-------------------------------------------------------------------------------
-- instances: time
-------------------------------------------------------------------------------

instance LiftT Data.Time.UTCTime where codeT :: forall (m :: * -> *). Quote m => CodeT m UTCTime
codeT = Name -> CodeT m UTCTime
forall {k} (m :: * -> *) (a :: k). Quote m => Name -> CodeT m a
unsafeCodeTName ''Data.Time.UTCTime
instance LiftT Data.Time.Day where codeT :: forall (m :: * -> *). Quote m => CodeT m Day
codeT = Name -> CodeT m Day
forall {k} (m :: * -> *) (a :: k). Quote m => Name -> CodeT m a
unsafeCodeTName ''Data.Time.Day