-
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
Overly general kind for PAlternative
#604
Comments
On second thought, option (2) is not as straightforward as I thought. Consider: $(promote [d|
class Supercls (T a) => Cls a where ...
|]) Where class PSupercls (T a) => PCls a where ... But this requires figuring out that Technically, this isn't a new problem, as you would encounter the same thing if you tried to promote a definition like this one: f :: Dict (Supercls (T a)) That being said, |
Actually, I take back what I said above in #604 (comment). We have already solved this problem in the context of singling, since we want to turn things like This approach works well for |
I've tried out the
And similarly for
However, this doesn't affect the kinds of the promoted methods' defunctionalization symbols:
This means that this code still wouldn't work in a future version of GHC where the instantiation of type family instances is fully determined by the left-hand side (see #601). Moreover, it's not clear to me how we could repair the kinds of the defunctionalization symbols, which are defined separately from the As such, I think the only way to truly fix this issue would be option (1) from #604 (comment). It's a bit sad, but oh well. We should also make sure to audit other classes in |
Besides
|
In particular, make note of the circumstances under which issues like #604. There is no way for `singletons-th` to generate code that avoids the problems in #604 in all cases, so we instead advise users to be wary when promoting code involving classes that are parameterized over higher-kinded type variables (e.g., `Alternative`).
Previously, `singletons-th` would generalize the kinds of `PAlternative` and related classes (e.g., `PMonadPlus`), as well of the kinds of the defunctionalization symbols for various classes that are parameterized over a higher-kinded type variable. As described in the "Class constraints" section of the `README.md`, the recommended workaround for this issue is to give the classes in question explicit kinds, so this patch does just that by giving `Alternative`, `MonadPlus`, etc. standalone kind signatures. This causes the code in `singletons-base` to deviate a bit from the original code in the `base` library. I have written a new `Note [Using standalone kind signatures not present in the base library]` and cited it in all of the places where such a deviation occurs. Fixes #604.
In particular, make note of the circumstances under which issues like #604. There is no way for `singletons-th` to generate code that avoids the problems in #604 in all cases, so we instead advise users to be wary when promoting code involving classes that are parameterized over higher-kinded type variables (e.g., `Alternative`).
Previously, `singletons-th` would generalize the kinds of `PAlternative` and related classes (e.g., `PMonadPlus`), as well of the kinds of the defunctionalization symbols for various classes that are parameterized over a higher-kinded type variable. As described in the "Class constraints" section of the `README.md`, the recommended workaround for this issue is to give the classes in question explicit kinds, so this patch does just that by giving `Alternative`, `MonadPlus`, etc. standalone kind signatures. This causes the code in `singletons-base` to deviate a bit from the original code in the `base` library. I have written a new `Note [Using standalone kind signatures not present in the base library]` and cited it in all of the places where such a deviation occurs. Fixes #604.
The kind of
PAlternative
should be(Type -> Type) -> Constraint
, but it is instead:We should fix this. Two possible ways to do so:
When promoting the
Alternative
class, givef
an explicit kind signature, i.e.,We may need to do this anyway as part of Make
singletons
buildable after GHC#23515 #601.Currently, when
singletons-th
promotes a class definition, it omits the superclasses, as they aren't needed at the type level. This does hav one drawback, however: we do not benefit from any kind information that the superclasses might have. In the specific example ofAlternative
, its superclassApplicative
is promoted to something with the correct kind:Therefore, if we promoted the definition of
Alternative
to something like this:Then GHC's kind inference would be able to figure out that
f
should be of kindType -> Type
.I'm inclined to try option (2) first, but option (1) may also be worth doing (if not now, then as part of #601).
The text was updated successfully, but these errors were encountered: