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
Type annotated quoters #125
Type annotated quoters #125
Conversation
How about reusing the existing phantom typed
|
@gelisam I remember reading somewhere that untyped template is needed because typed one are not always work, but i'm not sure about this. Of course if we can reuse |
Untyped TH is needed because it is more powerful than typed TH. For example, in category-syntax my macro takes in code which does not type-check, so it cannot have type
So using |
@gelisam I see, I have changed the proposal to use |
I'm not much of a consumer of quasi-quoters, so I don't have an informed opinion as to whether this is a good idea. I do agree that it should use |
This proposal makes sense to me. It's just a natural extension of the entire Typed Template Haskell idea, when It's much more than just documentation!! Consider
With the existing quasi-quote machinery we'd first have to run Worth explaining this in the proposal. |
This's a good point, i have added to |
This proposal doesn't specify if |
@gbaz , |
I don't think so. Just like |
Pardon the tangent, especially since I'm only following half of this; but I can't help wondering if there might be some potential cross-pollination with Hackett here, since its whole purpose for existence is to unify type checking with macro expansion. That's not the same as unifying with TH, so it's not directly applicable to this proposal; but I think it solves the same problem? Of course, the impedance mismatch might simply be too strong. But @lexi-lambda has mentioned that if it were more viable/convenient, she would like GHC as a Hackett backend, at which point Hackett modules should be importable from Haskell and vice versa, right? What's in the way of that? Is it harder than working out all the kinks and details here? Again, pardon the derailment, this isn't really the right place to bring this up. But it is the right context and audience, and I'm not sure where else to find that! |
@simonpj I'm definitely wrong on how a |
@nomeata I think this is ready for committee review ; ) |
Manuel volunteered to shepherd this. |
OK, let's see if my friends @sighingnow got some time. (Sorry for clicking the close button by mistake) |
I got an email from @simonpj that he was on holiday today. I don't know whether this extends for the whole week. I would love to hear more of his input, though it seems that his primary concern has been addressed. |
/remind me that @isovector wants to accept this on July 29 |
@nomeata set a reminder for Jul 29th 2019 |
Iavor's example is indeed helpful. I now see this proposal primarly as a way to write literal values in user-defined syntax. All the examples have this form:
Remember that in every case, we have an alternative that works today, namely
Is the quasiquote version sufficiently better? Beyond the name of the quasiquoter, the syntactic baggage is
Here I'm assuming that the typed version of quasiquotation uses two vertical bars, just like the type version of TH quotes. I suppose that we could be clever, and switch between typed and untyped quasiquoters based on the type of the quasiquoter, but that's uncomfortable. (The untyped ones run in the renamer which knows nothing of types.) Either way, the difference is not large. Question: does this proposal really pay its way? One might ask the same question of the existing quasiquotes, which can be similarly replaced. with splices. Back in 2007 when they were designed, all TH splices ran in the typechecker, and quasiquotes (which must run in the renamer) were something new. But nowadays, with the clear untyped-TH vs typed-TH split, I think we might well reject quasiquotes as a language extension too. Maybe I should write a proposal to deprecate quasiquotes! TL;DR, this proposal makes the language (and its implementation) just a bit more complicated, in exchange for what amounts to a minor syntactic variation in concrete syntax. I have not heard anyone saying "my life woud be so much better with this". So if it were me I wouldn't do it. But if everyone else is keen I won't stand in the way. The strongest argument is that (for better or worse) we do currently have quasiquotes, and this adds them to the typed-TH box as well as the untyped-TH box. If it is accepted, could the proposal be modified:
|
Quasioquotes are nice because they don't deal with weird escaping rules, work great over multiple lines, and are syntactically much easier. Replacing Consider a JSON quasiquoter. someJson :: Value
someJson = [json|
{ "hello world": [
"look ma",
{ "no weird quote": "escaping rules to follow!" }
]
}
|] If we were to redo this with a string literal, it'd look like garbage instead: someJson :: Value
someJson = $$(json "\
\ { \"hello world\": [ \
\ \ "look ma\", \
\ { \"no weird quote\": \"escaping rules to follow!\" } \
\ ] \
\ }" This entirely breaks the property of QQs that I can copy/paste some DSL directly into a quoter and get a Haskell value out of it. |
That's a very helpful observation, thanks Matt. But it's kind of accidental. You are really saying that Haskell lacks a good notation for string literals, especially
and it happens that the way that quasiquotes delimits strings is better for very long strings. Nothing directly to do with quasiquotation at all. Indeed It's really good to hear from people using this stuff in the field. More please! |
@simonpj https://gitlab.com/lorepub/moot/blob/master/src/Model.hs#L28-135 This is how the database models have been defined on almost every project I've worked on in the last 5 and 1/2 years, save the one that was Opaleye. I also use quasiquoters for:
I'm not really sure what you're angling at but it unnerves me. |
Don't be un-nerved! I'm just pointing out that, in principle, a quasiquote But Matt points out that a quote string I had not fully appreciated that because I'm not an at-scale user of quasiquotation, so I was expressing apprection of some concrete examples from the front line, which you have helpufully added to. No more than that. To me, this says that we should have designed a better notation for string literals in the first place! |
Indeed, quasiquoters are so much nicer than our notation for multi-line string literals that I've seen at least one package that provides a quasiquoter that is just for string literals (e.g. the |
👍 to these recent messages. I maintain this proposal is good while we have quasiquoters, but I actually despise them and would love to see them deprecated and removed:
|
@simonpj do you have any further concerns about this proposal? If not, I'll be happy to make the desired changes to the proposal text --- namely the double-bar syntax and that |
I couldn't parse that sentence. Perhaps you can make the changes an point us all at the relevant bit? But generally, yes ok. |
I think this discussion is very interesting. If we didn't have back-compat to worry about, I would probably advocate strongly for a new, better string-literal syntax (allowing multiline literals without escapes) and to remove quasiquotes. (Another infelicity about quasiquotes: they're much more like splices than quotes, yet both the name and syntax make them look like quotes.) Of course, we do have back-compat to worry about, and so I don't think I would do this. And, on balance, I support this proposal as it fills out a missing box. But it's good to know that almost the only reason to have quasiquotes is because we lack a better string-literal syntax, something I don't think I would have jumped to. |
👋 @isovector, accept this |
I've updated the proposal here: https://github.com/ghc-proposals/ghc-proposals/blob/eeeee74fdfd745a7906d237be112715323a7f887/proposals/0000-type-annotated-quoters.md . Can't for the life of me figure out how to merge it into this PR. I intend to merge this into /remind me to wants to accept this on July 31 |
@isovector set a reminder for Jul 31st 2019 |
@nomeata looks like we've reached consensus here and are ready to accept! |
|
FWIW I wrote #260 because while I approve of this proposal in the short term, I would like to see QuasiQuotes deprecated in the long term. |
The proposal has been accepted; the following discussion is mostly of historic interest.
RenderedRendered as rewritten by @isovector