-
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
Make Sing a type family #393
Conversation
I was initially opposed to the change, but then I realized: the important part of this encoding is that it says
rather than
This means we can still partially apply Would be good to see a mention of this in the docs (or a Note) |
I wonder, would this injectivity annotation make any difference?
|
2e9660d
to
42a8b70
Compare
I've just added a
It wouldn't. Since |
Since this is a nontrivial redesign of some of data instance Sing :: D a -> Type where It now generated this equivalent data type: data SD :: D a -> Type At least, I had previously convinced myself that they were equivalent. But I now realize that there's actually a subtle difference between the two in that the latter type does not have a CUSK! Data family instances don't really have an equivalent of CUSKs, but since data families themselves always have CUSKs, it not too much of a stretch to say that former type does have a CUSK. That being said, given that data (%:~:) :: a :~: b -> Type where
SRefl :: (%:~:) Refl Lacking a CUSK, |
A very quick gander at the code makes this look quite a bit easier than I would have thought. Cool. I'm in full support of this change, unsurprisingly. :) |
Hm, it turns out that @mstksg's {-# LANGUAGE AllowAmbiguousTypes #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE TypeOperators #-}
module Foo where
import Data.Kind
import Data.Singletons
import Data.Singletons.Decide
type Predicate k = k ~> Type
type TyPred = (TyCon1 :: (k -> Type) -> Predicate k)
type Evident = (TyPred Sing :: Predicate k)
type Decide p = forall a. Sing a -> Decision (p @@ a)
class Decidable p where
decide :: Decide p
instance Decidable Evident where
-- decide = Proved . prove @Evident With
(That error message isn't great, but there's a use of This worries me a bit, since I'm not exactly sure how one would port over this code. Thoughts, @mstksg? |
i'll look into it and see. the main issue is using a type family as an instance, right? So We may be able to get around the issue by using a newtype wrapper and writing the instance over that. I'll try to see if I can get something that works. |
Yes, I suspect that recommending the use of a newtype wrapper around |
@mstksg, I've just pushed a change which adds a |
Ping @mstksg. Do note that I'm essentially holding back this PR until I receive some an indication of some kind from you that this will (or won't) work out for your needs, so if you'd like to see this feature land, your feedback would be appreciated :) |
Ah, I was going to look deeper into this last week, but things did come up. It's a bit difficult for me to test right now because I need to set up a pipeline to test with GHC head :) I think if a newtype wrapper or some other workaround is possible, decidable would be okay for it. Overall the ergonomics of general singletons usage is a higher priority for me at this moment! I can't promise a specific day I can get to this, so feel free to move past me if you want to move things along :) |
No worries. I'm not in a huge hurry to merge this, especially since it there's still time before we even see a release candidate of GHC 8.8.1 (we're still in the alpha stage). Also, us folks at the #ghc IRC channel would be happy to help get you set up with a GHC HEAD configuration—it's much less painful than it used to be, I promise :) |
7988d62
to
44581d7
Compare
FWIW, I've pushed a fork of |
Thanks for this :) Looking over the changes, it all seems like a very reasonable interface. The only time someone would need to deal with wrapping is |
Indeed. I've pushed a commit which demonstrates one way to do this. |
44581d7
to
66dc138
Compare
This fixes #318 by switching `Sing` from a data family to a type family. There are several knock-on changes as a result of this switch—refer to `CHANGES.md` for an overview.
Since it's possible to partially apply `Sing`, there's not much utility in having defunctionalization symbols for it.
66dc138
to
7af1953
Compare
Judging from recent comments (especially #393 (comment)) and from the general quiescence of the discussion on this PR, it looks like we have come to a consensus that this is the right approach. In light of this, I'm going to merge this. Please speak up if you feel otherwise! |
This fixes #318 by switching
Sing
from a data family to a type family. There are several knock-on changes as a result of this switch—refer toCHANGES.md
for an overview.