[GHC] #10541: Expose kind information for type variables with reify

#10541: Expose kind information for type variables with reify -------------------------------------+------------------------------------- Reporter: spinda | Owner: Type: feature | Status: new request | Milestone: Priority: normal | Version: 7.10.1 Component: Template | Operating System: Unknown/Multiple Haskell | Type of failure: None/Unknown Keywords: | Blocked By: Architecture: | Related Tickets: Unknown/Multiple | Test Case: | Blocking: | Differential Revisions: | -------------------------------------+------------------------------------- The comment on [https://hackage.haskell.org/package/template- haskell-2.10.0.0/docs/Language-Haskell-TH-Syntax.html#v:TyVarI TyVarI] notes that the attached Type is always {{{VarT theName}}}, and that this could potentially be extended. Currently, there isn't a way to access kind information for a type variable through the Template Haskell API. It would be useful (at least for me) to have this ability here. The limitation on the returned Type comes from the [https://github.com/ghc/ghc/blob/master/compiler/typecheck/TcSplice.hs#L1060 ATyVar clause of reifyThing], which zonks the TyVar to a GHC type and then uses reifyType to convert it to a TH type. For a TyVarTy, [https://github.com/ghc/ghc/blob/master/compiler/typecheck/TcSplice.hs#L1281 reifyType] always returns {{{VarT theName}}}. I can see a few possible ways of exposing kind information here: (a) Fill the Type argument to TyVarI with {{{SigT (VarT theName) theKind}}}. This could be done either as a special case in place of the call to reifyType in reifyThing, or as a modification to reifyType's behavior. The question of when SigT should be included is open: all the time? when the kind isn't {{{*}}}? when the kind is something that involves more than {{{*}}} and {{{->}}}? (b) Change TyVarI from {{{TyVarI Name Type}}} to {{{TyVarI Name TyVarBndr}}}. This seems like the most straightforward, stable way of exposing kind information, but it requires a breaking API change. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10541 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10541: Expose kind information for type variables with reify -------------------------------------+------------------------------------- Reporter: spinda | Owner: Type: feature request | Status: new Priority: normal | Milestone: Component: Template Haskell | Version: 7.10.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: None/Unknown | Unknown/Multiple Blocked By: | Test Case: Related Tickets: | Blocking: | Differential Revisions: -------------------------------------+------------------------------------- Comment (by goldfire): Could you post your use-case? One thing I'm worried about here is the possibility that the result of a TH splice could affect a type variable's kind. For example: {{{ foo :: forall a. Proxy a -> $( ... ) }}} where the splice produces `a -> a`. If the code running in the splice needs the kind of `a`, we have a loop. Unless I'm missing something... which is entirely possible, as something smells wrong to me in my comment. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10541#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10541: Expose kind information for type variables with reify -------------------------------------+------------------------------------- Reporter: spinda | Owner: Type: feature request | Status: new Priority: normal | Milestone: Component: Template Haskell | Version: 7.10.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: None/Unknown | Unknown/Multiple Blocked By: | Test Case: Related Tickets: | Blocking: | Differential Revisions: -------------------------------------+------------------------------------- Comment (by spinda): That sounds right to me. If the splice produced {{{a b c}}} then that would change the kind. My use case is reading the kind in type synonyms with explicit kind signatures on certain type variables. What about possibility (b), with {{{KindedTV}}} where the kind is known and {{{PlainTV}}} where it isn't set? Or perhaps an additional {{{Maybe Kind}}} on {{{TyVarI}}}. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10541#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10541: Expose kind information for type variables with reify -------------------------------------+------------------------------------- Reporter: spinda | Owner: Type: feature request | Status: new Priority: normal | Milestone: Component: Template Haskell | Version: 7.10.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: None/Unknown | Unknown/Multiple Blocked By: | Test Case: Related Tickets: | Blocking: | Differential Revisions: -------------------------------------+------------------------------------- Comment (by spinda): The {{{KindedTV}}}/{{{PlainTV}}} solution matches up with {{{ForallTy}}}„ which seems appropriate. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10541#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10541: Expose kind information for type variables with reify -------------------------------------+------------------------------------- Reporter: spinda | Owner: Type: feature request | Status: new Priority: normal | Milestone: Component: Template Haskell | Version: 7.10.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: None/Unknown | Unknown/Multiple Blocked By: | Test Case: Related Tickets: | Blocking: | Differential Revisions: -------------------------------------+------------------------------------- Comment (by goldfire): I think we can actually do a bit better. It should be possible to tell whether we fully know a type variable's kind, by looking through the (zonked) kind for any `MetaTv`s. If there aren't any, then the kind is fully known and can be reported. Otherwise, don't report. The problem with my approach here is that it's fragile, depending delicately on the order that GHC reads through a type. Perhaps your solution is better: report the kind only when it is robustly known, either through a kind annotation or other means. (For "other means", I mean, for example, when a type variable is in scope in a term, via !ScopedTypeVariables. These type variables are generally fully known.) But how do we know when the tyvar's kind is robustly known... or even just annotated? By the time `reify` is called, we've lost a lot of that information. There's ''something'' we can do for you in this space, but I'm not sure exactly what yet. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10541#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10541: Expose kind information for type variables with reify -------------------------------------+------------------------------------- Reporter: spinda | Owner: Type: feature request | Status: new Priority: normal | Milestone: Component: Template Haskell | Version: 7.10.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Revisions: -------------------------------------+------------------------------------- Comment (by spinda): Hi -- just wanted to say that I don't need this anymore. Not sure if someone else does... -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10541#comment:5 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10541: Expose kind information for type variables with reify -------------------------------------+------------------------------------- Reporter: spinda | Owner: Type: feature request | Status: closed Priority: normal | Milestone: Component: Template Haskell | Version: 7.10.1 Resolution: wontfix | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Revisions: -------------------------------------+------------------------------------- Changes (by goldfire): * status: new => closed * resolution: => wontfix Comment: In that case, I'm going to close as wontfix. If you, or anyone else, needs this, please do reopen. I do like the idea of providing this functionality, but it's hard to motivate the time necessary if there are no eager users. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10541#comment:6 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC