module Language.Haskell.TH.Quotable (Quotable (..), qEC, qT) where

import Data.Constructor.Extract
import Language.Haskell.TH

-- | A 'Quotable' is a value that can be turned into a 'Q' computation, allowing it to be used in a quasi-quote
class Quotable a b where
    q :: a -> Q b

instance Quotable (Q a) a where
    q :: Q a -> Q a
q = Q a -> Q a
forall a. a -> a
id

instance Quotable a a where
    q :: a -> Q a
q = a -> Q a
forall a. a -> Q a
forall (f :: * -> *) a. Applicative f => a -> f a
pure

-- | Like 'q', but for extracted constructors (see 'ExtractedConstructor' from 'extract-cons')
qEC :: (ExtractedConstructor a b) => a -> Q b
qEC :: forall a b. ExtractedConstructor a b => a -> Q b
qEC = b -> Q b
forall a. a -> Q a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (b -> Q b) -> (a -> b) -> a -> Q b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> b
forall con ty. ExtractedConstructor con ty => con -> ty
fromEC

-- | Like 'q', but for typed expressions
qT :: TExp t -> Code Q t
qT :: forall t. TExp t -> Code Q t
qT = Q (TExp t) -> Code Q t
forall (m :: * -> *) a. m (TExp a) -> Code m a
Code (Q (TExp t) -> Code Q t)
-> (TExp t -> Q (TExp t)) -> TExp t -> Code Q t
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TExp t -> Q (TExp t)
forall a. a -> Q a
forall (f :: * -> *) a. Applicative f => a -> f a
pure