type parameters in a HsType

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

type parameters in a HsType

Tseen She
Hi all,

I'm writing a tool that needs to figure out if a type parameter declared on the type constructor (i.e. tcdTyVars DataDecl) is referenced by any of the fields (in the tcdDataDefn). I only care about ConDeclH98 things.

Is there a canonical way to do this that doesn't involve me having to traverse the HsType ?

In an ideal world I want this signature:


PS: I think this is probably done in the DeriveFunctor (etc) derivation rules, because they need to figure out which fields to touch, e.g. in gen_Functor_binds, but I don't see where this check would be done.

Best regards, Tseen She

_______________________________________________
ghc-devs mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs
Reply | Threaded
Open this post in threaded view
|

RE: type parameters in a HsType

GHC - devs mailing list

I think you are asking for a function to find the free variable of a HsType:

 

freeVars :: HsType Ps -> [Located RdrName]

 

Then you could see if the free vars intersects the binders.  Right?

 

If so, try GHC.Rename.HsType.extractHsTyRdrTyVars

 

Simon

 

From: ghc-devs <[hidden email]> On Behalf Of Tseen She
Sent: 06 October 2020 23:19
To: [hidden email]
Subject: type parameters in a HsType

 

Hi all,


I'm writing a tool that needs to figure out if a type parameter declared on the type constructor (i.e. tcdTyVars DataDecl) is referenced by any of the fields (in the tcdDataDefn). I only care about ConDeclH98 things.

 

Is there a canonical way to do this that doesn't involve me having to traverse the HsType ?

 

In an ideal world I want this signature:

 

  HsType -> [HsTyVarBndr GhcPs] -> Bool

 

PS: I think this is probably done in the DeriveFunctor (etc) derivation rules, because they need to figure out which fields to touch, e.g. in gen_Functor_binds, but I don't see where this check would be done.

 

Best regards, Tseen She


_______________________________________________
ghc-devs mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs