Skip to content
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 singling preserve type variable order in type signatures #408

Merged
merged 1 commit into from
Sep 6, 2019

Conversation

RyanGlScott
Copy link
Collaborator

This patch tweaks singType (and its sister function singCtor) to produce type signatures that preserve the order in which type variables appear. For instance, if one writes this:

const2 :: forall b a. a -> b -> a

Then its singled counterpart will now quantify b and a in the same order:

sConst2 :: forall b a (x :: a) (y :: b). Sing x -> Sing y -> Sing (Const2 x y)

This is important if one wants to combine sConst2 with visible type applications, as this means that the meaning of @T1 @T2 in const @T1 @T2 will be preserved when one writes sConst2 @T1 @T2. This also paves the way for #378, which seeks to fully support promoting/singling type applications in the TH machinery.

Most of the interesting parts of this patch are described in Note [Preserve the order of type variables during singling] in D.S.Single.Type, so start that is a good starting point when looking at this patch for the first time.

Fixes chunk (1) in #378 (comment), but there are still other parts of #378 that remain to be fixed.

Copy link
Owner

@goldfirere goldfirere left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks very good. Some small suggestions for marginal improvement herein. Thanks!

src/Data/Singletons/Single/Type.hs Show resolved Hide resolved
src/Data/Singletons/Single/Type.hs Show resolved Hide resolved
src/Data/Singletons/Single/Data.hs Show resolved Hide resolved
src/Data/Singletons/Single/Type.hs Outdated Show resolved Hide resolved
src/Data/Singletons/Single/Type.hs Show resolved Hide resolved
src/Data/Singletons/Single/Type.hs Show resolved Hide resolved
This patch tweaks `singType` (and its sister function `singCtor`) to
produce type signatures that preserve the order in which type
variables appear. For instance, if one writes this:

```hs
const2 :: forall b a. a -> b -> a
```

Then its singled counterpart will now quantify `b` and `a` in the
same order:

```hs
sConst2 :: forall b a (x :: a) (y :: b). Sing x -> Sing y -> Sing (Const2 x y)
```

This is important if one wants to combine `sConst2` with visible type
applications, as this means that the meaning of `@T1 @T2` in
`const @t1 @T2` will be preserved when one writes `sConst2 @t1 @T2`.
This also paves the way for #378, which seeks to fully support
promoting/singling type applications in the TH machinery.

Most of the interesting parts of this patch are described in
`Note [Preserve the order of type variables during singling]`
in `D.S.Single.Type`, so start that is a good starting point when
looking at this patch for the first time.

Fixes chunk (1) in
#378 (comment),
but there are still other parts of #378 that remain to be fixed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants