-
Notifications
You must be signed in to change notification settings - Fork 269
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make the TH machinery handle PolyKinds more robustly (#945)
This is a collection of various Template Haskell–related fixes that, when all put together, fixes #917. This does the following: * Rather than use `th-abstraction`'s `datatypeType` function, which strips off important kind information from type arguments, I defined a similar `datatypeTypeKinded` function that preserves kinds when reasonable. * `Control.Lens.Internal.{FieldTH,PrismTH}` is now more careful to use `freeVariablesWellScoped` (from `th-abstraction`) instead of `typeVars` to ensure that the resulting types are well scoped. This is particularly important for poly-kinded types, as the kind variables must always appear before the type variables. * I deleted the `close` function from `Control.Lens.Internal.PrismTH` in favor of `quantifyType` and `quantifyType'`, which I have moved to `Control.Lens.Internal.TH` so that they may be used by `FieldTH` and `PrismTH` alike. Moreover, I now use `quantifyType'` in the definition of `PrismTH.makeClassyPrismClass` so that any type variables bound by the class itself do not get requantified in any class methods. The previous code was not doing this at all, which was just plain wrong.
- Loading branch information
1 parent
aea8831
commit 66e199e
Showing
7 changed files
with
171 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
{-# LANGUAGE CPP #-} | ||
{-# LANGUAGE FlexibleInstances #-} | ||
{-# LANGUAGE FunctionalDependencies #-} | ||
{-# LANGUAGE GADTs #-} | ||
{-# LANGUAGE PolyKinds #-} | ||
{-# LANGUAGE TemplateHaskell #-} | ||
{-# LANGUAGE TypeFamilies #-} | ||
|
||
#if __GLASGOW_HASKELL__ >= 800 && __GLASGOW_HASKELL__ < 806 | ||
{-# LANGUAGE TypeInType #-} | ||
#endif | ||
module T917 where | ||
|
||
import Control.Lens | ||
import Data.Proxy | ||
|
||
#if __GLASGOW_HASKELL__ >= 800 && __GLASGOW_HASKELL__ < 806 | ||
import Data.Kind | ||
#endif | ||
|
||
-- Like Data.Functor.Const, but redfined to ensure that it is poly-kinded | ||
-- across all versions of GHC, not just 8.0+ | ||
newtype Constant a (b :: k) = Constant a | ||
|
||
data T917OneA (a :: k -> *) (b :: k -> *) = MkT917OneA | ||
data T917OneB a b = MkT917OneB (T917OneA a (Const b)) | ||
$(makePrisms ''T917OneB) | ||
|
||
data T917TwoA (a :: k -> *) (b :: k -> *) = MkT917TwoA | ||
data T917TwoB a b = MkT917TwoB (T917TwoA a (Const b)) | ||
$(makeClassyPrisms ''T917TwoB) | ||
|
||
data family T917DataFam (a :: k) | ||
data instance T917DataFam (a :: *) = MkT917DataFam { _unT917DataFam :: Proxy a } | ||
$(makeLenses 'MkT917DataFam) | ||
|
||
#if __GLASGOW_HASKELL__ >= 800 | ||
data T917GadtOne (a :: k) where | ||
MkT917GadtOne :: T917GadtOne (a :: *) | ||
$(makePrisms ''T917GadtOne) | ||
|
||
data T917GadtTwo (a :: k) where | ||
MkT917GadtTwo :: T917GadtTwo (a :: *) | ||
$(makePrisms ''T917GadtTwo) | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters