-
Notifications
You must be signed in to change notification settings - Fork 269
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 the TH machinery handle PolyKinds more robustly #945
Conversation
I have marked this as an WIP for now since I had to vendor in an unreleased version of |
de857e0
to
f2bc569
Compare
For what it's worth, this is definitely a breaking change, since any code that uses
This isn't a huge breakage, since one can fix it by simply enabling a language extension. But I thought this worth mentioning nonetheless. |
63f1998
to
cfaa3c0
Compare
FWIW when I fixed this in well-typed/optics#313 I only annotated types with kinds involving variables, not monomorphic ones, so that |
I fear that the situation is slightly more complicated than just detecting kind variables. Consider this program: {-# LANGUAGE PolyKinds #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeFamilies #-}
{-# OPTIONS_GHC -ddump-splices #-}
module Foo where
import Control.Lens
import Data.Kind
import Data.Proxy
data family DF (a :: k)
data instance DF (a :: Type) = MkDF { _unDF :: Proxy a }
$(makeLenses 'MkDF) If you generate this code without any kind signatures, you'll get the following:
This won't typecheck:
This is because unDF ::
forall (a_a2sl :: Type) (a_a3YQ :: Type).
Iso (DF (a_a2sl :: Type)) (DF (a_a3YQ :: Type)) (Proxy a_a2sl) (Proxy a_a3YQ)
unDF = (iso (\ (MkDF x_a3YR) -> x_a3YR)) MkDF
{-# INLINE unDF #-} That being said, I do see your point about not needing |
I've pushed some changes that alter |
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.
Now that |
This is a collection of various Template Haskell–related fixes that, when all put together, fixes #917. This does the following:
th-abstraction
'sdatatypeType
function, which strips off important kind information from type arguments, I defined a similardatatypeTypeKinded
function that preserves kinds.Control.Lens.Internal.{FieldTH,PrismTH}
is now more careful to usefreeVariablesWellScoped
(fromth-abstraction
) instead oftypeVars
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.close
function fromControl.Lens.Internal.PrismTH
in favor ofquantifyType
andquantifyType'
, which I have moved toControl.Lens.Internal.TH
so that they may be used byFieldTH
andPrismTH
alike. Moreover, I now usequantifyType'
in the definition ofPrismTH.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.