Skip to content

Commit

Permalink
Merge pull request #227 from goldfirere/T199-T220-improve-reification…
Browse files Browse the repository at this point in the history
…-wrt-saks

Improve local reification and desugaring with respect to standalone kind signatures
  • Loading branch information
RyanGlScott authored Jul 13, 2024
2 parents 72e74e1 + c7b4604 commit aeb8931
Show file tree
Hide file tree
Showing 9 changed files with 1,253 additions and 79 deletions.
55 changes: 55 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,61 @@ Version 1.18 [????.??.??]
`\(type a) (x :: a) -> x :: a`) and invisible type patterns (e.g.,
`\ @a (x :: a) -> x :: a`).
* Add a `Quote` instance for `DsM`.
* Add `mapDTVName` and `mapDTVKind` functions, which allow mapping over the
`Name` and `DKind` of a `DTyVarBndr`, respectively.
* Export `substTyVarBndr` from `Language.Haskell.TH.Desugar.Subst`.
* Add a `Language.Haskell.TH.Desugar.Subst.Capturing` module. This exposes
mostly the same API as `Language.Haskell.TH.Desugar.Subst`, except that the
substitution functions in `Language.Haskell.TH.Desugar.Subst.Capturing` do
not avoid capture when subtituting into a @forall@ type. As a result, these
substitution functions are pure rather than monadic.
* Add `dMatchUpSAKWithDecl`, a function that matches up type variable binders
from a standalone kind signature to the corresponding type variable binders
in the type-level declaration's header:

* The type signature for `dMatchUpSAKWithDecl` returns
`[DTyVarBndr ForAllTyFlag]`, where `ForAllTyFlag` is a new data type that
generalizes both `Specificity` and `BndrVis`.
* Add `dtvbForAllTyFlagsToSpecs` and `dtvbForAllTyFlagsToBndrVis` functions,
which allow converting the results of calling `dMatchUpSAKWithDecl` to
`[DTyVarBndrSpec]` or `[DTyVarBndrVis]`, respectively.
* Also add `matchUpSAKWithDecl`, `tvbForAllTyFlagsToSpecs`, and
`tvbForAllTyFlagsToBndrVis` functions, which work over `TyVarBndr` instead
of `DTyVarBndr`.
* Local reifying the type of a data constructor or class method now yields type
signatures with more precise type variable information, as `th-desugar` now
incorporates information from the standalone kind signature (if any) for the
parent data type or class, respectively. For instance, consider the following
data type declaration:

```hs
type P :: forall {k}. k -> Type
data P (a :: k) = MkP
```

In previous versions of `th-desugar`, locally reifying `MkP` would yield the
following type:

```hs
MkP :: forall k (a :: k). P a
```

This was subtly wrong, as `k` is marked as specified (i.e., eligible for
visible type application), not inferred. In `th-desugar-1.18`, however, the
locally reified type will mark `k` as inferred, as expected:

```hs
MkP :: forall {k} (a :: k). P a
```

Similarly, desugaring `MkP` from Template Haskell to `th-desugar` results
in a data constructor with the expected type above.
* As a result of these changes, the type of `dsCon` has changed slightly:

```diff
-dsCon :: DsMonad q => [DTyVarBndrUnit] -> DType -> Con -> q [DCon]
+dsCon :: DsMonad q => [DTyVarBndrSpec] -> DType -> Con -> q [DCon]
```

Version 1.17 [2024.05.12]
-------------------------
Expand Down
4 changes: 4 additions & 0 deletions Language/Haskell/TH/Desugar.hs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,11 @@ module Language.Haskell.TH.Desugar (
unboxedSumNameDegree_maybe, unboxedTupleNameDegree_maybe,
isTypeKindName, typeKindName, bindIP,
mkExtraDKindBinders, dTyVarBndrToDType, changeDTVFlags,
mapDTVName, mapDTVKind,
toposortTyVarsOf, toposortKindVarsOfTvbs,
ForAllTyFlag(..),
tvbForAllTyFlagsToSpecs, tvbForAllTyFlagsToBndrVis, matchUpSAKWithDecl,
dtvbForAllTyFlagsToSpecs, dtvbForAllTyFlagsToBndrVis, dMatchUpSAKWithDecl,

-- ** 'FunArgs' and 'VisFunArg'
FunArgs(..), ForallTelescope(..), VisFunArg(..),
Expand Down
378 changes: 364 additions & 14 deletions Language/Haskell/TH/Desugar/Core.hs

Large diffs are not rendered by default.

Loading

0 comments on commit aeb8931

Please sign in to comment.