Add `typeToName` bike shedding
I've written a helper function typeToName
that seems like a useful addition to template-haskell
. Here's the code currently:
module Data.Typeable.Extended
( module Data.Typeable.Extended,
module Data.Typeable,
)
where
import Data.Typeable
import Language.Haskell.TH.Syntax
-- | Retrieve a @TemplateHaskell@ 'Name' for a 'Typeable' type. Used to drive derivation:
--
-- @
-- $(
-- let
-- prxy = Proxy :: Proxy Int
-- in
-- mobileGen (moatOptionsP prxy) (typeToName prxy)
-- )
-- @
typeToName :: Typeable a => Proxy a -> Name
typeToName prxy =
let tyRep =
typeRep prxy
tyCon =
typeRepTyCon tyRep
in mkNameG TcClsName (tyConPackage tyCon) (tyConModule tyCon) (tyConName tyCon)
Would a PR adding this be accepted?
If so, where should it go? And should it have a different name or signature?