New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix the treatment of type variables in quotations #207
Conversation
Really? Like what?
Does this proposal really solve that? For example, Does your proposal accept the program in the motivation? Note that this doesn't have a |
@RyanGlScott showed me a program with untyped template haskell which had some strange dynamic binding property which I think would be rejected by this proposal. I can't recall the exact definition though. Perhaps a lot is quite an exaggeration. Constraints containing polytypes are solved fine by my tests once you turn on the impredicativity extension. You can see all the examples that work in the test I added with the patch. If No the proposal rejects the program because it doesn't have a |
Indeed, I think the only programs that would be rejected under this proposal are the ones that are doing illicit things to begin with. Here is one example that comes to mind: wat :: forall a. Proxy a -> Q Type
wat _ = [t| a |] Currently, this quotation doesn't do what you think it does—it results in
This program will be rejected under this proposal, since there's no |
Broadly I think this makes sense, but there are lots of things I don't understand.
Here (b) is purely a matter of convenience. Once (a) is sorted, (b) is pretty simple. So let's focus on (a).
Also stress that the
6.Do you have any customers? Anyone who needs this feature? |
Thanks Simon, responding to your points below.
|
Another solution to the soundness issue is simply not to allow the use of scoped type variables inside of TH quotes. Also, I'd like to point out that use of polytypes requires |
This is a cool idea! It's certainly consistent with the decision to lift values in quotes. In the past I've used a very simple Something like this makes sense to me:
|
Is there anything else blocking this proposal? It is needed to fix a bad bug in Template Haskell. |
Thanks for the proposal, but unfortunately I have to tell you that the committee has rejected it, for the following reasons:
Perhaps with proper motivation -- and with an implementation based on Typeable -- we would be more in support. We do think this may be useful. But given the fact that the TH bug has existed since the dawn of time and no one has complained until now -- and even now, there is no practical, on the ground motivation -- we are uninclined to move forward here. Also, there’s a simple bug-fix for now: just reject the program. If we get lots of people yelling that they really want such programs, we can tackle it then. |
Obviously this is an unsatisfactory conclusion for the user's of typed template haskell. |
Why? I don't mean to be dense, but I'm genuinely not sure how you want this feature to work in typed TH. I do see how it could work in untyped TH, but I don't see how the proposal motivates adding the type-variable feature instead of just rejecting the original program. Full disclosure: I believe I am the original author of the text Joachim cribbed in his rejection. (Apologies if I've misremembered.) So feel free to respond to those points. I do think TH (and typed TH) should grow toward being more expressive, but the motivation behind this proposal is not compelling to me given that there is a much easier way to solve the problem. When/if folks come forward with more concrete motivation, then I (for one) would be happy to reconsider this. |
One big problem with typed template haskell currently is that you can end up splicing in an expression which fails to type check because of an ambiguous type variable. If you want to resolve the ambiguity by instantiating that variable using type applications then you have to choose a concrete type rather than a polymorphic type which can be annoying. This proposal means that you can resolve the ambiguity but still remain polymorphic which is valuable for code reuse. It's not an ideal solution but a decent enough workaround. There are more invasive and correct ways to fix this issue but I didn't want to derail the proposal with those. I have a paper in preparation which discusses more complicated problems to do with implicit arguments and a more invasive way to fix it. I think you don't think this will work because there is no source syntax for splicing types into typed quotations? but you don't need a source syntax. The "splices" are inserted implicitly just like how cross stage persistence works for values. |
I'm not worried about the source syntax (though it would be a bit sad not to be able to desugar implicit splices into other source syntax). I'm worried about the fact that TH types are not indexed by their kinds, which would seem necessary to support this in a typed way. But maybe it's OK because we allow only implicit splices, where GHC does know the kind of the type variable in question? It would be helpful to spell all this out. Note that this interpretation is in conflict with Simon's #207 (comment) which observed that implicit splicing was merely a matter of convenience. Again, I suppose that could all work, but I'd want it spelled out to be sure (and not just in a comment: in the proposal). It would also be very helpful (for me, at least) to have a concrete, practical use-case in the motivation. It's clear that you badly want this: why? |
Analyzing GHC#15833 yielded some motivation for this proposal. Here is the problem:
The first two definitions are accepted without issue. When splicing into The first step to understanding this is to look at the code in the quote in The solution to the problem appears to be not to just replace Indeed I don't see a way to accept the program above without something resembling this proposal. However, note that this example does not need users of typed TH to be able to include scoped type variables in their splices -- the need here is all internal. So my worries of #207 (comment) are allayed here. Nevertheless, I still think this proposal can be significantly simplified, say by using |
View Rendered