Skip to content

Instantly share code, notes, and snippets.

@parsonsmatt
Created April 19, 2021 19:33
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parsonsmatt/4747a846085889bde5dce08c37a40f45 to your computer and use it in GitHub Desktop.
Save parsonsmatt/4747a846085889bde5dce08c37a40f45 to your computer and use it in GitHub Desktop.
liftType :: forall t. Typeable t => Q Type
liftType = do
let rep = typeRep @t
go rep
where
go :: forall (a :: k). TypeRep a -> Q Type
go tr =
case tr of
Con tyCon -> do
let
nameBase =
mkOccName $ tyConName tyCon
flavor =
NameG
TcClsName
(mkPkgName $ tyConPackage tyCon)
(mkModName $ tyConModule tyCon)
name =
Name
nameBase
flavor
pure $ ConT name
App trA trB ->
[t|$(go trA) $(go trB)|]
Fun trA trB ->
[t|$(go trA) -> $(go trB)|]
@gergoerdi
Copy link

Now a major motion picture Cabal package!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment