-
Notifications
You must be signed in to change notification settings - Fork 9
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
On generating singletons for Idx (a.k.a. Fin) #2
Comments
Thanks. I made a branch for experimenting called promote-fin. The file that has the definition for Idx is SubstScoped.hs. I had trouble defining Idx separately from Nat, I was getting these errors:
Should Nat produce them? Or do I need another option? |
Interesting. If I'm reading that correctly, the issue is not due to challenge/debruijn/src/SubstScoped.hs Lines 42 to 48 in b5bb206
In order to produce singled versions of these functions, we need to single the diff --git a/debruijn/src/SubstScoped.hs b/debruijn/src/SubstScoped.hs
index aae6be4..092a61b 100644
--- a/debruijn/src/SubstScoped.hs
+++ b/debruijn/src/SubstScoped.hs
@@ -14,6 +14,9 @@ import Data.Singletons.TH.Options
-- are used to describe the number of free variables allowed in
-- a term.
+$(withOptions defaultOptions{genSingKindInsts = False} $
+ genSingletons [''SNat])
+
$(withOptions defaultOptions{genSingKindInsts = False} $
singletons $ lift [d|
(As a side note, it would be great if we didn't have to generate singletons for singletons. See goldfirere/singletons#460 for a discussion on how this might be improved.) Unfortunately, that doesn't solve all of our problems. While the old error messages should go away, new ones take their place. They all have the same general shape:
The root cause of these errors is that the type of Unfortunately, I don't have a quick-and-dirty fix this time, so I suppose this means that I have failed the challenge. Oh well. At this point, I can only speculate on ways that I could improve Just as I added an option to disable generating The challenge/debruijn/src/SubstScoped.hs Line 67 in b5bb206
Is there any hope of supporting type-family-returning functions in today's
I apologize if that was more information than you wanted. This turned out to be much trickier than I expected it would be! (That makes it a good challenge, I suppose.) |
Thanks, Ryan this is fascinating. Is there a way to rewrite SubstScoped so that it plays better with singletons? |
I don't know what this code will look like when it's finished, so I don't know how detailed of an answer I can give. I can at least give some generic advice that I have used in the past to deal with especially fancy
Using |
Thanks Ryan. I'll close this now as I don't see a way forward. |
This isn't a bug report so much as a response to a challenge you posed during your Chalmers FP talk. And who am I to back down from a challenge? :)
If I understood you correctly, the reason that
VarTy
is defined like it is below:challenge/debruijn/src/Poly.hs
Line 11 in e9ef4d4
Is due to a restriction in
singletons
. That is,VarTy
uses a "simply typed"Idx
(which is just a synonym forNat
) since it promoted/singles more easily usingsingletons
' TH machinery. The drawback of this approach is thatVarTy
doesn't track the scope of type variables inTy
s. This would be possible if a "richly typed" version ofIdx
were used instead:challenge/debruijn/src/SubstScoped.hs
Lines 15 to 17 in e9ef4d4
However, this doesn't play nicely with
singletons
' TH machinery out of the box, making it inconvenient to use. (Did I summarize that accurately? If not, that makes the rest of this moot.)The good news is that
singletons-2.7
(which requires GHC 8.10 or later) has a configurable setting that makes automatically promoting/singlingIdx
possible. The challenge with handling GADTs is that the TH machinery will try to generate an instance of theSingKind
class. Unfortunately,SingKind
's current design isn't well suited to dealing with GADTs. Luckily, you can disable the generation ofSingKind
instances altogether by usingData.Singletons.TH.Options
, like so:Not having a
SingKind
instance forIdx n
may impact your library, however, since thetoSing
method ofSingKind
is used in a couple of places. If so, you can always roll your own version oftoSing
fairly easily:I haven't attempted to use the "richly typed" version of
Idx
inVarTy
, as I'm unclear what sort of repercussions that would have on the rest of the design. But this should hopefully demonstrate that it is at least possible!The text was updated successfully, but these errors were encountered: