-
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
Do singled case
expressions need an explicit kind annotation?
#547
Comments
For some additional background on why I am interested in removing this kind annotation, consider this example: absurd :: forall a. Void -> a
absurd v = case v of {} Currently, this singles to something resembling: sAbsurd :: forall a (v :: Void). Sing v -> Sing (Absurd v :: a)
sAbsurd (sV :: Sing v) = id @(Sing (Case v :: a)) (case sV of {}) Crucially, Now consider what would happen in a variant of absurd' :: Void -> forall a. a
absurd' v = case v of {} If we singled sAbsurd' :: forall (v :: Void). Sing v -> forall a. Sing (Absurd' v :: a)
sAbsurd' (sV :: Sing v) = id @(Sing (Case v :: a)) (case sV of {}) Unfortunately, this is not well scoped. Since the Possible ways to fix this include:
|
… expressions Explicit kind annotations aren't necessary in modern `singletons-th` due to the approach that it uses for singling `case` expressions. This allows us to delete a modest amount of code. Fixes #547.
… expressions Explicit kind annotations aren't necessary in modern `singletons-th` due to the approach that it uses for singling `case` expressions. This allows us to delete a modest amount of code. Fixes #547.
… expressions Explicit kind annotations aren't necessary in modern `singletons-th` due to the approach that it uses for singling `case` expressions. This allows us to delete a modest amount of code. Fixes #547.
… expressions Explicit kind annotations aren't necessary in modern `singletons-th` due to the approach that it uses for singling `case` expressions. This allows us to delete a modest amount of code. Fixes #547.
Previously, `singletons-th` would always attempt to generate instance signatures for singled instance methods, even if the original instance code lacks instance signatures. To do so, `singletons-th` will infer an instance signature by reifying the type of the method (or, if that cannot be found, the singled version of the method) and manually applying a substitution from class variables to instance types. This process is quite involved, and what's more, it doesn't work in all cases: * As noted in #358, inferred instance signatures can sometimes be ill-kinded. * In order to support singling examples like the ones from #581, we need type variables from class method defaults and instance methods to scope over their bodies. However, the approach that `singletons-th` used to reify the method type for the singled code will sometimes reify _different_ type variables than the ones used in the promoted code, leading to disaster. This convention of inferring the instance signature dates all the way back to commit c9beec5, and it's unclear why this choice was made. At the time of writing #358, I was convinced that inferred instance signatures were necessary to support examples like the one in #358 (comment). However, this example is only problematic due to the use of an explicit kind annotation on a promoted `case` expression, and these explicit kind annotations were removed in the fix for #547. As such, this convention no longer serves a useful purpose. This patch removes the instance signature inference code, greatly simplifying the overall process of singling instance declarations. Fixes #590.
Previously, `singletons-th` would always attempt to generate instance signatures for singled instance methods, even if the original instance code lacks instance signatures. To do so, `singletons-th` will infer an instance signature by reifying the type of the method (or, if that cannot be found, the singled version of the method) and manually applying a substitution from class variables to instance types. This process is quite involved, and what's more, it doesn't work in all cases: * As noted in #358, inferred instance signatures can sometimes be ill-kinded. * In order to support singling examples like the ones from #581, we need type variables from class method defaults and instance methods to scope over their bodies. However, the approach that `singletons-th` used to reify the method type for the singled code will sometimes reify _different_ type variables than the ones used in the promoted code, leading to disaster. This convention of inferring the instance signature dates all the way back to commit c9beec5, and it's unclear why this choice was made. At the time of writing #358, I was convinced that inferred instance signatures were necessary to support examples like the one in #358 (comment). However, this example is only problematic due to the use of an explicit kind annotation on a promoted `case` expression, and these explicit kind annotations were removed in the fix for #547. As such, this convention no longer serves a useful purpose. This patch removes the instance signature inference code, greatly simplifying the overall process of singling instance declarations. Fixes #590.
Previously, `singletons-th` would always attempt to generate instance signatures for singled instance methods, even if the original instance code lacks instance signatures. To do so, `singletons-th` will infer an instance signature by reifying the type of the method (or, if that cannot be found, the singled version of the method) and manually applying a substitution from class variables to instance types. This process is quite involved, and what's more, it doesn't work in all cases: * As noted in #358, inferred instance signatures can sometimes be ill-kinded. * In order to support singling examples like the ones from #581, we need type variables from class method defaults and instance methods to scope over their bodies. However, the approach that `singletons-th` used to reify the method type for the singled code will sometimes reify _different_ type variables than the ones used in the promoted code, leading to disaster. This convention of inferring the instance signature dates all the way back to commit c9beec5, and it's unclear why this choice was made. At the time of writing #358, I was convinced that inferred instance signatures were necessary to support examples like the one in #358 (comment). However, this example is only problematic due to the use of an explicit kind annotation on a promoted `case` expression, and these explicit kind annotations were removed in the fix for #547. As such, this convention no longer serves a useful purpose. This patch removes the instance signature inference code, greatly simplifying the overall process of singling instance declarations. Fixes #590.
While pursuing a fix for #542, I uncovered this interesting piece of code:
singletons/singletons-th/src/Data/Singletons/TH/Single.hs
Lines 959 to 965 in c419ece
In particular, the part of interest is the
ret_ty `maybeSigT` res_ki
bit. Why do we need the explicitres_ki
kind annotation? That is, why do we needid @(Sing (t :: k)) e
instead of justid @(Sing t) e
? This is whatNote [Annotate case return type]
has to say:singletons/singletons-th/src/Data/Singletons/TH/Single.hs
Lines 824 to 837 in c419ece
Curiously, this Note never actually discusses the kind annotation portion of the code. As an experiment, I decided to change
ret_ty `maybeSigT` res_ki
in the code to justret_ty
, and everything insingletons-base
and its test suite continued to compile.As historical context, this kind annotation was added in a60b000 in pursuit of a fix for #136. It's possible that this kind annotation was needed at the time, especially since
case
expressions were singled ase :: Sing (t :: k)
rather thanid @(Sing (t :: k)) e
. This is because former interacts with kind generalization differently than the latter—seeNote [The id hack; or, how singletons-th learned to stop worrying and avoid kind generalization]
for the details. Now thatsingletons-th
uses theid
hack, it's quite possible that the kind annotation is no longer required due to the lack of kind generalization.The text was updated successfully, but these errors were encountered: