-
Notifications
You must be signed in to change notification settings - Fork 36
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
singletonsOnly and fixity declarations for infix names don't play nicely #326
Comments
This implements workaround (2) in #326 (comment), which has the advantages of: (a) Not needing to generate a bunch of superfluous code. (b) In the event that ghc-proposals/ghc-proposals#65 is implemented, it will be much easier to notice that the hack can be removed (since the workaround will then produce an error).
I implemented workaround (2) in 40c736f, since: (a) It doesn't require generating a bunch of superfluous code. |
After implementing #427, I realized that there is a much cleaner way to resolve this issue than the hack I implemented in commit 40c736f. Currently, I'll reopen this ticket as a reminder to implement this idea. |
This patch: * Introduces a `genQuotedDecs :: Bool` option that controls whether the `q [Dec]` arguments in the `promote` and `singletons` functions should be generated as part of their output. * Refactor `promote{Only}` and `singletons{Only}` to use `genQuotedDecs`. * Changes `D.S.Promote.promoteInfixDecl` so that it _does_ promote fixity declarations for infix names when `genQuotedDecs` is `False`. (See the updated `Note [singletons and fixity declarations]` in `D.S.Single.Fixity`, wrinkle 1, for a more detailed explanation.) This fixes #326 in a much more robust way than the previous hacky workaround in commit 40c736f.
This patch: * Introduces a `genQuotedDecs :: Bool` option that controls whether the `q [Dec]` arguments in the `promote` and `singletons` functions should be generated as part of their output. * Refactor `promote{Only}` and `singletons{Only}` to use `genQuotedDecs`. * Changes `D.S.Promote.promoteInfixDecl` so that it _does_ promote fixity declarations for infix names when `genQuotedDecs` is `False`. (See the updated `Note [singletons and fixity declarations]` in `D.S.Single.Fixity`, wrinkle 1, for a more detailed explanation.) This fixes #326 in a much more robust way than the previous hacky workaround in commit 40c736f.
…se (#430) This patch: * Introduces a `genQuotedDecs :: Bool` option that controls whether the `q [Dec]` arguments in the `promote` and `singletons` functions should be generated as part of their output. * Refactor `promote{Only}` and `singletons{Only}` to use `genQuotedDecs`. * Changes `D.S.Promote.promoteInfixDecl` so that it _does_ promote fixity declarations for infix names when `genQuotedDecs` is `False`. (See the updated `Note [singletons and fixity declarations]` in `D.S.Single.Fixity`, wrinkle 1, for a more detailed explanation.) This fixes #326 in a much more robust way than the previous hacky workaround in commit 40c736f.
While working on #323, I discovered something unsettling. The vast majority of infix type families that
singletons
produces, including($)
,(++)
,(+)
,(-)
,(*)
, and many others, do not have fixity declarations! The culprit, as it turns out, is due to an unfortunate side-effect of the waysingletons
is architectured.Using
($)
an example, here is how we promote($)
currently:Note that we use
singletonsOnly
because we don't want to generate a value-level($)
. However, when processing theinfixr 0 $
declaration,singletons
notes that the promoted version of($)
is also($)
, and thus generating a fixity declaration for the type-level($)
would be redundant, since there's already one in scope for the value-level($)
......well, except that's not true. We're using
singletonsOnly
, so we don't actually generate a value-levelinfixr 0 $
declaration! Thus, the type-level($)
is left without any fixity declaration at all. Major bummer.One might wonder why
singletonsOnly
doesn't always generate fixity declarations. Alas, we can't due this, because it would break programs like this:Thus,
singletons
must be conservative here.In an ideal world where we had the ability to control which namespace fixity declarations worked over, we could just write:
And then we could always promote
infixr value 0 $
toinfixr type 0 $
, without fear of name clashes. But we don't live in such a world today, so we'll have to think of a workaround in the interim. I can think of two workarounds:singletonsOnly
withsingletons
(making sure not to export the value-level identifiers that are generated).The text was updated successfully, but these errors were encountered: