-
Notifications
You must be signed in to change notification settings - Fork 37
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
Knowing what is (and isn't) defunctionalized can be confusing #429
Comments
Question: what should we do to resolve inconsistencies (1)-(3) above? Here are my thoughts:
|
Thanks for this thorough analysis. Here is what I propose as a way forward -- but my opinion here is fairly weak, and I am happy with many possible directions (including simply documenting the current strange setup, which I don't believe is actively hurting anyone).
These ideas broadly follow yours, but with the possibility that some find the bundling behavior useful. |
I like your suggested design of having both data GenSymbolsDepth
= GenNameOnlyDefunSymbols
| GenNonDataOrClassDefunSymbols
| GenAllDefunSymbols With this approach, |
I don't feel the need for exposing this much flexibility, per se. Is anyone asking for it? But I'm also not actively against exposing it. |
It's hard to answer that question since this new design is still hypothetical. But it is worth noting that anyone who relies on the current behavior of Of course, it could be the case that my worrying is completely unfounded and that no one will miss the current behavior of |
Given that there are about 20 usages of |
This patch fleshes out some more details about what `singletons` can and can't do in its `README`. The key changes are: 1. There is a new "Promotion and partial application" section that explains what defunctionalization is in some amount of detail. There is also a new subsection that explains the limitations of the `genDefunSymbols` function that were observed in #429. 2. The "Supported Haskell constructs" section has received some more love. Some Haskell features were inaccurately characterized (e.g., pattern signatures are really only partially supported), so I also reorganized some of the bullet points. I have also added a new bullet point for `ScopedTypeVariables` under the "Little to no support" section, as #433 reveals that promoting functions that rely on the behavior of `ScopedTypeVariables` is terribly fragile (and not easy to fix). 3. Lots of little formatting and grammar fixes to make the prose in the `README` flow better. Note that this patch does _not_ fix either of #429 or #433—it just documents the rather unsatisfying current state of affairs.
I briefly looked into implementing this, but it turned out to be much more work than I originally had expected. For now, I'll just document the various corner cases of |
This patch fleshes out some more details about what `singletons` can and can't do in its `README`. The key changes are: 1. There is a new "Promotion and partial application" section that explains what defunctionalization is in some amount of detail. There is also a new subsection that explains the limitations of the `genDefunSymbols` function that were observed in #429. 2. The "Supported Haskell constructs" section has received some more love. Some Haskell features were inaccurately characterized (e.g., pattern signatures are really only partially supported), so I also reorganized some of the bullet points. I have also added a new bullet point for `ScopedTypeVariables` under the "Little to no support" section, as #433 reveals that promoting functions that rely on the behavior of `ScopedTypeVariables` is terribly fragile (and not easy to fix). 3. Lots of little formatting and grammar fixes to make the prose in the `README` flow better. Note that this patch does _not_ fix either of #429 or #433—it just documents the rather unsatisfying current state of affairs.
) This patch fleshes out some more details about what `singletons` can and can't do in its `README`. The key changes are: 1. There is a new "Promotion and partial application" section that explains what defunctionalization is in some amount of detail. There is also a new subsection that explains the limitations of the `genDefunSymbols` function that were observed in #429. 2. The "Supported Haskell constructs" section has received some more love. Some Haskell features were inaccurately characterized (e.g., pattern signatures are really only partially supported), so I also reorganized some of the bullet points. I have also added a new bullet point for `ScopedTypeVariables` under the "Little to no support" section, as #433 reveals that promoting functions that rely on the behavior of `ScopedTypeVariables` is terribly fragile (and not easy to fix). 3. Lots of little formatting and grammar fixes to make the prose in the `README` flow better. Note that this patch does _not_ fix either of #429 or #433—it just documents the rather unsatisfying current state of affairs.
While pondering the questions in #427 (comment), I realized that trying to document the existing status quo regarding what language constructs are OK to defunctionalize is much, much trickier than I thought. The main source of trickiness is that
singletons
has an inconsistent ruleset: whether something is defunctionalized or not depends on whether it is quoted (i.e.,$(singletons [d| ... |])
) or reified (i.e.,$(genDefunSymbols [...])
):Quoted
Functions
Legal. Just define the function in quotes, e.g.,
And
singletons
will produceFooSym0
andFooSym1
.Classes
Legal, but only in the sense that quoted classes will produce defunctionalization symbols for the promoted class methods and associated type families, e.g.,
Defunctionalization symbols for the class itself are not produced.
Class methods
Legal. See the "Classes" section.
Type families and synonyms
Legal. Quoted type families and synonyms are defunctionalized as you would expect. See also the "Classes" section for how associated type families are handled.
Data types
Legal, but only in the sense that quoted data types will produce defunctionalization symbols for the promoted record selectors and data constructors, e.g.,
Defunctionalization symbols for the data type itself are not produced.
Data constructors
Legal. See the "Data types" section.
Record selectors
Legal. See the "Data types" section.
Reified
Functions
Illegal. Attempting to use
genDefunSymbols
on a function name will throw an error:Classes
Legal. Reified class names will get defunctionalization symbols, but its promoted class methods and associated type families will not be defunctionalized:
Class methods
Illegal. Attempting to use
genDefunSymbols
on a class method name will throw an error:Reifying the parent class name will not produce defunctionalization symbols for its promoted class methods either.
Type families and synonyms
Legal. Reified type families and synonyms are defunctionalized as you would expect. Associated type families are not automatically defunctionalized when the parent class name is reified, but one can just as well reify the associated type family name directly.
Data types
Legal, but only in the sense that reified data types will produce defunctionalization symbols for the data constructors, e.g.,
Data constructors
Illegal. Attempting to use
genDefunSymbols
on a data constructor name will throw an error:The only way to defunctionalize data constructor names through reification is to reify the parent data type.
Record selectors
Illegal. Attempting to use
genDefunSymbols
on a record selector name will throw an error:Reifying the parent data type name will not produce defunctionalization symbols for its promoted record selectors either.
There are multiple inconsistencies between quote-based defunctionalization and reification-based defunctionalization:
The text was updated successfully, but these errors were encountered: