-
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
Support promoting/singling invisible type patterns #583
Comments
This bumps the `th-desugar` commit in the `cabal.project` file's `source-repository-package` to bring in the changes from `th-desugar-1.17`. Among other things, this version of `th-desugar` adds support for: * Namespace specifiers in fixity declarations * Embedded type expressions and patterns * Invisible type patterns For now, `singletons-th` will error if it encounters any of these constructs. Where appropriate, I have opened issues to track the idea of supporting these language features in `singletons-th`: * For namespace specifiers in fixity declarations, see #582. * Supporting embedded type expressions and patterns seems quite difficult due to `singletons-th`'s policy of only promoting/singling vanilla type signatures (see the `README`), so I have not opened an issue for this. * For invisible type patterns, see #583. This is one step towards preparing a GHC 9.10–compatible release of `singletons` and friends (see #569).
This bumps the `th-desugar` commit in the `cabal.project` file's `source-repository-package` to bring in the changes from `th-desugar-1.17`. Among other things, this version of `th-desugar` adds support for: * Namespace specifiers in fixity declarations * Embedded type expressions and patterns * Invisible type patterns For now, `singletons-th` will error if it encounters any of these constructs. Where appropriate, I have opened issues to track the idea of supporting these language features in `singletons-th`: * For namespace specifiers in fixity declarations, see #582. * Supporting embedded type expressions and patterns seems quite difficult due to `singletons-th`'s policy of only promoting/singling vanilla type signatures (see the `README`), so I have not opened an issue for this. * For invisible type patterns, see #583. This is one step towards preparing a GHC 9.10–compatible release of `singletons` and friends (see #569).
This bumps the `th-desugar` commit in the `cabal.project` file's `source-repository-package` to bring in the changes from `th-desugar-1.17`. Among other things, this version of `th-desugar` adds support for: * Namespace specifiers in fixity declarations * Embedded type expressions and patterns * Invisible type patterns For now, `singletons-th` will error if it encounters any of these constructs. Where appropriate, I have opened issues to track the idea of supporting these language features in `singletons-th`: * For namespace specifiers in fixity declarations, see #582. * Supporting embedded type expressions and patterns seems quite difficult due to `singletons-th`'s policy of only promoting/singling vanilla type signatures (see the `README`), so I have not opened an issue for this. * For invisible type patterns, see #583. This is one step towards preparing a GHC 9.10–compatible release of `singletons` and friends (see #569).
One wrinkle that I foresee is class method defaults. Consider this example: class C a where
m :: forall b. a -> b -> a
m x _ = x Currently, we promote this to: class PC a where
type M (x :: a) (y :: b) :: a
type M x y = MDefault x y
type MDefault :: a -> b -> a
type family MDefault x y where
MDefault x _ = x So far, so good. Now consider this variation: class C a where
m :: forall b. a -> b -> a
m @b x (_ :: b) = x A naïve approach would lead to this promoted definition: class PC a where
type M (x :: a) (y :: b) :: a
type M x y = MDefault x y
type MDefault :: a -> b -> a
type family MDefault x y where
MDefault @b x (_ :: b) = x But this is wrong: we really want to generate this instead: type MDefault :: a -> b -> a
type family MDefault x y where
MDefault @_ @b x (_ :: b) = x In general, we'd need to insert a number of Actually, that's an oversimplification. Inspired by class C b where
m :: forall a. a -> b -> a
m x _ = x Note that class PC b where
type M (x :: a) (y :: b) :: a
type M x y = MDefault x y
type MDefault :: a -> b -> a
type family MDefault x y where
MDefault x (_ :: b) = x This makes it less clear what to do when class C b where
m :: forall a. a -> b -> a
m @a (x :: a) _ = x Two possible options for promoting this to
Option (1) might appear simpler at a first glance, but generating that code would require us to ignore our earlier rule about inserting Option (2), on the other hand, would be more consistent with the example above, since we'd continue to apply the insert- |
#591 takes one step towards option (2), as it ensures that type families like |
After discovering a regression, I've reverted #596 (in #606). As such, we cannot guarantee the order of kind variables for promoted class methods after all. This means that if we wanted to support invisible type patterns in class method defaults, then we would have no choice but to go with option (1). This means that we would need to swizzle around the invisible type patterns to match whatever type variable order Is this doable? Perhaps. But it would be somewhat tedious to do so, and I'm not exactly excited about implementing it. As such, I'm inclined to decide that |
We also can't reliably guarantee the order of type variables for Thinking about this more, this issue is really just a new twist on the old problem of not being able to guarantee the order of type variables, first described in #378. The last update on #378 was that we opted not to promote visible type applications because |
GHC 9.10 introduces the ability to use invisible type patterns. As such, examples like this can now be written:
The question is: can we promote and single these definitions? It seems plausible, given that we can write the following:
We should see if this is doable. See also #565.
The text was updated successfully, but these errors were encountered: