Last active
August 20, 2019 09:09
-
-
Save chrisdone/7dd85517b48183cb7ca5ae18554951bf to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{- | |
> :t $$(named [|| map ||]) | |
$$(named [|| map ||]) | |
:: TypedName | |
((ghc-prim-0.5.3:GHC.Types.Any -> ghc-prim-0.5.3:GHC.Types.Any) | |
-> [ghc-prim-0.5.3:GHC.Types.Any] | |
-> [ghc-prim-0.5.3:GHC.Types.Any]) | |
> $$(named [|| map ||]) | |
TypedName GHC.Base.map | |
-} | |
{-# LANGUAGE DeriveLift #-} | |
module TypedNameQuote (TypedName, named) where | |
import Language.Haskell.TH.Syntax | |
import Language.Haskell.TH.Lift () | |
data TypedName a = TypedName Name deriving (Lift, Show) | |
named :: Q (TExp a) -> Q (TExp (TypedName a)) | |
named getNamedExp = do | |
namedExp <- getNamedExp | |
case namedExp of | |
TExp (VarE name) -> unsafeTExpCoerce (lift (TypedName name)) | |
_ -> error "Need a variable name." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment