GHC issueshttps://gitlab.haskell.org/ghc/ghc/-/issues2019-07-07T18:13:50Zhttps://gitlab.haskell.org/ghc/ghc/-/issues/15195Merge -XPolyKinds with -XTypeInType2019-07-07T18:13:50ZRichard Eisenbergrae@richarde.devMerge -XPolyKinds with -XTypeInTypeAs described in [this accepted proposal](https://github.com/ghc-proposals/ghc-proposals/blob/master/proposals/0020-no-type-in-type.rst).
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ------------...As described in [this accepted proposal](https://github.com/ghc-proposals/ghc-proposals/blob/master/proposals/0020-no-type-in-type.rst).
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | ------------ |
| Version | 8.2.2 |
| Type | Bug |
| TypeOfFailure | OtherFailure |
| Priority | normal |
| Resolution | Unresolved |
| Component | Compiler |
| Test case | |
| Differential revisions | |
| BlockedBy | |
| Related | |
| Blocking | |
| CC | |
| Operating system | |
| Architecture | |
</details>
<!-- {"blocked_by":[],"summary":"Merge -XPolyKinds with -XTypeInType","status":"New","operating_system":"","component":"Compiler","related":[],"milestone":"8.6.1","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"8.2.2","keywords":[],"differentials":[],"test_case":"","architecture":"","cc":[""],"type":"Bug","description":"As described in [https://github.com/ghc-proposals/ghc-proposals/blob/master/proposals/0020-no-type-in-type.rst this accepted proposal].","type_of_failure":"OtherFailure","blocking":[]} -->8.6.1Vladislav ZavialovVladislav Zavialovhttps://gitlab.haskell.org/ghc/ghc/-/issues/15170GHC HEAD panic (dischargeFmv)2019-07-07T18:13:56ZRyan ScottGHC HEAD panic (dischargeFmv)The following program panics on GHC HEAD:
```hs
{-# LANGUAGE AllowAmbiguousTypes #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariable...The following program panics on GHC HEAD:
```hs
{-# LANGUAGE AllowAmbiguousTypes #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilyDependencies #-}
{-# LANGUAGE TypeInType #-}
{-# LANGUAGE TypeOperators #-}
module Bug where
import Data.Kind
import Data.Proxy
data family Sing (a :: k)
data SomeSing :: Type -> Type where
SomeSing :: Sing (a :: k) -> SomeSing k
class SingKind k where
type Demote k = (r :: Type) | r -> k
fromSing :: Sing (a :: k) -> Demote k
toSing :: Demote k -> SomeSing k
withSomeSing :: forall k r
. SingKind k
=> Demote k
-> (forall (a :: k). Sing a -> r)
-> r
withSomeSing x f =
case toSing x of
SomeSing x' -> f x'
newtype instance Sing (f :: k1 ~> k2) =
SLambda { applySing :: forall t. Sing t -> Sing (f @@ t) }
instance (SingKind k1, SingKind k2) => SingKind (k1 ~> k2) where
type Demote (k1 ~> k2) = Demote k1 -> Demote k2
fromSing sFun x = withSomeSing x (fromSing . applySing sFun)
toSing = undefined
data TyFun :: Type -> Type -> Type
type a ~> b = TyFun a b -> Type
infixr 0 ~>
type family Apply (f :: k1 ~> k2) (x :: k1) :: k2
type f @@ x = Apply f x
infixl 9 @@
dcomp :: forall (a :: Type)
(b :: a ~> Type)
(c :: forall (x :: a). Proxy x ~> b @@ x ~> Type)
(f :: forall (x :: a) (y :: b @@ x). Proxy x ~> Proxy y ~> c @@ ('Proxy :: Proxy x) @@ y)
(g :: forall (x :: a). Proxy x ~> b @@ x)
(x :: a).
SingKind (c @@ ('Proxy :: Proxy x) @@ (g @@ ('Proxy :: Proxy x)))
=> (forall (xx :: a) (yy :: b @@ xx). Sing (f @@ ('Proxy :: Proxy xx) @@ ('Proxy :: Proxy yy)))
-> Sing g
-> Sing a
-> Demote (c @@ ('Proxy :: Proxy x) @@ (g @@ ('Proxy :: Proxy x)))
dcomp _sf _ _ = undefined
```
```
$ /opt/ghc/head/bin/ghc Bug2.hs
[1 of 1] Compiling Bug ( Bug2.hs, Bug2.o )
ghc: panic! (the 'impossible' happened)
(GHC version 8.5.20180501 for x86_64-unknown-linux):
dischargeFmv
[D] _ {0}:: (Apply
(f_a1ih[sk:2] xx_a1iA[tau:3] yy_a1iB[tau:3] |> Sym ((TyFun
<Proxy xx_a1iA[tau:3]>_N
((TyFun
(Proxy
(Sym {co_a1jm})
(Coh <yy_a1iB[tau:3]>_N
{co_a1jm}))_N
(Sym {co_a1jB} ; (Apply
(Sym {co_a1jm})
<*>_N
(Coh ((Coh <s_a1jn[fmv:0]>_N
((TyFun
(Sym {co_a1jm})
<*>_N)_N
->_N <*>_N) ; Sym {co_a1jA}) ; (Apply
<Proxy
xx_a1iA[tau:3]>_N
((TyFun
(Sym {co_a1jm})
<*>_N)_N
->_N <*>_N)
(Coh <c_a1ig[sk:2] xx_a1iA[tau:3]>_N
(Sym ((TyFun
<Proxy
xx_a1iA[tau:3]>_N
((TyFun
(Sym {co_a1jm})
<*>_N)_N
->_N <*>_N))_N
->_N <*>_N)))
<'Proxy>_N)_N)
(Sym ((TyFun
(Sym {co_a1jm})
<*>_N)_N
->_N <*>_N)))
(Coh <yy_a1iB[tau:3]>_N
{co_a1jm}))_N))_N
->_N <*>_N))_N
->_N <*>_N))
'Proxy :: (Proxy (yy_a1iB[tau:3] |> {co_a1jm}) ~> s_a1jp[fmv:0]))
~# (s_a1jQ[fmv:0] :: (Proxy (yy_a1iB[tau:3] |> {co_a1jm})
~> s_a1jp[fmv:0]))
Call stack:
CallStack (from HasCallStack):
callStackDoc, called at compiler/utils/Outputable.hs:1162:37 in ghc:Outputable
pprPanic, called at compiler/typecheck/TcSMonad.hs:3047:25 in ghc:TcSMonad
```
On GHC 8.4.2, it simply throws an error:
```
$ /opt/ghc/8.4.2/bin/ghci Bug2.hs
GHCi, version 8.4.2: http://www.haskell.org/ghc/ :? for help
Loaded GHCi configuration from /home/rgscott/.ghci
[1 of 1] Compiling Bug ( Bug2.hs, interpreted )
Bug2.hs:53:71: error:
• Expected kind ‘Apply b xx’, but ‘y’ has kind ‘b @@ x’
• In the first argument of ‘Proxy’, namely ‘y’
In the first argument of ‘(~>)’, namely ‘Proxy y’
In the second argument of ‘(~>)’, namely
‘Proxy y ~> c @@ ( 'Proxy :: Proxy x) @@ y’
|
53 | (f :: forall (x :: a) (y :: b @@ x). Proxy x ~> Proxy y ~> c @@ ('Proxy :: Proxy x) @@ y)
| ^
```
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | ----------------------- |
| Version | 8.5 |
| Type | Bug |
| TypeOfFailure | OtherFailure |
| Priority | normal |
| Resolution | Unresolved |
| Component | Compiler (Type checker) |
| Test case | |
| Differential revisions | |
| BlockedBy | |
| Related | |
| Blocking | |
| CC | |
| Operating system | |
| Architecture | |
</details>
<!-- {"blocked_by":[],"summary":"GHC HEAD panic (dischargeFmv)","status":"New","operating_system":"","component":"Compiler (Type checker)","related":[],"milestone":"8.6.1","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"8.5","keywords":["TypeInType"],"differentials":[],"test_case":"","architecture":"","cc":[""],"type":"Bug","description":"The following program panics on GHC HEAD:\r\n\r\n{{{#!hs\r\n{-# LANGUAGE AllowAmbiguousTypes #-}\r\n{-# LANGUAGE FlexibleContexts #-}\r\n{-# LANGUAGE FlexibleInstances #-}\r\n{-# LANGUAGE GADTs #-}\r\n{-# LANGUAGE RankNTypes #-}\r\n{-# LANGUAGE ScopedTypeVariables #-}\r\n{-# LANGUAGE TypeApplications #-}\r\n{-# LANGUAGE TypeFamilyDependencies #-}\r\n{-# LANGUAGE TypeInType #-}\r\n{-# LANGUAGE TypeOperators #-}\r\nmodule Bug where\r\n\r\nimport Data.Kind\r\nimport Data.Proxy\r\n\r\ndata family Sing (a :: k)\r\ndata SomeSing :: Type -> Type where\r\n SomeSing :: Sing (a :: k) -> SomeSing k\r\n\r\nclass SingKind k where\r\n type Demote k = (r :: Type) | r -> k\r\n fromSing :: Sing (a :: k) -> Demote k\r\n toSing :: Demote k -> SomeSing k\r\n\r\nwithSomeSing :: forall k r\r\n . SingKind k\r\n => Demote k\r\n -> (forall (a :: k). Sing a -> r)\r\n -> r\r\nwithSomeSing x f =\r\n case toSing x of\r\n SomeSing x' -> f x'\r\n\r\nnewtype instance Sing (f :: k1 ~> k2) =\r\n SLambda { applySing :: forall t. Sing t -> Sing (f @@ t) }\r\n\r\ninstance (SingKind k1, SingKind k2) => SingKind (k1 ~> k2) where\r\n type Demote (k1 ~> k2) = Demote k1 -> Demote k2\r\n fromSing sFun x = withSomeSing x (fromSing . applySing sFun)\r\n toSing = undefined\r\n\r\ndata TyFun :: Type -> Type -> Type\r\ntype a ~> b = TyFun a b -> Type\r\ninfixr 0 ~>\r\n\r\ntype family Apply (f :: k1 ~> k2) (x :: k1) :: k2\r\ntype f @@ x = Apply f x\r\ninfixl 9 @@\r\n\r\ndcomp :: forall (a :: Type)\r\n (b :: a ~> Type)\r\n (c :: forall (x :: a). Proxy x ~> b @@ x ~> Type)\r\n (f :: forall (x :: a) (y :: b @@ x). Proxy x ~> Proxy y ~> c @@ ('Proxy :: Proxy x) @@ y)\r\n (g :: forall (x :: a). Proxy x ~> b @@ x)\r\n (x :: a).\r\n SingKind (c @@ ('Proxy :: Proxy x) @@ (g @@ ('Proxy :: Proxy x)))\r\n => (forall (xx :: a) (yy :: b @@ xx). Sing (f @@ ('Proxy :: Proxy xx) @@ ('Proxy :: Proxy yy)))\r\n -> Sing g\r\n -> Sing a\r\n -> Demote (c @@ ('Proxy :: Proxy x) @@ (g @@ ('Proxy :: Proxy x)))\r\ndcomp _sf _ _ = undefined\r\n}}}\r\n{{{\r\n$ /opt/ghc/head/bin/ghc Bug2.hs\r\n[1 of 1] Compiling Bug ( Bug2.hs, Bug2.o )\r\nghc: panic! (the 'impossible' happened)\r\n (GHC version 8.5.20180501 for x86_64-unknown-linux):\r\n dischargeFmv\r\n [D] _ {0}:: (Apply\r\n (f_a1ih[sk:2] xx_a1iA[tau:3] yy_a1iB[tau:3] |> Sym ((TyFun\r\n <Proxy xx_a1iA[tau:3]>_N\r\n ((TyFun\r\n (Proxy\r\n (Sym {co_a1jm})\r\n (Coh <yy_a1iB[tau:3]>_N\r\n {co_a1jm}))_N\r\n (Sym {co_a1jB} ; (Apply\r\n (Sym {co_a1jm})\r\n <*>_N\r\n (Coh ((Coh <s_a1jn[fmv:0]>_N\r\n ((TyFun\r\n (Sym {co_a1jm})\r\n <*>_N)_N\r\n ->_N <*>_N) ; Sym {co_a1jA}) ; (Apply\r\n <Proxy\r\n xx_a1iA[tau:3]>_N\r\n ((TyFun\r\n (Sym {co_a1jm})\r\n <*>_N)_N\r\n ->_N <*>_N)\r\n (Coh <c_a1ig[sk:2] xx_a1iA[tau:3]>_N\r\n (Sym ((TyFun\r\n <Proxy\r\n xx_a1iA[tau:3]>_N\r\n ((TyFun\r\n (Sym {co_a1jm})\r\n <*>_N)_N\r\n ->_N <*>_N))_N\r\n ->_N <*>_N)))\r\n <'Proxy>_N)_N)\r\n (Sym ((TyFun\r\n (Sym {co_a1jm})\r\n <*>_N)_N\r\n ->_N <*>_N)))\r\n (Coh <yy_a1iB[tau:3]>_N\r\n {co_a1jm}))_N))_N\r\n ->_N <*>_N))_N\r\n ->_N <*>_N))\r\n 'Proxy :: (Proxy (yy_a1iB[tau:3] |> {co_a1jm}) ~> s_a1jp[fmv:0]))\r\n ~# (s_a1jQ[fmv:0] :: (Proxy (yy_a1iB[tau:3] |> {co_a1jm})\r\n ~> s_a1jp[fmv:0]))\r\n Call stack:\r\n CallStack (from HasCallStack):\r\n callStackDoc, called at compiler/utils/Outputable.hs:1162:37 in ghc:Outputable\r\n pprPanic, called at compiler/typecheck/TcSMonad.hs:3047:25 in ghc:TcSMonad\r\n}}}\r\n\r\nOn GHC 8.4.2, it simply throws an error:\r\n\r\n{{{\r\n$ /opt/ghc/8.4.2/bin/ghci Bug2.hs\r\nGHCi, version 8.4.2: http://www.haskell.org/ghc/ :? for help\r\nLoaded GHCi configuration from /home/rgscott/.ghci\r\n[1 of 1] Compiling Bug ( Bug2.hs, interpreted )\r\n\r\nBug2.hs:53:71: error:\r\n • Expected kind ‘Apply b xx’, but ‘y’ has kind ‘b @@ x’\r\n • In the first argument of ‘Proxy’, namely ‘y’\r\n In the first argument of ‘(~>)’, namely ‘Proxy y’\r\n In the second argument of ‘(~>)’, namely\r\n ‘Proxy y ~> c @@ ( 'Proxy :: Proxy x) @@ y’\r\n |\r\n53 | (f :: forall (x :: a) (y :: b @@ x). Proxy x ~> Proxy y ~> c @@ ('Proxy :: Proxy x) @@ y)\r\n | ^\r\n}}}","type_of_failure":"OtherFailure","blocking":[]} -->8.6.1https://gitlab.haskell.org/ghc/ghc/-/issues/15142GHC HEAD regression: tcTyVarDetails2019-07-07T18:14:05ZRyan ScottGHC HEAD regression: tcTyVarDetailsThis regression prevents the `generic-lens` library from building. Here is a minimized test case:
```hs
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeInType #-}
module Bug where
import Data.Kind
...This regression prevents the `generic-lens` library from building. Here is a minimized test case:
```hs
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeInType #-}
module Bug where
import Data.Kind
class ListTuple (tuple :: Type) (as :: [(k, Type)]) where
type ListToTuple as :: Type
```
On GHC 8.4.2, this compiles, but on GHC HEAD, it panics:
```
$ ~/Software/ghc/inplace/bin/ghc-stage2 Bug.hs[1 of 1] Compiling Bug ( Bug.hs, Bug.o )
ghc-stage2: panic! (the 'impossible' happened)
(GHC version 8.5.20180511 for x86_64-unknown-linux):
tcTyVarDetails
co_aWx :: (k_aWt[tau:2] :: *) ~# (* :: *)
Call stack:
CallStack (from HasCallStack):
callStackDoc, called at compiler/utils/Outputable.hs:1162:37 in ghc:Outputable
pprPanic, called at compiler/basicTypes/Var.hs:497:22 in ghc:Var
```
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | ----------------------- |
| Version | 8.5 |
| Type | Bug |
| TypeOfFailure | OtherFailure |
| Priority | highest |
| Resolution | Unresolved |
| Component | Compiler (Type checker) |
| Test case | |
| Differential revisions | |
| BlockedBy | |
| Related | |
| Blocking | |
| CC | |
| Operating system | |
| Architecture | |
</details>
<!-- {"blocked_by":[],"summary":"GHC HEAD regression: tcTyVarDetails","status":"New","operating_system":"","component":"Compiler (Type checker)","related":[],"milestone":"8.6.1","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"8.5","keywords":["TypeFamilies","TypeInType,"],"differentials":[],"test_case":"","architecture":"","cc":[""],"type":"Bug","description":"This regression prevents the `generic-lens` library from building. Here is a minimized test case:\r\n\r\n{{{#!hs\r\n{-# LANGUAGE MultiParamTypeClasses #-}\r\n{-# LANGUAGE TypeFamilies #-}\r\n{-# LANGUAGE TypeInType #-}\r\nmodule Bug where\r\n\r\nimport Data.Kind\r\n\r\nclass ListTuple (tuple :: Type) (as :: [(k, Type)]) where\r\n type ListToTuple as :: Type\r\n}}}\r\n\r\nOn GHC 8.4.2, this compiles, but on GHC HEAD, it panics:\r\n\r\n{{{\r\n$ ~/Software/ghc/inplace/bin/ghc-stage2 Bug.hs[1 of 1] Compiling Bug ( Bug.hs, Bug.o )\r\nghc-stage2: panic! (the 'impossible' happened)\r\n (GHC version 8.5.20180511 for x86_64-unknown-linux):\r\n tcTyVarDetails\r\n co_aWx :: (k_aWt[tau:2] :: *) ~# (* :: *)\r\n Call stack:\r\n CallStack (from HasCallStack):\r\n callStackDoc, called at compiler/utils/Outputable.hs:1162:37 in ghc:Outputable\r\n pprPanic, called at compiler/basicTypes/Var.hs:497:22 in ghc:Var\r\n}}}","type_of_failure":"OtherFailure","blocking":[]} -->8.6.1Richard Eisenbergrae@richarde.devRichard Eisenbergrae@richarde.devhttps://gitlab.haskell.org/ghc/ghc/-/issues/15122GHC HEAD typechecker regression2019-07-07T18:14:10ZfmixingGHC HEAD typechecker regressionThis code, distilled from the `type-level-sets` library:
```hs
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeInType #-}
{-# LANGUAGE TypeO...This code, distilled from the `type-level-sets` library:
```hs
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeInType #-}
{-# LANGUAGE TypeOperators #-}
module Bug where
data Proxy (p :: k) = Proxy
data Set (n :: [k]) where
Empty :: Set '[]
Ext :: e -> Set s -> Set (e ': s)
type family (m :: [k]) :\ (x :: k) :: [k] where
'[] :\ x = '[]
(x ': xs) :\ x = xs
(y ': xs) :\ x = y ': (xs :\ x)
class Remove s t where
remove :: Set s -> Proxy t -> Set (s :\ t)
instance Remove '[] t where
remove Empty Proxy = Empty
instance {-# OVERLAPS #-} Remove (x ': xs) x where
remove (Ext _ xs) Proxy = xs
instance {-# OVERLAPPABLE #-} (((y : xs) :\ x) ~ (y : (xs :\ x)), Remove xs x)
=> Remove (y ': xs) x where
remove (Ext y xs) (x@Proxy) = Ext y (remove xs x)
```
Typechecks in GHC 8.4.2, but not in GHC HEAD:
```
$ /opt/ghc/head/bin/ghc Bug.hs
[1 of 1] Compiling Bug ( Bug.hs, Bug.o )
Bug.hs:31:33: error:
• Could not deduce: ((e : s) :\ x) ~ (e : (s :\ x))
from the context: (((y : xs) :\ x) ~ (y : (xs :\ x)), Remove xs x)
bound by the instance declaration at Bug.hs:(29,31)-(30,27)
or from: (k ~ *, (y : xs :: [k]) ~~ (e : s :: [*]))
bound by a pattern with constructor:
Ext :: forall e (s :: [*]). e -> Set s -> Set (e : s),
in an equation for ‘remove’
at Bug.hs:31:11-18
Expected type: Set ((y : xs) :\ x)
Actual type: Set (e : (s :\ x))
• In the expression: Ext y (remove xs x)
In an equation for ‘remove’:
remove (Ext y xs) (x@Proxy) = Ext y (remove xs x)
In the instance declaration for ‘Remove (y : xs) x’
• Relevant bindings include
x :: Proxy x (bound at Bug.hs:31:22)
xs :: Set s (bound at Bug.hs:31:17)
y :: e (bound at Bug.hs:31:15)
remove :: Set (y : xs) -> Proxy x -> Set ((y : xs) :\ x)
(bound at Bug.hs:31:3)
|
31 | remove (Ext y xs) (x@Proxy) = Ext y (remove xs x)
| ^^^^^^^^^^^^^^^^^^^
```
This regression was introduced in commit e3dbb44f53b2f9403d20d84e27f187062755a089 (Fix #12919 by making the flattener homegeneous.).8.6.1https://gitlab.haskell.org/ghc/ghc/-/issues/15116GHC internal error when GADT return type mentions its own constructor name2019-07-07T18:14:11ZRyan ScottGHC internal error when GADT return type mentions its own constructor nameTake the following program:
```hs
{-# LANGUAGE GADTs #-}
{-# LANGUAGE TypeInType #-}
module Bug where
data A (a :: k) where
MkA :: A MkA
```
On GHC 8.4.2, this is rejected with a sensible error message:
```
$ /opt/ghc/8.4.2/bin/ghc...Take the following program:
```hs
{-# LANGUAGE GADTs #-}
{-# LANGUAGE TypeInType #-}
module Bug where
data A (a :: k) where
MkA :: A MkA
```
On GHC 8.4.2, this is rejected with a sensible error message:
```
$ /opt/ghc/8.4.2/bin/ghc Bug.hs
[1 of 1] Compiling Bug ( Bug.hs, Bug.o )
Bug.hs:6:12: error:
• Data constructor ‘MkA’ cannot be used here
(it is defined and used in the same recursive group)
• In the first argument of ‘A’, namely ‘MkA’
In the type ‘A MkA’
In the definition of data constructor ‘MkA’
|
6 | MkA :: A MkA
| ^^^
```
On GHC HEAD, however, this causes a GHC internal error:
```
$ ghc2/inplace/bin/ghc-stage2 Bug.hs
[1 of 1] Compiling Bug ( Bug.hs, Bug.o )
Bug.hs:6:12: error:
• GHC internal error: ‘MkA’ is not in scope during type checking, but it passed the renamer
tcl_env of environment: [asv :-> Type variable ‘k’ = k :: *,
asw :-> Type variable ‘a’ = a :: k,
rqs :-> ATcTyCon A :: forall k. k -> *]
• In the first argument of ‘A’, namely ‘MkA’
In the type ‘A MkA’
In the definition of data constructor ‘MkA’
|
6 | MkA :: A MkA
| ^^^
```
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | ----------------------- |
| Version | 8.5 |
| Type | Bug |
| TypeOfFailure | OtherFailure |
| Priority | normal |
| Resolution | Unresolved |
| Component | Compiler (Type checker) |
| Test case | |
| Differential revisions | |
| BlockedBy | |
| Related | |
| Blocking | |
| CC | |
| Operating system | |
| Architecture | |
</details>
<!-- {"blocked_by":[],"summary":"GHC internal error when GADT return type mentions its own constructor name","status":"New","operating_system":"","component":"Compiler (Type checker)","related":[],"milestone":"8.6.1","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"8.5","keywords":["GADTs,","TypeInType"],"differentials":[],"test_case":"","architecture":"","cc":[""],"type":"Bug","description":"Take the following program:\r\n\r\n{{{#!hs\r\n{-# LANGUAGE GADTs #-}\r\n{-# LANGUAGE TypeInType #-}\r\nmodule Bug where\r\n\r\ndata A (a :: k) where\r\n MkA :: A MkA\r\n}}}\r\n\r\nOn GHC 8.4.2, this is rejected with a sensible error message:\r\n\r\n{{{\r\n$ /opt/ghc/8.4.2/bin/ghc Bug.hs\r\n[1 of 1] Compiling Bug ( Bug.hs, Bug.o )\r\n\r\nBug.hs:6:12: error:\r\n • Data constructor ‘MkA’ cannot be used here\r\n (it is defined and used in the same recursive group)\r\n • In the first argument of ‘A’, namely ‘MkA’\r\n In the type ‘A MkA’\r\n In the definition of data constructor ‘MkA’\r\n |\r\n6 | MkA :: A MkA\r\n | ^^^\r\n}}}\r\n\r\nOn GHC HEAD, however, this causes a GHC internal error:\r\n\r\n{{{\r\n$ ghc2/inplace/bin/ghc-stage2 Bug.hs\r\n[1 of 1] Compiling Bug ( Bug.hs, Bug.o )\r\n\r\nBug.hs:6:12: error:\r\n • GHC internal error: ‘MkA’ is not in scope during type checking, but it passed the renamer\r\n tcl_env of environment: [asv :-> Type variable ‘k’ = k :: *,\r\n asw :-> Type variable ‘a’ = a :: k,\r\n rqs :-> ATcTyCon A :: forall k. k -> *]\r\n • In the first argument of ‘A’, namely ‘MkA’\r\n In the type ‘A MkA’\r\n In the definition of data constructor ‘MkA’\r\n |\r\n6 | MkA :: A MkA\r\n | ^^^\r\n}}}","type_of_failure":"OtherFailure","blocking":[]} -->8.6.1https://gitlab.haskell.org/ghc/ghc/-/issues/15079GHC HEAD regression: cannot instantiate higher-rank kind2020-10-31T11:08:22ZRyan ScottGHC HEAD regression: cannot instantiate higher-rank kindThe following program typechecks on GHC 8.2.2 and 8.4.2:
```hs
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeInType #-}
{-# LANGUAGE TypeOperators #-}
module Bug where
import Data.Kind
import Data.Void
inf...The following program typechecks on GHC 8.2.2 and 8.4.2:
```hs
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeInType #-}
{-# LANGUAGE TypeOperators #-}
module Bug where
import Data.Kind
import Data.Void
infixl 4 :==
-- | Heterogeneous Leibnizian equality.
newtype (a :: j) :== (b :: k)
= HRefl { hsubst :: forall (c :: forall (i :: Type). i -> Type). c a -> c b }
newtype Coerce a = Coerce { uncoerce :: Starify a }
type family Starify (a :: k) :: Type where
Starify (a :: Type) = a
Starify _ = Void
coerce :: a :== b -> a -> b
coerce f = uncoerce . hsubst f . Coerce
```
But GHC HEAD rejects it:
```
$ ~/Software/ghc/inplace/bin/ghc-stage2 Bug.hs
[1 of 1] Compiling Bug ( Bug.hs, Bug.o )
Bug.hs:21:34: error:
• Kind mismatch: cannot unify (c0 :: forall i. i -> *) with:
Coerce :: forall k. k -> *
Their kinds differ.
Expected type: a -> c0 * a
Actual type: Starify a -> Coerce a
• In the second argument of ‘(.)’, namely ‘Coerce’
In the second argument of ‘(.)’, namely ‘hsubst f . Coerce’
In the expression: uncoerce . hsubst f . Coerce
|
21 | coerce f = uncoerce . hsubst f . Coerce
| ^^^^^^
```
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | ----------------------- |
| Version | 8.5 |
| Type | Bug |
| TypeOfFailure | OtherFailure |
| Priority | high |
| Resolution | Unresolved |
| Component | Compiler (Type checker) |
| Test case | |
| Differential revisions | |
| BlockedBy | |
| Related | |
| Blocking | |
| CC | |
| Operating system | |
| Architecture | |
</details>
<!-- {"blocked_by":[],"summary":"GHC HEAD regression: cannot instantiate higher-rank kind","status":"New","operating_system":"","component":"Compiler (Type checker)","related":[],"milestone":"8.6.1","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"8.5","keywords":["TypeInType"],"differentials":[],"test_case":"","architecture":"","cc":[""],"type":"Bug","description":"The following program typechecks on GHC 8.2.2 and 8.4.2:\r\n\r\n{{{#!hs\r\n{-# LANGUAGE RankNTypes #-}\r\n{-# LANGUAGE TypeFamilies #-}\r\n{-# LANGUAGE TypeInType #-}\r\n{-# LANGUAGE TypeOperators #-}\r\nmodule Bug where\r\n\r\nimport Data.Kind\r\nimport Data.Void\r\n\r\ninfixl 4 :==\r\n-- | Heterogeneous Leibnizian equality.\r\nnewtype (a :: j) :== (b :: k)\r\n = HRefl { hsubst :: forall (c :: forall (i :: Type). i -> Type). c a -> c b }\r\n\r\nnewtype Coerce a = Coerce { uncoerce :: Starify a }\r\ntype family Starify (a :: k) :: Type where\r\n Starify (a :: Type) = a\r\n Starify _ = Void\r\n\r\ncoerce :: a :== b -> a -> b\r\ncoerce f = uncoerce . hsubst f . Coerce\r\n}}}\r\n\r\nBut GHC HEAD rejects it:\r\n\r\n{{{\r\n$ ~/Software/ghc/inplace/bin/ghc-stage2 Bug.hs\r\n[1 of 1] Compiling Bug ( Bug.hs, Bug.o )\r\n\r\nBug.hs:21:34: error:\r\n • Kind mismatch: cannot unify (c0 :: forall i. i -> *) with:\r\n Coerce :: forall k. k -> *\r\n Their kinds differ.\r\n Expected type: a -> c0 * a\r\n Actual type: Starify a -> Coerce a\r\n • In the second argument of ‘(.)’, namely ‘Coerce’\r\n In the second argument of ‘(.)’, namely ‘hsubst f . Coerce’\r\n In the expression: uncoerce . hsubst f . Coerce\r\n |\r\n21 | coerce f = uncoerce . hsubst f . Coerce\r\n | ^^^^^^\r\n}}}","type_of_failure":"OtherFailure","blocking":[]} -->8.6.1https://gitlab.haskell.org/ghc/ghc/-/issues/15076Typed hole with higher-rank kind causes GHC to panic (No skolem info)2019-07-07T18:14:23ZRyan ScottTyped hole with higher-rank kind causes GHC to panic (No skolem info)Spun out from #14040\#[ticket:15076\#comment:152359](https://gitlab.haskell.org//ghc/ghc/issues/15076#note_152359), which was different enough from the original program in #14040 to warrant its own ticket. The following program panics on...Spun out from #14040\#[ticket:15076\#comment:152359](https://gitlab.haskell.org//ghc/ghc/issues/15076#note_152359), which was different enough from the original program in #14040 to warrant its own ticket. The following program panics on every version of GHC from 8.0.2 onward:
```hs
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeInType #-}
module Bug where
import Data.Kind
import Data.Proxy
foo :: forall (a :: Type)
(f :: forall (x :: a). Proxy x -> Type).
Proxy f -> ()
foo (_ :: _) = ()
```
```
$ ~/Software/ghc/inplace/bin/ghc-stage2 Bug.hs
[1 of 1] Compiling Bug ( Bug.hs, Bug.o )
Bug.hs:12:11: error:ghc-stage2: panic! (the 'impossible' happened)
(GHC version 8.5.20180420 for x86_64-unknown-linux):
No skolem info:
[a_aZo[sk:1]]
Call stack:
CallStack (from HasCallStack):
callStackDoc, called at compiler/utils/Outputable.hs:1162:37 in ghc:Outputable
pprPanic, called at compiler/typecheck/TcErrors.hs:3224:5 in ghc:TcErrors
```8.8.1https://gitlab.haskell.org/ghc/ghc/-/issues/15039Bizarre pretty-printing of inferred Coercible constraint in partial type sign...2019-07-07T18:14:36ZRyan ScottBizarre pretty-printing of inferred Coercible constraint in partial type signatureConsider the following GHCi session:
```
$ ghci
GHCi, version 8.4.1: http://www.haskell.org/ghc/ :? for help
Loaded GHCi configuration from /home/rgscott/.ghci
λ> import Data.Type.Coercion
λ> foo :: _ => Coercion a b; foo = Coercion
<...Consider the following GHCi session:
```
$ ghci
GHCi, version 8.4.1: http://www.haskell.org/ghc/ :? for help
Loaded GHCi configuration from /home/rgscott/.ghci
λ> import Data.Type.Coercion
λ> foo :: _ => Coercion a b; foo = Coercion
<interactive>:2:8: error:
• Found type wildcard ‘_’
standing for ‘Coercible a b :: TYPE ('GHC.Types.TupleRep '[])’
Where: ‘a’, ‘b’ are rigid type variables bound by
the inferred type of foo :: Coercible a b => Coercion a b
at <interactive>:2:27-40
To use the inferred type, enable PartialTypeSignatures
• In the type signature: foo :: _ => Coercion a b
λ> :set -fprint-explicit-kinds
λ> foo :: _ => Coercion a b; foo = Coercion
<interactive>:4:8: error:
• Found type wildcard ‘_’
standing for ‘(a :: *) ~~ (b :: *) :: TYPE
('GHC.Types.TupleRep ('[] GHC.Types.RuntimeRep))’
Where: ‘a’, ‘b’ are rigid type variables bound by
the inferred type of
foo :: ((a :: *) ~~ (b :: *)) => Coercion * a b
at <interactive>:4:27-40
To use the inferred type, enable PartialTypeSignatures
• In the type signature: foo :: _ => Coercion a b
```
There are two things quite strange about this:
1. In both error messages, GHC claims that `Coercible a b`/`a ~~ b` has kind `TYPE (TupleRep '[])`. This is wrong, and should be `Coercible`.
1. For some reason, enabling `-fprint-explicit-kinds` causes the inferred constraint to be `(~~)` instead of `Coercible`, which is just plain wrong.
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | ----------------------- |
| Version | 8.4.1 |
| Type | Bug |
| TypeOfFailure | OtherFailure |
| Priority | normal |
| Resolution | Unresolved |
| Component | Compiler (Type checker) |
| Test case | |
| Differential revisions | |
| BlockedBy | |
| Related | |
| Blocking | |
| CC | |
| Operating system | |
| Architecture | |
</details>
<!-- {"blocked_by":[],"summary":"Bizarre pretty-printing of inferred Coercible constraint in partial type signature","status":"New","operating_system":"","component":"Compiler (Type checker)","related":[],"milestone":"8.6.1","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"8.4.1","keywords":["PartialTypeSignatures"],"differentials":[],"test_case":"","architecture":"","cc":[""],"type":"Bug","description":"Consider the following GHCi session:\r\n\r\n{{{\r\n$ ghci\r\nGHCi, version 8.4.1: http://www.haskell.org/ghc/ :? for help\r\nLoaded GHCi configuration from /home/rgscott/.ghci\r\nλ> import Data.Type.Coercion\r\nλ> foo :: _ => Coercion a b; foo = Coercion\r\n\r\n<interactive>:2:8: error:\r\n • Found type wildcard ‘_’\r\n standing for ‘Coercible a b :: TYPE ('GHC.Types.TupleRep '[])’\r\n Where: ‘a’, ‘b’ are rigid type variables bound by\r\n the inferred type of foo :: Coercible a b => Coercion a b\r\n at <interactive>:2:27-40\r\n To use the inferred type, enable PartialTypeSignatures\r\n • In the type signature: foo :: _ => Coercion a b\r\nλ> :set -fprint-explicit-kinds \r\nλ> foo :: _ => Coercion a b; foo = Coercion\r\n\r\n<interactive>:4:8: error:\r\n • Found type wildcard ‘_’\r\n standing for ‘(a :: *) ~~ (b :: *) :: TYPE\r\n ('GHC.Types.TupleRep ('[] GHC.Types.RuntimeRep))’\r\n Where: ‘a’, ‘b’ are rigid type variables bound by\r\n the inferred type of\r\n foo :: ((a :: *) ~~ (b :: *)) => Coercion * a b\r\n at <interactive>:4:27-40\r\n To use the inferred type, enable PartialTypeSignatures\r\n • In the type signature: foo :: _ => Coercion a b\r\n}}}\r\n\r\nThere are two things quite strange about this:\r\n\r\n1. In both error messages, GHC claims that `Coercible a b`/`a ~~ b` has kind `TYPE (TupleRep '[])`. This is wrong, and should be `Coercible`.\r\n2. For some reason, enabling `-fprint-explicit-kinds` causes the inferred constraint to be `(~~)` instead of `Coercible`, which is just plain wrong.","type_of_failure":"OtherFailure","blocking":[]} -->8.6.1https://gitlab.haskell.org/ghc/ghc/-/issues/14991GHC HEAD regression involving TYPEs in type families2019-07-07T18:14:46ZRyan ScottGHC HEAD regression involving TYPEs in type familiesThis program typechecks on GHC 8.2.2 and 8.4.1:
```hs
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeInType #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE UndecidableInstances #-}
module Bug where
import Data.Kind
type family Promote...This program typechecks on GHC 8.2.2 and 8.4.1:
```hs
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeInType #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE UndecidableInstances #-}
module Bug where
import Data.Kind
type family Promote (k :: Type) :: Type
type family PromoteX (a :: k) :: Promote k
type family Demote (k :: Type) :: Type
type family DemoteX (a :: k) :: Demote k
-----
-- Type
-----
type instance Demote Type = Type
type instance Promote Type = Type
type instance DemoteX (a :: Type) = Demote a
type instance PromoteX (a :: Type) = Promote a
-----
-- Arrows
-----
data TyFun :: Type -> Type -> Type
type a ~> b = TyFun a b -> Type
infixr 0 ~>
type instance Demote (a ~> b) = DemoteX a -> DemoteX b
type instance Promote (a -> b) = PromoteX a ~> PromoteX b
```
However, it fails to typecheck on GHC HEAD:
```
$ ~/Software/ghc/inplace/bin/ghc-stage2 --interactive Bug.hs
GHCi, version 8.5.20180401: http://www.haskell.org/ghc/ :? for help
Loaded GHCi configuration from /home/rgscott/.ghci
[1 of 1] Compiling Bug ( Bug.hs, interpreted )
Bug.hs:34:34: error:
• Expected a type, but ‘PromoteX a’ has kind ‘Promote (TYPE t0)’
• In the first argument of ‘(~>)’, namely ‘PromoteX a’
In the type ‘PromoteX a ~> PromoteX b’
In the type instance declaration for ‘Promote’
|
34 | type instance Promote (a -> b) = PromoteX a ~> PromoteX b
| ^^^^^^^^^^
Bug.hs:34:48: error:
• Expected a type, but ‘PromoteX b’ has kind ‘Promote (TYPE t1)’
• In the second argument of ‘(~>)’, namely ‘PromoteX b’
In the type ‘PromoteX a ~> PromoteX b’
In the type instance declaration for ‘Promote’
|
34 | type instance Promote (a -> b) = PromoteX a ~> PromoteX b
| ^^^^^^^^^^
```
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | ----------------------- |
| Version | 8.5 |
| Type | Bug |
| TypeOfFailure | OtherFailure |
| Priority | normal |
| Resolution | Unresolved |
| Component | Compiler (Type checker) |
| Test case | |
| Differential revisions | |
| BlockedBy | |
| Related | |
| Blocking | |
| CC | |
| Operating system | |
| Architecture | |
</details>
<!-- {"blocked_by":[],"summary":"GHC HEAD regression involving TYPEs in type families","status":"New","operating_system":"","component":"Compiler (Type checker)","related":[],"milestone":"8.6.1","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"8.5","keywords":["TypeFamilies","TypeInType,"],"differentials":[],"test_case":"","architecture":"","cc":[""],"type":"Bug","description":"This program typechecks on GHC 8.2.2 and 8.4.1:\r\n\r\n{{{#!hs\r\n{-# LANGUAGE TypeFamilies #-}\r\n{-# LANGUAGE TypeInType #-}\r\n{-# LANGUAGE TypeOperators #-}\r\n{-# LANGUAGE UndecidableInstances #-}\r\nmodule Bug where\r\n\r\nimport Data.Kind\r\n\r\ntype family Promote (k :: Type) :: Type\r\ntype family PromoteX (a :: k) :: Promote k\r\n\r\ntype family Demote (k :: Type) :: Type\r\ntype family DemoteX (a :: k) :: Demote k\r\n\r\n-----\r\n-- Type\r\n-----\r\n\r\ntype instance Demote Type = Type\r\ntype instance Promote Type = Type\r\n\r\ntype instance DemoteX (a :: Type) = Demote a\r\ntype instance PromoteX (a :: Type) = Promote a\r\n\r\n-----\r\n-- Arrows\r\n-----\r\n\r\ndata TyFun :: Type -> Type -> Type\r\ntype a ~> b = TyFun a b -> Type\r\ninfixr 0 ~>\r\n\r\ntype instance Demote (a ~> b) = DemoteX a -> DemoteX b\r\ntype instance Promote (a -> b) = PromoteX a ~> PromoteX b\r\n}}}\r\n\r\nHowever, it fails to typecheck on GHC HEAD:\r\n\r\n{{{\r\n$ ~/Software/ghc/inplace/bin/ghc-stage2 --interactive Bug.hs\r\nGHCi, version 8.5.20180401: http://www.haskell.org/ghc/ :? for help\r\nLoaded GHCi configuration from /home/rgscott/.ghci\r\n[1 of 1] Compiling Bug ( Bug.hs, interpreted )\r\n\r\nBug.hs:34:34: error:\r\n • Expected a type, but ‘PromoteX a’ has kind ‘Promote (TYPE t0)’\r\n • In the first argument of ‘(~>)’, namely ‘PromoteX a’\r\n In the type ‘PromoteX a ~> PromoteX b’\r\n In the type instance declaration for ‘Promote’\r\n |\r\n34 | type instance Promote (a -> b) = PromoteX a ~> PromoteX b\r\n | ^^^^^^^^^^\r\n\r\nBug.hs:34:48: error:\r\n • Expected a type, but ‘PromoteX b’ has kind ‘Promote (TYPE t1)’\r\n • In the second argument of ‘(~>)’, namely ‘PromoteX b’\r\n In the type ‘PromoteX a ~> PromoteX b’\r\n In the type instance declaration for ‘Promote’\r\n |\r\n34 | type instance Promote (a -> b) = PromoteX a ~> PromoteX b\r\n | ^^^^^^^^^^\r\n}}}","type_of_failure":"OtherFailure","blocking":[]} -->8.6.1Richard Eisenbergrae@richarde.devRichard Eisenbergrae@richarde.devhttps://gitlab.haskell.org/ghc/ghc/-/issues/14938Pattern matching on GADT does not refine type family parameters2019-07-07T18:14:57ZCsongor KissPattern matching on GADT does not refine type family parametersCompiling the following code
```hs
type family R (x :: k) (y :: k) (prf :: x :~: y) :: x :~: y where
R x y Refl = Refl
```
fails with the error
```txt
Temp.hs:49:9: error:
• Expected kind ‘x :~: y’, but ‘Refl’ has kind ‘x :~: x’...Compiling the following code
```hs
type family R (x :: k) (y :: k) (prf :: x :~: y) :: x :~: y where
R x y Refl = Refl
```
fails with the error
```txt
Temp.hs:49:9: error:
• Expected kind ‘x :~: y’, but ‘Refl’ has kind ‘x :~: x’
• In the third argument of ‘R’, namely ‘Refl’
In the type family declaration for ‘R’
|
49 | R x y Refl = Refl
| ^^^^
```
where `Refl` is defined as
```hs
data a :~: b where
Refl :: a :~: a
```
I would expect pattern-matching on `Refl` to bring the equality `x ~ y` into scope. It seems like it not only doesn't do that, but the pattern match itself is rejected.
(both 8.2.2 and HEAD)
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | ----------------------- |
| Version | 8.2.2 |
| Type | Bug |
| TypeOfFailure | OtherFailure |
| Priority | normal |
| Resolution | Unresolved |
| Component | Compiler (Type checker) |
| Test case | |
| Differential revisions | |
| BlockedBy | |
| Related | |
| Blocking | |
| CC | |
| Operating system | |
| Architecture | |
</details>
<!-- {"blocked_by":[],"summary":"Pattern matching on GADT does not refine type family parameters","status":"New","operating_system":"","component":"Compiler (Type checker)","related":[],"milestone":"","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"8.2.2","keywords":["GADTs,","TypeFamilies"],"differentials":[],"test_case":"","architecture":"","cc":[""],"type":"Bug","description":"Compiling the following code\r\n\r\n{{{#!hs\r\ntype family R (x :: k) (y :: k) (prf :: x :~: y) :: x :~: y where\r\n R x y Refl = Refl\r\n}}}\r\n\r\nfails with the error\r\n\r\n\r\n{{{#!txt\r\nTemp.hs:49:9: error:\r\n • Expected kind ‘x :~: y’, but ‘Refl’ has kind ‘x :~: x’\r\n • In the third argument of ‘R’, namely ‘Refl’\r\n In the type family declaration for ‘R’\r\n |\r\n49 | R x y Refl = Refl\r\n | ^^^^\r\n}}}\r\n\r\nwhere `Refl` is defined as\r\n{{{#!hs\r\ndata a :~: b where\r\n Refl :: a :~: a\r\n}}}\r\n\r\nI would expect pattern-matching on `Refl` to bring the equality `x ~ y` into scope. It seems like it not only doesn't do that, but the pattern match itself is rejected.\r\n\r\n(both 8.2.2 and HEAD)\r\n","type_of_failure":"OtherFailure","blocking":[]} -->https://gitlab.haskell.org/ghc/ghc/-/issues/14904Compiler panic (piResultTy)2019-07-07T18:15:06ZCsongor KissCompiler panic (piResultTy)Type-checking the following type family
```hs
type family F (f :: forall a. g a) :: Type where
F (f :: forall a. g a) = Int
```
panics with the message:
```txt
ghc: panic! (the 'impossible' happened)
(GHC version 8.4.0.20180118 fo...Type-checking the following type family
```hs
type family F (f :: forall a. g a) :: Type where
F (f :: forall a. g a) = Int
```
panics with the message:
```txt
ghc: panic! (the 'impossible' happened)
(GHC version 8.4.0.20180118 for x86_64-apple-darwin):
piResultTy
k_aVM[tau:1]
a_aVF[sk:1]
Call stack:
CallStack (from HasCallStack):
callStackDoc, called at compiler/utils/Outputable.hs:1150:37 in ghc:Outputable
pprPanic, called at compiler/types/Type.hs:950:35 in ghc:Type
```
The panic happens with HEAD, 8.4 and 8.2. 8.0 rejects the program with an error message, but even it panics on the following version:
```hs
type family F f :: Type where
F ((f :: forall a. g a) :: forall a. g a) = Int
```
#14873 seemed somewhat related, so I tried with the patch implemented in 3d252037234ce48f9bdada7d5c9b1d8eba470829, but that fails with the same panic too.
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | ----------------------- |
| Version | 8.2.2 |
| Type | Bug |
| TypeOfFailure | OtherFailure |
| Priority | normal |
| Resolution | Unresolved |
| Component | Compiler (Type checker) |
| Test case | |
| Differential revisions | |
| BlockedBy | |
| Related | #14873 |
| Blocking | |
| CC | |
| Operating system | |
| Architecture | |
</details>
<!-- {"blocked_by":[],"summary":"Compiler panic (piResultTy)","status":"New","operating_system":"","component":"Compiler (Type checker)","related":[14873],"milestone":"","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"8.2.2","keywords":[],"differentials":[],"test_case":"","architecture":"","cc":[""],"type":"Bug","description":"Type-checking the following type family\r\n\r\n{{{#!hs\r\ntype family F (f :: forall a. g a) :: Type where\r\n F (f :: forall a. g a) = Int\r\n}}}\r\n\r\npanics with the message:\r\n\r\n{{{#!txt\r\nghc: panic! (the 'impossible' happened)\r\n (GHC version 8.4.0.20180118 for x86_64-apple-darwin):\r\n piResultTy\r\n k_aVM[tau:1]\r\n a_aVF[sk:1]\r\n Call stack:\r\n CallStack (from HasCallStack):\r\n callStackDoc, called at compiler/utils/Outputable.hs:1150:37 in ghc:Outputable\r\n pprPanic, called at compiler/types/Type.hs:950:35 in ghc:Type\r\n\r\n}}}\r\n\r\nThe panic happens with HEAD, 8.4 and 8.2. 8.0 rejects the program with an error message, but even it panics on the following version:\r\n\r\n{{{#!hs\r\ntype family F f :: Type where\r\n F ((f :: forall a. g a) :: forall a. g a) = Int\r\n}}}\r\n\r\n#14873 seemed somewhat related, so I tried with the patch implemented in 3d252037234ce48f9bdada7d5c9b1d8eba470829, but that fails with the same panic too.","type_of_failure":"OtherFailure","blocking":[]} -->8.6.1https://gitlab.haskell.org/ghc/ghc/-/issues/14887Explicitly quantifying a kind variable causes a telescope to fail to kind-check2019-07-07T18:15:11ZRyan ScottExplicitly quantifying a kind variable causes a telescope to fail to kind-checkConsider the following program:
```hs
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeInType #-}
{-# LANGUAGE TypeOperators #-}
{-# OPTIONS_GHC -fprint-explicit-kinds #-}
module Bug where
import Data.Kind
import Data.Type.Equality
type...Consider the following program:
```hs
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeInType #-}
{-# LANGUAGE TypeOperators #-}
{-# OPTIONS_GHC -fprint-explicit-kinds #-}
module Bug where
import Data.Kind
import Data.Type.Equality
type family Foo1 (e :: (a :: k) :~: (a :: k)) :: Type where
Foo1 (e :: a :~: a) = a :~: a
type family Foo2 (k :: Type) (e :: (a :: k) :~: (a :: k)) :: Type where
Foo2 k (e :: a :~: a) = a :~: a
```
`Foo2` is wholly equivalent to `Foo1`, except that in `Foo2`, the `k` kind variable is explicitly quantified. However, `Foo1` typechecks, but `Foo2` does not!
```
$ /opt/ghc/8.2.2/bin/ghci Bug.hs -fprint-explicit-kinds
GHCi, version 8.2.2: http://www.haskell.org/ghc/ :? for help
Loaded GHCi configuration from /home/ryanglscott/.ghci
[1 of 1] Compiling Bug ( Bug.hs, interpreted )
Bug.hs:13:10: error:
• Couldn't match kind ‘k’ with ‘k1’
When matching the kind of ‘a’
Expected kind ‘(:~:) k a a’, but ‘e’ has kind ‘(:~:) k a a’
• In the second argument of ‘Foo2’, namely ‘(e :: a :~: a)’
In the type family declaration for ‘Foo2’
|
13 | Foo2 k (e :: a :~: a) = a :~: a
| ^^^^^^^^^^^^^^
```
(Moreover, there seems to be a tidying bug, since GHC claims that `(:~:) k a a` is not the same kind as `(:~:) k a a`.)
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | ----------------------- |
| Version | 8.2.2 |
| Type | Bug |
| TypeOfFailure | OtherFailure |
| Priority | normal |
| Resolution | Unresolved |
| Component | Compiler (Type checker) |
| Test case | |
| Differential revisions | |
| BlockedBy | |
| Related | |
| Blocking | |
| CC | |
| Operating system | |
| Architecture | |
</details>
<!-- {"blocked_by":[],"summary":"Explicitly quantifying a kind variable causes a type family to fail to typecheck","status":"New","operating_system":"","component":"Compiler (Type checker)","related":[],"milestone":"","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"8.2.2","keywords":["TypeFamilies,","TypeInType"],"differentials":[],"test_case":"","architecture":"","cc":[""],"type":"Bug","description":"Consider the following program:\r\n\r\n{{{#!hs\r\n{-# LANGUAGE TypeFamilies #-}\r\n{-# LANGUAGE TypeInType #-}\r\n{-# LANGUAGE TypeOperators #-}\r\n{-# OPTIONS_GHC -fprint-explicit-kinds #-}\r\nmodule Bug where\r\n\r\nimport Data.Kind\r\nimport Data.Type.Equality\r\n\r\ntype family Foo1 (e :: (a :: k) :~: (a :: k)) :: Type where\r\n Foo1 (e :: a :~: a) = a :~: a\r\n\r\ntype family Foo2 (k :: Type) (e :: (a :: k) :~: (a :: k)) :: Type where\r\n Foo2 k (e :: a :~: a) = a :~: a\r\n}}}\r\n\r\n`Foo2` is wholly equivalent to `Foo1`, except that in `Foo2`, the `k` kind variable is explicitly quantified. However, `Foo1` typechecks, but `Foo2` does not!\r\n\r\n{{{\r\n$ /opt/ghc/8.2.2/bin/ghci Bug.hs -fprint-explicit-kinds\r\nGHCi, version 8.2.2: http://www.haskell.org/ghc/ :? for help\r\nLoaded GHCi configuration from /home/ryanglscott/.ghci\r\n[1 of 1] Compiling Bug ( Bug.hs, interpreted )\r\n\r\nBug.hs:13:10: error:\r\n • Couldn't match kind ‘k’ with ‘k1’\r\n When matching the kind of ‘a’\r\n Expected kind ‘(:~:) k a a’, but ‘e’ has kind ‘(:~:) k a a’\r\n • In the second argument of ‘Foo2’, namely ‘(e :: a :~: a)’\r\n In the type family declaration for ‘Foo2’\r\n |\r\n13 | Foo2 k (e :: a :~: a) = a :~: a\r\n | ^^^^^^^^^^^^^^\r\n}}}\r\n\r\n(Moreover, there seems to be a tidying bug, since GHC claims that `(:~:) k a a` is not the same kind as `(:~:) k a a`.)","type_of_failure":"OtherFailure","blocking":[]} -->8.8.1Richard Eisenbergrae@richarde.devRichard Eisenbergrae@richarde.devhttps://gitlab.haskell.org/ghc/ghc/-/issues/14880GHC panic: updateRole2019-07-07T18:15:13ZRyan ScottGHC panic: updateRoleThe following program panics on GHC 8.0.2, 8.2.2, 8.4.1, and HEAD:
```hs
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeInType #-}
{-# LANGUAGE...The following program panics on GHC 8.0.2, 8.2.2, 8.4.1, and HEAD:
```hs
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeInType #-}
{-# LANGUAGE TypeOperators #-}
module Bug where
import Data.Kind
import Data.Type.Equality ((:~:))
type SameKind (a :: k) (b :: k) = (() :: Constraint)
data TyFun :: Type -> Type -> Type
type a ~> b = TyFun a b -> Type
infixr 0 ~>
type family Apply (f :: k1 ~> k2) (x :: k1) :: k2
data WhyCongSym1 (x :: Type) :: forall (a :: x)
(y :: Type)
(z :: x).
Type ~> (x ~> y) ~> x ~> x ~> (a :~: z) ~> Type
data WhyCongSym0 :: forall (x :: Type)
(a :: x)
(y :: Type)
(z :: x).
Type ~> Type ~> (x ~> y) ~> x ~> x ~> (a :~: z) ~> Type
where
WhyCongSym0KindInference :: forall x arg.
SameKind (Apply WhyCongSym0 arg) (WhyCongSym1 arg) =>
WhyCongSym0 x
```
```
$ /opt/ghc/8.2.2/bin/ghci Bug.hs
GHCi, version 8.2.2: http://www.haskell.org/ghc/ :? for help
Loaded GHCi configuration from /home/rgscott/.ghci
[1 of 1] Compiling Bug ( Bug.hs, interpreted )
ghc: panic! (the 'impossible' happened)
(GHC version 8.2.2 for x86_64-unknown-linux):
updateRole
WhyCongSym0
arg_a1A6[sk:1]
[a1A5 :-> 4, a2Cy :-> 0, a2Cz :-> 1, a2CA :-> 2, a2CB :-> 3]
Call stack:
CallStack (from HasCallStack):
prettyCurrentCallStack, called at compiler/utils/Outputable.hs:1133:58 in ghc:Outputable
callStackDoc, called at compiler/utils/Outputable.hs:1137:37 in ghc:Outputable
pprPanic, called at compiler/typecheck/TcTyDecls.hs:656:23 in ghc:TcTyDecls
```8.6.2Richard Eisenbergrae@richarde.devRichard Eisenbergrae@richarde.devhttps://gitlab.haskell.org/ghc/ghc/-/issues/14873The well-kinded type invariant (in TcType)2021-09-07T15:47:33ZRyan ScottThe well-kinded type invariant (in TcType)(Originally noticed [here](https://travis-ci.org/goldfirere/singletons/jobs/347945148#L1179).)
The following program typechecks on GHC 8.2.2 on GHC 8.4.1, but panics on GHC HEAD:
```hs
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTyp...(Originally noticed [here](https://travis-ci.org/goldfirere/singletons/jobs/347945148#L1179).)
The following program typechecks on GHC 8.2.2 on GHC 8.4.1, but panics on GHC HEAD:
```hs
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeInType #-}
{-# LANGUAGE TypeOperators #-}
module Bug where
import Data.Kind (Type)
data family Sing (a :: k)
newtype instance Sing (f :: k1 ~> k2) =
SLambda { applySing :: forall t. Sing t -> Sing (Apply f t) }
data TyFun :: Type -> Type -> Type
type a ~> b = TyFun a b -> Type
infixr 0 ~>
type family Apply (f :: k1 ~> k2) (x :: k1) :: k2
class SingI (a :: k) where
sing :: Sing a
data ColSym1 :: f a -> a ~> Bool
type instance Apply (ColSym1 x) y = Col x y
class PColumn (f :: Type -> Type) where
type Col (x :: f a) (y :: a) :: Bool
class SColumn (f :: Type -> Type) where
sCol :: forall (x :: f a) (y :: a).
Sing x -> Sing y -> Sing (Col x y :: Bool)
instance (SColumn f, SingI x) => SingI (ColSym1 (x :: f a) :: a ~> Bool) where
sing = SLambda (sCol (sing @_ @x))
```
```
$ /opt/ghc/head/bin/ghc Bug.hs
[1 of 1] Compiling Bug ( Bug.hs, Bug.o )
ghc: panic! (the 'impossible' happened)
(GHC version 8.5.20180201 for x86_64-unknown-linux):
piResultTy
k_aZU[tau:1]
(a_aW8[sk:1] |> <*>_N)
Call stack:
CallStack (from HasCallStack):
callStackDoc, called at compiler/utils/Outputable.hs:1150:37 in ghc:Outputable
pprPanic, called at compiler/types/Type.hs:947:35 in ghc:Type
```
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | ----------------------- |
| Version | 8.5 |
| Type | Bug |
| TypeOfFailure | OtherFailure |
| Priority | highest |
| Resolution | Unresolved |
| Component | Compiler (Type checker) |
| Test case | |
| Differential revisions | |
| BlockedBy | |
| Related | |
| Blocking | |
| CC | |
| Operating system | |
| Architecture | |
</details>
<!-- {"blocked_by":[],"summary":"GHC HEAD regression (piResultTy)","status":"New","operating_system":"","component":"Compiler (Type checker)","related":[],"milestone":"","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"8.5","keywords":[],"differentials":[],"test_case":"","architecture":"","cc":[""],"type":"Bug","description":"(Originally noticed [https://travis-ci.org/goldfirere/singletons/jobs/347945148#L1179 here].)\r\n\r\nThe following program typechecks on GHC 8.2.2 on GHC 8.4.1, but panics on GHC HEAD:\r\n\r\n{{{#!hs\r\n{-# LANGUAGE RankNTypes #-}\r\n{-# LANGUAGE ScopedTypeVariables #-}\r\n{-# LANGUAGE TypeApplications #-}\r\n{-# LANGUAGE TypeFamilies #-}\r\n{-# LANGUAGE TypeInType #-}\r\n{-# LANGUAGE TypeOperators #-}\r\nmodule Bug where\r\n\r\nimport Data.Kind (Type)\r\n\r\ndata family Sing (a :: k)\r\n\r\nnewtype instance Sing (f :: k1 ~> k2) =\r\n SLambda { applySing :: forall t. Sing t -> Sing (Apply f t) }\r\n\r\ndata TyFun :: Type -> Type -> Type\r\ntype a ~> b = TyFun a b -> Type\r\ninfixr 0 ~>\r\ntype family Apply (f :: k1 ~> k2) (x :: k1) :: k2\r\n\r\nclass SingI (a :: k) where\r\n sing :: Sing a\r\n\r\ndata ColSym1 :: f a -> a ~> Bool\r\ntype instance Apply (ColSym1 x) y = Col x y\r\n\r\nclass PColumn (f :: Type -> Type) where\r\n type Col (x :: f a) (y :: a) :: Bool\r\n\r\nclass SColumn (f :: Type -> Type) where\r\n sCol :: forall (x :: f a) (y :: a).\r\n Sing x -> Sing y -> Sing (Col x y :: Bool)\r\n\r\ninstance (SColumn f, SingI x) => SingI (ColSym1 (x :: f a) :: a ~> Bool) where\r\n sing = SLambda (sCol (sing @_ @x))\r\n}}}\r\n\r\n{{{\r\n$ /opt/ghc/head/bin/ghc Bug.hs\r\n[1 of 1] Compiling Bug ( Bug.hs, Bug.o )\r\nghc: panic! (the 'impossible' happened)\r\n (GHC version 8.5.20180201 for x86_64-unknown-linux):\r\n piResultTy\r\n k_aZU[tau:1]\r\n (a_aW8[sk:1] |> <*>_N)\r\n Call stack:\r\n CallStack (from HasCallStack):\r\n callStackDoc, called at compiler/utils/Outputable.hs:1150:37 in ghc:Outputable\r\n pprPanic, called at compiler/types/Type.hs:947:35 in ghc:Type\r\n}}}","type_of_failure":"OtherFailure","blocking":[]} -->9.2.1Richard Eisenbergrae@richarde.devRichard Eisenbergrae@richarde.devhttps://gitlab.haskell.org/ghc/ghc/-/issues/14847Inferring dependent kinds for non-recursive types2019-07-07T18:15:20ZSimon Peyton JonesInferring dependent kinds for non-recursive typesConsider this
```
data Proxy k (a :: k) = MkProxy
data Proxy2 k a = MkP (Proxy k a)
```
which is discussed in [a corner of the user manual](http://downloads.haskell.org/~ghc/master/users-guide/glasgow_exts.html#inferring-dependency-in-...Consider this
```
data Proxy k (a :: k) = MkProxy
data Proxy2 k a = MkP (Proxy k a)
```
which is discussed in [a corner of the user manual](http://downloads.haskell.org/~ghc/master/users-guide/glasgow_exts.html#inferring-dependency-in-datatype-declarations).
Surprisingly, we reject `Proxy2` -- but there is nothing difficult about inferring its kind. There would be if it was recursive -- but it isn't.
Simple solution: for non-recursive type declarations (we do SCC analysis so we know which these are) do not call `getInitialKinds`; instead, just infer the kind of the definition! Simple.
Warning: is this recursive?
```
data Proxy2 k a where
MkP :: Proxy k a -> Proxy2 k a
```
Presumably no more than the other definition. But currently we need `Proxy2` in the environment during kind inference, because we kind-check the result type. That seems jolly odd and inconsistent. Needs more thought.
Similar questions for
```
data T a where
T :: Int -> T Bool
type family F a where
F Int = True
F _ = False
```
See also:
- #14451
- #12088
- #9427https://gitlab.haskell.org/ghc/ghc/-/issues/14846Renamer hangs (because of -XInstanceSigs?)2019-07-07T18:15:20ZIcelandjackRenamer hangs (because of -XInstanceSigs?)```hs
{-# Language RankNTypes, TypeInType, EmptyCase, GADTs, FlexibleInstances, ConstraintKinds, UndecidableInstances, AllowAmbiguousTypes, InstanceSigs, ScopedTypeVariables #-}
import Data.Kind
import Data.Proxy
type Cat ob = ob -> ob...```hs
{-# Language RankNTypes, TypeInType, EmptyCase, GADTs, FlexibleInstances, ConstraintKinds, UndecidableInstances, AllowAmbiguousTypes, InstanceSigs, ScopedTypeVariables #-}
import Data.Kind
import Data.Proxy
type Cat ob = ob -> ob -> Type
data Struct :: (k -> Constraint) -> Type where
S :: Proxy (a::k) -> Struct (cls::k -> Constraint)
type Structured a cls = (S ('Proxy :: Proxy a)::Struct cls)
data AStruct :: Struct cls -> Type where
AStruct :: cls a => AStruct (Structured a cls)
class StructI (structured::Struct (cls :: k -> Constraint)) where
struct :: AStruct structured
instance (Structured xx cls ~ structured, cls xx) => StructI structured where
struct :: AStruct (Structured xx cls)
struct = AStruct
data Hom :: Cat k -> Cat (Struct cls) where
class Category (cat::Cat ob) where
i :: StructI a => ríki a a
instance Category ríki => Category (Hom ríki :: Cat (Struct cls)) where
-- Commenting out this instance signature makes the issue go away
i :: forall a. StructI a => Hom ríki a a
i = case struct :: AStruct (Structured a cls) of
```
Running on 8.2.1 and 8.5.20180105 both loop until interrupted
```
$ ghci -ignore-dot-ghci 199.hs
GHCi, version 8.5.20180105: http://www.haskell.org/ghc/ :? for help
[1 of 1] Compiling Main ( 199.hs, interpreted )
^CInterrupted.
>
>
```8.4.2Richard Eisenbergrae@richarde.devRichard Eisenbergrae@richarde.devhttps://gitlab.haskell.org/ghc/ghc/-/issues/14845TypeInType, index GADT by constraint witness2019-07-07T18:15:21ZIcelandjackTypeInType, index GADT by constraint witnessJust wondering if it would ever make sense to allow or use constraints like this
```hs
{-# Language PolyKinds, DataKinds, KindSignatures, GADTs, TypeInType, ConstraintKinds #-}
import Data.Kind
data Struct :: (k -> Constraint) -> (k -...Just wondering if it would ever make sense to allow or use constraints like this
```hs
{-# Language PolyKinds, DataKinds, KindSignatures, GADTs, TypeInType, ConstraintKinds #-}
import Data.Kind
data Struct :: (k -> Constraint) -> (k -> Type) where
S :: cls a => Struct cls a
data Foo a where
F :: Foo (S::Struct Eq a)
```
```
$ ghci -ignore-dot-ghci /tmp/test.hs
GHCi, version 8.5.20180105: http://www.haskell.org/ghc/ :? for help
[1 of 1] Compiling Main ( /tmp/test.hs, interpreted )
/tmp/test.hs:9:13: error:
• Illegal constraint in a type: cls0 a0
• In the first argument of ‘Foo’, namely ‘(S :: Struct Eq a)’
In the type ‘Foo (S :: Struct Eq a)’
In the definition of data constructor ‘F’
|
9 | F :: Foo (S::Struct Eq a)
| ^
Failed, no modules loaded.
Prelude>
```
Please close the ticket if it doesn't
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | -------------- |
| Version | 8.5 |
| Type | FeatureRequest |
| TypeOfFailure | OtherFailure |
| Priority | normal |
| Resolution | Unresolved |
| Component | Compiler |
| Test case | |
| Differential revisions | |
| BlockedBy | |
| Related | |
| Blocking | |
| CC | |
| Operating system | |
| Architecture | |
</details>
<!-- {"blocked_by":[],"summary":"TypeInType, index by GADT witnessing constraint","status":"New","operating_system":"","component":"Compiler","related":[],"milestone":"","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"8.5","keywords":["TypeInType"],"differentials":[],"test_case":"","architecture":"","cc":[""],"type":"FeatureRequest","description":"Just wondering if it would ever make sense to allow or use constraints like this\r\n\r\n{{{#!hs\r\n{-# Language PolyKinds, DataKinds, KindSignatures, GADTs, TypeInType, ConstraintKinds #-}\r\n\r\nimport Data.Kind\r\n\r\ndata Struct :: (k -> Constraint) -> (k -> Type) where\r\n S :: cls a => Struct cls a\r\n\r\ndata Foo a where\r\n F :: Foo (S::Struct Eq a)\r\n}}}\r\n\r\n{{{\r\n$ ghci -ignore-dot-ghci /tmp/test.hs\r\nGHCi, version 8.5.20180105: http://www.haskell.org/ghc/ :? for help\r\n[1 of 1] Compiling Main ( /tmp/test.hs, interpreted )\r\n\r\n/tmp/test.hs:9:13: error:\r\n • Illegal constraint in a type: cls0 a0\r\n • In the first argument of ‘Foo’, namely ‘(S :: Struct Eq a)’\r\n In the type ‘Foo (S :: Struct Eq a)’\r\n In the definition of data constructor ‘F’\r\n |\r\n9 | F :: Foo (S::Struct Eq a)\r\n | ^\r\nFailed, no modules loaded.\r\nPrelude> \r\n}}}\r\n\r\nPlease close the ticket if it doesn't","type_of_failure":"OtherFailure","blocking":[]} -->8.6.1https://gitlab.haskell.org/ghc/ghc/-/issues/14795Data type return kinds don't obey the forall-or-nothing rule2022-07-13T16:54:51ZRyan ScottData type return kinds don't obey the forall-or-nothing ruleOriginally noticed [here](https://github.com/ghc-proposals/ghc-proposals/pull/103#issuecomment-364562974). GHC accepts this:
```hs
{-# LANGUAGE GADTs #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE TypeInType #-}
import Data.Kind
data Fo...Originally noticed [here](https://github.com/ghc-proposals/ghc-proposals/pull/103#issuecomment-364562974). GHC accepts this:
```hs
{-# LANGUAGE GADTs #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE TypeInType #-}
import Data.Kind
data Foo :: forall a. a -> b -> Type where
MkFoo :: a -> Foo a b
```
Despite the fact that `Foo`'s return kind is headed by an explicit `forall` which does not quantify `b`.
The users' guide doesn't explicitly indicate that the `forall`-or-nothing rule should apply to data type return kinds, but goldfirere believes that not doing so is an [inconsistent design](https://github.com/ghc-proposals/ghc-proposals/pull/103#issuecomment-364670215), so I'm opening this ticket to track this.
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | ----------------------- |
| Version | 8.2.2 |
| Type | Bug |
| TypeOfFailure | OtherFailure |
| Priority | normal |
| Resolution | Unresolved |
| Component | Compiler (Type checker) |
| Test case | |
| Differential revisions | |
| BlockedBy | |
| Related | |
| Blocking | |
| CC | |
| Operating system | |
| Architecture | |
</details>
<!-- {"blocked_by":[],"summary":"Data type return kinds don't obey the forall-or-nothing rule","status":"New","operating_system":"","component":"Compiler (Type checker)","related":[],"milestone":"","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"8.2.2","keywords":["TypeInType"],"differentials":[],"test_case":"","architecture":"","cc":[""],"type":"Bug","description":"Originally noticed [https://github.com/ghc-proposals/ghc-proposals/pull/103#issuecomment-364562974 here]. GHC accepts this:\r\n\r\n{{{#!hs\r\n{-# LANGUAGE GADTs #-}\r\n{-# LANGUAGE RankNTypes #-}\r\n{-# LANGUAGE TypeInType #-}\r\n\r\nimport Data.Kind\r\n\r\ndata Foo :: forall a. a -> b -> Type where\r\n MkFoo :: a -> Foo a b\r\n}}}\r\n\r\nDespite the fact that `Foo`'s return kind is headed by an explicit `forall` which does not quantify `b`.\r\n\r\nThe users' guide doesn't explicitly indicate that the `forall`-or-nothing rule should apply to data type return kinds, but goldfirere believes that not doing so is an [https://github.com/ghc-proposals/ghc-proposals/pull/103#issuecomment-364670215 inconsistent design], so I'm opening this ticket to track this.","type_of_failure":"OtherFailure","blocking":[]} -->https://gitlab.haskell.org/ghc/ghc/-/issues/14764Make $! representation-polymorphic2019-07-07T18:15:43ZDavid FeuerMake $! representation-polymorphicCurrently,
```hs
($) :: forall r a (b :: TYPE r). (a -> b) -> a -> b
```
but
```hs
($!) :: (a -> b) -> a -> b
```
It seems fairly obvious that we should generalize `($!)`.
<details><summary>Trac metadata</summary>
| Trac field ...Currently,
```hs
($) :: forall r a (b :: TYPE r). (a -> b) -> a -> b
```
but
```hs
($!) :: (a -> b) -> a -> b
```
It seems fairly obvious that we should generalize `($!)`.
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | -------------- |
| Version | 8.2.2 |
| Type | Task |
| TypeOfFailure | OtherFailure |
| Priority | normal |
| Resolution | Unresolved |
| Component | Core Libraries |
| Test case | |
| Differential revisions | |
| BlockedBy | |
| Related | |
| Blocking | |
| CC | |
| Operating system | |
| Architecture | |
</details>
<!-- {"blocked_by":[],"summary":"Make $! representation-polymorphic","status":"New","operating_system":"","component":"Core Libraries","related":[],"milestone":"8.6.1","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"8.2.2","keywords":["TypeInType"],"differentials":[],"test_case":"","architecture":"","cc":[""],"type":"Task","description":"Currently,\r\n\r\n{{{#!hs\r\n($) :: forall r a (b :: TYPE r). (a -> b) -> a -> b\r\n}}}\r\n\r\nbut\r\n\r\n{{{#!hs\r\n($!) :: (a -> b) -> a -> b\r\n}}}\r\n\r\nIt seems fairly obvious that we should generalize `($!)`.","type_of_failure":"OtherFailure","blocking":[]} -->8.6.1https://gitlab.haskell.org/ghc/ghc/-/issues/14749T13822 fails2019-07-07T18:15:46ZSimon Peyton JonesT13822 failsConsider this cut-down T13822
```
{-# LANGUAGE GADTs, TypeOperators, DataKinds, TypeFamilies, TypeInType #-}
module T13822 where
import Data.Kind
data KIND = STAR | KIND :> KIND
data Ty :: KIND -> Type where
TMaybe :: Ty (STAR :> ...Consider this cut-down T13822
```
{-# LANGUAGE GADTs, TypeOperators, DataKinds, TypeFamilies, TypeInType #-}
module T13822 where
import Data.Kind
data KIND = STAR | KIND :> KIND
data Ty :: KIND -> Type where
TMaybe :: Ty (STAR :> STAR)
TApp :: Ty (a :> b) -> (Ty a -> Ty b)
type family IK (k :: KIND) = (res :: Type) where
IK STAR = Type
IK (a:>b) = IK a -> IK b
type family I (t :: Ty k) = (res :: IK k) where
I TMaybe = Maybe
I (TApp f a) = (I f) (I a)
data TyRep (k :: KIND) (t :: Ty k) where
TyMaybe :: TyRep (STAR:>STAR) TMaybe
TyApp :: TyRep (a:>b) f -> TyRep a x -> TyRep b (TApp f x)
zero :: TyRep STAR a -> I a
zero x = case x of
TyApp TyMaybe _ -> Nothing
```
With a stage-1 compiler with DEBUG enabled, this program yields a Lint error in all recent versions of GHC. (NB: Lint, not an assertion failure.)
With stage-2 it succeeds, and passes Lint. Reason: without DEBUG the output of the typechecker is not Linted until after a run of the `CoreOpt`; and that simplifies the coercions; which somehow eliminates the Lint error.
I added`-ddump-ds-preopt` to made the pre-core-opt dump optional -- it is sometimes useful in a non-DEBUG compiler. But that makes Lint run on the pre-core-opt code, and that shows up the bug always.
But an apparently unrelated patch makes it fail Lint even in stage 2. So it's kind of harmless; but a clear bug that we should fix.
I'll mark T13822 as expect-broken; you can re-enable it when this ticket is fixed.
The Lint error is pretty obscure
```
*** Core Lint errors : in result of Desugar (before optimization) ***
<no location info>: warning:
[in body of letrec with binders co_a10u :: (f_a10g :: Ty
(a_a10f ':> 'STAR))
~# (('TMaybe |> (Ty
(Sym co_a10r
':> <'STAR>_N)_N)_N) :: Ty
(a_a10f
':> 'STAR))]
Kind application error in
coercion ‘(Maybe
(Sym (Coh <I (x_a10h |> Sym (Ty (Sym co_a10r))_N)>_N
(D:R:IK[0]) ; Coh <(I (x_a10h |> Sym (Ty
(Sym co_a10r))_N) |> D:R:IK[0])>_N
(Sym (D:R:IK[0]))) ; Coh <I (x_a10h |> Sym (Ty
(Sym co_a10r))_N)>_N
(D:R:IK[0])))_N’
Function kind = * -> *
Arg kinds = [(I (x_a10h |> Sym (Ty (Sym co_a10r))_N), IK 'STAR)]
Fun: *
(I (x_a10h |> Sym (Ty (Sym co_a10r))_N), IK 'STAR)
```Richard Eisenbergrae@richarde.devRichard Eisenbergrae@richarde.dev