GHC issueshttps://gitlab.haskell.org/ghc/ghc/-/issues2019-07-07T18:49:28Zhttps://gitlab.haskell.org/ghc/ghc/-/issues/7503Bug with PolyKinds, type synonyms & GADTs2019-07-07T18:49:28ZAshley YakeleyBug with PolyKinds, type synonyms & GADTsGHC incorrectly rejects this program:
```
{-# LANGUAGE ExistentialQuantification, DataKinds, PolyKinds, KindSignatures, GADTs #-}
module TestConstraintKinds where
import GHC.Exts hiding (Any)
data WrappedType = forall a. WrapTy...GHC incorrectly rejects this program:
```
{-# LANGUAGE ExistentialQuantification, DataKinds, PolyKinds, KindSignatures, GADTs #-}
module TestConstraintKinds where
import GHC.Exts hiding (Any)
data WrappedType = forall a. WrapType a
data A :: WrappedType -> * where
MkA :: forall (a :: *). AW a -> A (WrapType a)
type AW (a :: k) = A (WrapType a)
type AW' (a :: k) = A (WrapType a)
class C (a :: k) where
aw :: AW a -- workaround: AW'
instance C [] where
aw = aw
```
GHC accepts the program when AW is replaced with AW' on that line.
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | ----------------------- |
| Version | 7.6.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":"Bug with PolyKinds, type synonyms & GADTs","status":"New","operating_system":"","component":"Compiler (Type checker)","related":[],"milestone":"","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"7.6.1","keywords":[],"differentials":[],"test_case":"","architecture":"","cc":[""],"type":"Bug","description":"GHC incorrectly rejects this program:\r\n{{{\r\n{-# LANGUAGE ExistentialQuantification, DataKinds, PolyKinds, KindSignatures, GADTs #-}\r\nmodule TestConstraintKinds where\r\n import GHC.Exts hiding (Any)\r\n\r\n data WrappedType = forall a. WrapType a\r\n\r\n data A :: WrappedType -> * where\r\n MkA :: forall (a :: *). AW a -> A (WrapType a)\r\n\r\n type AW (a :: k) = A (WrapType a)\r\n type AW' (a :: k) = A (WrapType a)\r\n\r\n class C (a :: k) where\r\n aw :: AW a -- workaround: AW'\r\n\r\n instance C [] where\r\n aw = aw\r\n}}}\r\n\r\nGHC accepts the program when AW is replaced with AW' on that line.","type_of_failure":"OtherFailure","blocking":[]} -->8.0.1Simon Peyton JonesSimon Peyton Joneshttps://gitlab.haskell.org/ghc/ghc/-/issues/11196TypeInType performance regressions2021-03-31T16:11:18ZRichard Eisenbergrae@richarde.devTypeInType performance regressionsThis ticket is to track the handful of performance regressions seen with the addition of `TypeInType`. It is quite possibly a good idea to break these out into separate tickets, but until we investigate, they're all bundled here.
The re...This ticket is to track the handful of performance regressions seen with the addition of `TypeInType`. It is quite possibly a good idea to break these out into separate tickets, but until we investigate, they're all bundled here.
The regressions are (all in bytes allocated, unless otherwise noted):
- T3064, up by 14.9%
- T5030, up by 61.8%
- T5837, up by 13%
- T5321Fun, up by 11%
- T5631, up by 39%
- T9872d, **down** by 22% (see below)
- T9872a, up by 33.6%
- T9872c, up by 59.4%
- T9872b, up by 49.4%
- T9675, up by 29.7%, and peak megabytes allocated up by 28.4%
- haddock.base, up by 12.4%
- haddock.Cabal, up by 9.5%
I did add an optimization around type family reduction (the function `zonk_eq_types` in !TcCanonical) that could cause such a drastic reduction.8.4.1Richard Eisenbergrae@richarde.devRichard Eisenbergrae@richarde.devhttps://gitlab.haskell.org/ghc/ghc/-/issues/11241Kind-level PartialTypeSignatures causes internal error2019-07-07T18:31:19ZAdam GundryKind-level PartialTypeSignatures causes internal errorConsider the following module:
```hs
{-# LANGUAGE ExplicitForAll, KindSignatures, PartialTypeSignatures #-}
foo :: forall (a :: _) . a -> a
foo = id
```
In HEAD, this fails with an internal errror:
```
• GHC internal error: ‘_’...Consider the following module:
```hs
{-# LANGUAGE ExplicitForAll, KindSignatures, PartialTypeSignatures #-}
foo :: forall (a :: _) . a -> a
foo = id
```
In HEAD, this fails with an internal errror:
```
• GHC internal error: ‘_’ is not in scope during type checking, but it passed the renamer
tcl_env of environment: []
• In the kind ‘_’
In the type signature:
foo :: forall (a :: _). a -> a
```
I would expect it to succeed and figure out that the wildcard is `*`.
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | ----------------------- |
| Version | 7.11 |
| Type | Bug |
| TypeOfFailure | OtherFailure |
| Priority | normal |
| Resolution | Unresolved |
| Component | Compiler (Type checker) |
| Test case | |
| Differential revisions | |
| BlockedBy | |
| Related | |
| Blocking | |
| CC | goldfire |
| Operating system | |
| Architecture | |
</details>
<!-- {"blocked_by":[],"summary":"Kind-level PartialTypeSignatures causes internal error","status":"New","operating_system":"","component":"Compiler (Type checker)","related":[],"milestone":"","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"7.11","keywords":[],"differentials":[],"test_case":"","architecture":"","cc":["goldfire"],"type":"Bug","description":"Consider the following module:\r\n\r\n{{{#!hs\r\n{-# LANGUAGE ExplicitForAll, KindSignatures, PartialTypeSignatures #-}\r\n\r\nfoo :: forall (a :: _) . a -> a \r\nfoo = id \r\n}}}\r\n\r\nIn HEAD, this fails with an internal errror:\r\n\r\n{{{\r\n • GHC internal error: ‘_’ is not in scope during type checking, but it passed the renamer\r\n tcl_env of environment: []\r\n • In the kind ‘_’\r\n In the type signature:\r\n foo :: forall (a :: _). a -> a\r\n}}}\r\n\r\nI would expect it to succeed and figure out that the wildcard is `*`.","type_of_failure":"OtherFailure","blocking":[]} -->8.0.1Richard Eisenbergrae@richarde.devRichard Eisenbergrae@richarde.devhttps://gitlab.haskell.org/ghc/ghc/-/issues/11246Regression typechecking type synonym which includes `Any`.2019-07-07T18:31:17ZMatthew PickeringRegression typechecking type synonym which includes `Any`.```hs
module Foo where
import GHC.Exts
type Key a = Any
```
produces the error message on HEAD but compiles on 7.8.3 and 7.10.1 (thanks to Reid for testing).
```
unsafeany.hs:5:1: error:
• The type family ‘Any’ should have no arg...```hs
module Foo where
import GHC.Exts
type Key a = Any
```
produces the error message on HEAD but compiles on 7.8.3 and 7.10.1 (thanks to Reid for testing).
```
unsafeany.hs:5:1: error:
• The type family ‘Any’ should have no arguments, but has been given none
• In the type synonym declaration for ‘Key’
Failed, modules loaded: none.
```8.0.1Richard Eisenbergrae@richarde.devRichard Eisenbergrae@richarde.devhttps://gitlab.haskell.org/ghc/ghc/-/issues/11252:kind command hides the explicit kind2019-07-07T18:31:15ZIcelandjack:kind command hides the explicit kind```hs
-- /tmp/test.hs
{-# LANGUAGE TypeInType #-}
data Proxy1 k (a :: k) = P1
data Proxy2 (a :: k) = P2
```
if I load the following into ghci (head) the `:kind` command gives the same result
```haskell
% ghci -ignore-dot-ghci /tmp/t...```hs
-- /tmp/test.hs
{-# LANGUAGE TypeInType #-}
data Proxy1 k (a :: k) = P1
data Proxy2 (a :: k) = P2
```
if I load the following into ghci (head) the `:kind` command gives the same result
```haskell
% ghci -ignore-dot-ghci /tmp/test.hs
GHCi, version 7.11.20151216: http://www.haskell.org/ghc/ :? for help
[1 of 1] Compiling Main ( test.hs, interpreted )
Ok, modules loaded: Main.
*Main> :kind Proxy1
Proxy1 :: k -> *
*Main> :kind Proxy2
Proxy2 :: k -> *
```
edit: I asked on \#ghc, was told this was undesirable8.0.1Richard Eisenbergrae@richarde.devRichard Eisenbergrae@richarde.devhttps://gitlab.haskell.org/ghc/ghc/-/issues/11266Can't :browse some modules with GHCi 7.112019-07-07T18:31:12ZRyan ScottCan't :browse some modules with GHCi 7.11Trying to `:browse` certain modules with GHCi fails with GHC 7.11:
```
$ inplace/bin/ghc-stage2 --interactive
GHCi, version 7.11.20151219: http://www.haskell.org/ghc/ :? for help
λ> :browse GHC.Base
($) ::
forall (w :: GHC.Types.Levi...Trying to `:browse` certain modules with GHCi fails with GHC 7.11:
```
$ inplace/bin/ghc-stage2 --interactive
GHCi, version 7.11.20151219: http://www.haskell.org/ghc/ :? for help
λ> :browse GHC.Base
($) ::
forall (w :: GHC.Types.Levity) a (b :: TYPE w). (a -> b) -> a -> b
($!) :: (a -> b) -> a -> b
<lots of output elided>
data Ordering*** Exception: No match in record selector tyConTyVars
λ> :browse GHC.Exts
class GHC.Exts.IsList l where
type family GHC.Exts.Item l
Kind: * -> *
GHC.Exts.fromList :: [GHC.Exts.Item l] -> l
GHC.Exts.fromListN :: Int -> [GHC.Exts.Item l] -> l
GHC.Exts.toList :: l -> [GHC.Exts.Item l]
{-# MINIMAL fromList, toList #-}
<lots of output elided>
data GHC.Prim.MutableByteArray# a*** Exception: No match in record selector tyConTyVars
λ> :browse GHC.Prim
*** Exception: No match in record selector tyConTyVars
```
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | ------------ |
| Version | 7.11 |
| Type | Bug |
| TypeOfFailure | OtherFailure |
| Priority | high |
| Resolution | Unresolved |
| Component | GHCi |
| Test case | |
| Differential revisions | |
| BlockedBy | |
| Related | |
| Blocking | |
| CC | |
| Operating system | |
| Architecture | |
</details>
<!-- {"blocked_by":[],"summary":"Can't :browse some modules with GHCi 7.11","status":"New","operating_system":"","component":"GHCi","related":[],"milestone":"8.0.1","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"7.11","keywords":[],"differentials":[],"test_case":"","architecture":"","cc":[""],"type":"Bug","description":"Trying to `:browse` certain modules with GHCi fails with GHC 7.11:\r\n\r\n{{{\r\n$ inplace/bin/ghc-stage2 --interactive\r\nGHCi, version 7.11.20151219: http://www.haskell.org/ghc/ :? for help\r\nλ> :browse GHC.Base\r\n($) ::\r\n forall (w :: GHC.Types.Levity) a (b :: TYPE w). (a -> b) -> a -> b\r\n($!) :: (a -> b) -> a -> b\r\n<lots of output elided>\r\ndata Ordering*** Exception: No match in record selector tyConTyVars\r\nλ> :browse GHC.Exts\r\nclass GHC.Exts.IsList l where\r\n type family GHC.Exts.Item l\r\n Kind: * -> *\r\n GHC.Exts.fromList :: [GHC.Exts.Item l] -> l\r\n GHC.Exts.fromListN :: Int -> [GHC.Exts.Item l] -> l\r\n GHC.Exts.toList :: l -> [GHC.Exts.Item l]\r\n {-# MINIMAL fromList, toList #-}\r\n<lots of output elided>\r\ndata GHC.Prim.MutableByteArray# a*** Exception: No match in record selector tyConTyVars\r\nλ> :browse GHC.Prim\r\n*** Exception: No match in record selector tyConTyVars\r\n}}}","type_of_failure":"OtherFailure","blocking":[]} -->8.0.1https://gitlab.haskell.org/ghc/ghc/-/issues/11334GHC panic when calling typeOf on a promoted data constructor2019-07-07T18:30:53ZRyan ScottGHC panic when calling typeOf on a promoted data constructorHere's what I did in GHCi to trigger the panic:
```
$ inplace/bin/ghc-stage2 --interactive
GHCi, version 8.1.20160101: http://www.haskell.org/ghc/ :? for help
λ> :set -XDataKinds
λ> :m Data.Typeable Data.Functor.Compose
λ> typeOf (Prox...Here's what I did in GHCi to trigger the panic:
```
$ inplace/bin/ghc-stage2 --interactive
GHCi, version 8.1.20160101: http://www.haskell.org/ghc/ :? for help
λ> :set -XDataKinds
λ> :m Data.Typeable Data.Functor.Compose
λ> typeOf (Proxy :: Proxy 'Compose)
ghc-stage2: panic! (the 'impossible' happened)
(GHC version 8.1.20160101 for x86_64-unknown-linux):
piResultTy
*
TYPE 'Lifted *
Please report this as a GHC bug: http://www.haskell.org/ghc/reportabug
```
Enabling `-XPolyKinds` doesn't trigger the error, though; #10343 will be triggered instead:
```
λ> :set -XPolyKinds
λ> typeOf (Proxy :: Proxy 'Compose)
<interactive>:5:1: error:
• No instance for (Typeable a0) arising from a use of ‘typeOf’
• In the expression: typeOf (Proxy :: Proxy Compose)
In an equation for ‘it’: it = typeOf (Proxy :: Proxy Compose)
```
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | ----------------------- |
| Version | 8.1 |
| Type | Bug |
| TypeOfFailure | OtherFailure |
| Priority | high |
| Resolution | Unresolved |
| Component | Compiler (Type checker) |
| Test case | |
| Differential revisions | |
| BlockedBy | |
| Related | |
| Blocking | |
| CC | goldfire |
| Operating system | |
| Architecture | |
</details>
<!-- {"blocked_by":[],"summary":"GHC panic when calling typeOf on a promoted data constructor","status":"New","operating_system":"","component":"Compiler (Type checker)","related":[],"milestone":"","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"8.1","keywords":[],"differentials":[],"test_case":"","architecture":"","cc":["goldfire"],"type":"Bug","description":"Here's what I did in GHCi to trigger the panic:\r\n\r\n{{{\r\n$ inplace/bin/ghc-stage2 --interactive\r\nGHCi, version 8.1.20160101: http://www.haskell.org/ghc/ :? for help\r\nλ> :set -XDataKinds\r\nλ> :m Data.Typeable Data.Functor.Compose\r\nλ> typeOf (Proxy :: Proxy 'Compose)\r\nghc-stage2: panic! (the 'impossible' happened)\r\n (GHC version 8.1.20160101 for x86_64-unknown-linux):\r\n piResultTy\r\n *\r\n TYPE 'Lifted *\r\n\r\nPlease report this as a GHC bug: http://www.haskell.org/ghc/reportabug\r\n}}}\r\n\r\nEnabling `-XPolyKinds` doesn't trigger the error, though; #10343 will be triggered instead:\r\n\r\n{{{\r\nλ> :set -XPolyKinds\r\nλ> typeOf (Proxy :: Proxy 'Compose)\r\n\r\n<interactive>:5:1: error:\r\n • No instance for (Typeable a0) arising from a use of ‘typeOf’\r\n • In the expression: typeOf (Proxy :: Proxy Compose)\r\n In an equation for ‘it’: it = typeOf (Proxy :: Proxy Compose)\r\n}}}","type_of_failure":"OtherFailure","blocking":[]} -->8.0.1Richard Eisenbergrae@richarde.devRichard Eisenbergrae@richarde.devhttps://gitlab.haskell.org/ghc/ghc/-/issues/11339Possible type-checker regression in GHC 8.02019-07-07T18:30:52ZHerbert Valerio Riedelhvr@gnu.orgPossible type-checker regression in GHC 8.0The following code (extracted from hackage:microlens) type-checks on GHC 7.10 but **not** on GHC 8.0/8.1:
```hs
{-# LANGUAGE RankNTypes, ScopedTypeVariables #-}
module Failing where
import Control.Applicative ( Const(Const, getConst) ...The following code (extracted from hackage:microlens) type-checks on GHC 7.10 but **not** on GHC 8.0/8.1:
```hs
{-# LANGUAGE RankNTypes, ScopedTypeVariables #-}
module Failing where
import Control.Applicative ( Const(Const, getConst) )
import Data.Functor.Identity ( Identity(Identity) )
type Traversal s t a b = forall f. Applicative f => (a -> f b) -> s -> f t
failing :: forall s t a b . Traversal s t a b -> Traversal s t a b -> Traversal s t a b
failing left right afb s = case pins t of
[] -> right afb s
_ -> t afb
where
-- t :: (a -> f b) -> f t
-- TYPECHECKS with GHC 7.10, but not with GHC 8.x:
Bazaar { getBazaar = t } = left sell s
-- FAILS TO TYPECHECK with GHC 7.10 and GHC 8.x:
-- t = getBazaar (left sell s)
sell :: a -> Bazaar a b b
sell w = Bazaar ($ w)
pins :: ((a -> Const [Identity a] b) -> Const [Identity a] t) -> [Identity a]
pins f = getConst (f (\ra -> Const [Identity ra]))
newtype Bazaar a b t = Bazaar { getBazaar :: (forall f. Applicative f => (a -> f b) -> f t) }
instance Functor (Bazaar a b) where
fmap f (Bazaar k) = Bazaar (fmap f . k)
instance Applicative (Bazaar a b) where
pure a = Bazaar $ \_ -> pure a
Bazaar mf <*> Bazaar ma = Bazaar $ \afb -> mf afb <*> ma afb
```
The following error is emitted on GHC 8.0:
```
failing.hs:13:11: error:
• Couldn't match type ‘f’ with ‘Const [Identity a]’
‘f’ is a rigid type variable bound by
the type signature for:
failing :: forall (f :: * -> *). Applicative f => Traversal s t a b -> Traversal s t a b -> (a -> f b) -> s -> f t
at failing.hs:11:1
Expected type: a -> Const [Identity a] b
Actual type: a -> f b
• In the first argument of ‘t’, namely ‘afb’
In the expression: t afb
In a case alternative: _ -> t afb
• Relevant bindings include
t :: (a -> Const [Identity a] b) -> Const [Identity a] t (bound at failing.hs:18:26)
sell :: a -> Bazaar a b b (bound at failing.hs:24:5)
pins :: ((a -> Const [Identity a] b) -> Const [Identity a] t) -> [Identity a] (bound at failing.hs:27:5)
afb :: a -> f b (bound at failing.hs:11:20)
right :: Traversal s t a b (bound at failing.hs:11:14)
left :: Traversal s t a b (bound at failing.hs:11:9)
failing :: Traversal s t a b -> Traversal s t a b -> Traversal s t a b (bound at failing.hs:11:1)
```
I don't understand why `Bazaar t = ...` vs `t = getBazaar ...` makes a difference in GHC 7.10 at all. So I'm not sure if this is a regression or actually something that got fixed in GHC 8.0...
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | ----------------------- |
| Version | 8.1 |
| Type | Bug |
| TypeOfFailure | OtherFailure |
| Priority | highest |
| Resolution | Unresolved |
| Component | Compiler (Type checker) |
| Test case | |
| Differential revisions | |
| BlockedBy | |
| Related | |
| Blocking | |
| CC | bgamari, simonpj |
| Operating system | |
| Architecture | |
</details>
<!-- {"blocked_by":[],"summary":"Possible type-checker regression in GHC 8.0","status":"New","operating_system":"","component":"Compiler (Type checker)","related":[],"milestone":"8.0.1","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"8.1","keywords":[],"differentials":[],"test_case":"","architecture":"","cc":["bgamari","simonpj"],"type":"Bug","description":"The following code (extracted from hackage:microlens) type-checks on GHC 7.10 but '''not''' on GHC 8.0/8.1:\r\n\r\n{{{#!hs\r\n{-# LANGUAGE RankNTypes, ScopedTypeVariables #-}\r\n\r\nmodule Failing where\r\n\r\nimport Control.Applicative ( Const(Const, getConst) )\r\nimport Data.Functor.Identity ( Identity(Identity) )\r\n\r\ntype Traversal s t a b = forall f. Applicative f => (a -> f b) -> s -> f t\r\n\r\nfailing :: forall s t a b . Traversal s t a b -> Traversal s t a b -> Traversal s t a b\r\nfailing left right afb s = case pins t of\r\n [] -> right afb s\r\n _ -> t afb\r\n where\r\n -- t :: (a -> f b) -> f t\r\n\r\n -- TYPECHECKS with GHC 7.10, but not with GHC 8.x:\r\n Bazaar { getBazaar = t } = left sell s\r\n\r\n -- FAILS TO TYPECHECK with GHC 7.10 and GHC 8.x:\r\n -- t = getBazaar (left sell s)\r\n\r\n sell :: a -> Bazaar a b b\r\n sell w = Bazaar ($ w)\r\n\r\n pins :: ((a -> Const [Identity a] b) -> Const [Identity a] t) -> [Identity a]\r\n pins f = getConst (f (\\ra -> Const [Identity ra]))\r\n\r\nnewtype Bazaar a b t = Bazaar { getBazaar :: (forall f. Applicative f => (a -> f b) -> f t) }\r\n\r\ninstance Functor (Bazaar a b) where\r\n fmap f (Bazaar k) = Bazaar (fmap f . k)\r\n\r\ninstance Applicative (Bazaar a b) where\r\n pure a = Bazaar $ \\_ -> pure a\r\n Bazaar mf <*> Bazaar ma = Bazaar $ \\afb -> mf afb <*> ma afb\r\n}}}\r\n\r\nThe following error is emitted on GHC 8.0:\r\n\r\n{{{\r\nfailing.hs:13:11: error:\r\n • Couldn't match type ‘f’ with ‘Const [Identity a]’\r\n ‘f’ is a rigid type variable bound by\r\n the type signature for:\r\n failing :: forall (f :: * -> *). Applicative f => Traversal s t a b -> Traversal s t a b -> (a -> f b) -> s -> f t\r\n at failing.hs:11:1\r\n Expected type: a -> Const [Identity a] b\r\n Actual type: a -> f b\r\n • In the first argument of ‘t’, namely ‘afb’\r\n In the expression: t afb\r\n In a case alternative: _ -> t afb\r\n • Relevant bindings include\r\n t :: (a -> Const [Identity a] b) -> Const [Identity a] t (bound at failing.hs:18:26)\r\n sell :: a -> Bazaar a b b (bound at failing.hs:24:5)\r\n pins :: ((a -> Const [Identity a] b) -> Const [Identity a] t) -> [Identity a] (bound at failing.hs:27:5)\r\n afb :: a -> f b (bound at failing.hs:11:20)\r\n right :: Traversal s t a b (bound at failing.hs:11:14)\r\n left :: Traversal s t a b (bound at failing.hs:11:9)\r\n failing :: Traversal s t a b -> Traversal s t a b -> Traversal s t a b (bound at failing.hs:11:1)\r\n}}}\r\n\r\n\r\nI don't understand why `Bazaar t = ...` vs `t = getBazaar ...` makes a difference in GHC 7.10 at all. So I'm not sure if this is a regression or actually something that got fixed in GHC 8.0...","type_of_failure":"OtherFailure","blocking":[]} -->8.0.2Simon Peyton JonesSimon Peyton Joneshttps://gitlab.haskell.org/ghc/ghc/-/issues/11356GHC panic2019-07-07T18:30:46ZIcelandjackGHC panicThe attached file causes GHC (version 8.1.20160102) panic.
I tried shrinking, attached code is bogus at this point.
Interestingly inlining the type synonym `T = Nat` into Category's superclass context fixes the panic, and causes a regu...The attached file causes GHC (version 8.1.20160102) panic.
I tried shrinking, attached code is bogus at this point.
Interestingly inlining the type synonym `T = Nat` into Category's superclass context fixes the panic, and causes a regular error.
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | ----------------------- |
| Version | 8.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":"GHC panic","status":"New","operating_system":"","component":"Compiler (Type checker)","related":[],"milestone":"","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"8.1","keywords":[],"differentials":[],"test_case":"","architecture":"","cc":[""],"type":"Bug","description":"The attached file causes GHC (version 8.1.20160102) panic.\r\n\r\nI tried shrinking, attached code is bogus at this point.\r\n\r\nInterestingly inlining the type synonym `T = Nat` into Category's superclass context fixes the panic, and causes a regular error.","type_of_failure":"OtherFailure","blocking":[]} -->8.0.1https://gitlab.haskell.org/ghc/ghc/-/issues/11357Regression when deriving Generic1 on poly-kinded data family2019-07-07T18:30:45ZRyan ScottRegression when deriving Generic1 on poly-kinded data familyOn GHC 7.10.3, the following code compiles:
```hs
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE TypeFamilies #-}
module ProxyFam where
import GHC.Generics (Generic1)
data family...On GHC 7.10.3, the following code compiles:
```hs
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE TypeFamilies #-}
module ProxyFam where
import GHC.Generics (Generic1)
data family ProxyFam (a :: k)
data instance ProxyFam (a :: k) = ProxyCon deriving Generic1
```
But on GHC 8.1, it fails:
```
$ /opt/ghc/head/bin/ghc ProxyFam.hs
[1 of 1] Compiling ProxyFam ( ProxyFam.hs, ProxyFam.o )
ProxyFam.hs:10:53: error:
• Can't make a derived instance of ‘Generic1 ProxyFam’:
ProxyFam must not be instantiated; try deriving `ProxyFam k a' instead
• In the data instance declaration for ‘ProxyFam’
```
I'm not sure what exactly is going on here, but I have a hunch. The `Generic1` typeclass is of kind `* -> *`, which means that in a `Generic1 ProxyFam` instance, the kind of `a` is instantiated to `*`.
Curiously, though, the same error does *not* appear when `deriving Generic` for a normal datatype (e.g., `data ProxyFam (a :: k) = ProxyCon deriving Generic1`).
Richard, I'm stuck as to how to fix this. I suspect this was triggered by `-XTypeInType`-related changes, specifically, [this change](http://git.haskell.org/ghc.git/blobdiff/6e56ac58a6905197412d58e32792a04a63b94d7e..6746549772c5cc0ac66c0fce562f297f4d4b80a2:/compiler/typecheck/TcGenGenerics.hs):
```diff
diff --git a/compiler/typecheck/TcGenGenerics.hs b/compiler/typecheck/TcGenGenerics.hs
index 2c5b80e..fb18517 100644 (file)
--- a/compiler/typecheck/TcGenGenerics.hs
+++ b/compiler/typecheck/TcGenGenerics.hs
@@ -147,7 +146,7 @@ canDoGenerics tc tc_args
--
-- Data family indices can be instantiated; the `tc_args` here are
-- the representation tycon args
- (if (all isTyVarTy (filterOut isKind tc_args))
+ (if (all isTyVarTy (filterOutInvisibleTypes tc tc_args))
then IsValid
else NotValid (tc_name <+> text "must not be instantiated;" <+>
text "try deriving `" <> tc_name <+> tc_tys <>
```
What exactly does `filterOutInvisibleTypes` do?
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | ------------------ |
| Version | 8.1 |
| Type | Bug |
| TypeOfFailure | OtherFailure |
| Priority | high |
| Resolution | Unresolved |
| Component | Compiler (CodeGen) |
| Test case | |
| Differential revisions | |
| BlockedBy | |
| Related | |
| Blocking | |
| CC | goldfire |
| Operating system | |
| Architecture | |
</details>
<!-- {"blocked_by":[],"summary":"Regression when deriving Generic1 on poly-kinded data family","status":"New","operating_system":"","component":"Compiler (CodeGen)","related":[],"milestone":"","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"8.1","keywords":["Generics,","TypeInType"],"differentials":[],"test_case":"","architecture":"","cc":["goldfire"],"type":"Bug","description":"On GHC 7.10.3, the following code compiles:\r\n\r\n{{{#!hs\r\n{-# LANGUAGE DeriveGeneric #-}\r\n{-# LANGUAGE KindSignatures #-}\r\n{-# LANGUAGE PolyKinds #-}\r\n{-# LANGUAGE TypeFamilies #-}\r\nmodule ProxyFam where\r\n\r\nimport GHC.Generics (Generic1)\r\n\r\ndata family ProxyFam (a :: k)\r\ndata instance ProxyFam (a :: k) = ProxyCon deriving Generic1\r\n}}}\r\n\r\nBut on GHC 8.1, it fails:\r\n\r\n{{{\r\n$ /opt/ghc/head/bin/ghc ProxyFam.hs \r\n[1 of 1] Compiling ProxyFam ( ProxyFam.hs, ProxyFam.o )\r\n\r\nProxyFam.hs:10:53: error:\r\n • Can't make a derived instance of ‘Generic1 ProxyFam’:\r\n ProxyFam must not be instantiated; try deriving `ProxyFam k a' instead\r\n • In the data instance declaration for ‘ProxyFam’\r\n}}}\r\n\r\nI'm not sure what exactly is going on here, but I have a hunch. The `Generic1` typeclass is of kind `* -> *`, which means that in a `Generic1 ProxyFam` instance, the kind of `a` is instantiated to `*`.\r\n\r\nCuriously, though, the same error does ''not'' appear when `deriving Generic` for a normal datatype (e.g., `data ProxyFam (a :: k) = ProxyCon deriving Generic1`).\r\n\r\nRichard, I'm stuck as to how to fix this. I suspect this was triggered by `-XTypeInType`-related changes, specifically, [http://git.haskell.org/ghc.git/blobdiff/6e56ac58a6905197412d58e32792a04a63b94d7e..6746549772c5cc0ac66c0fce562f297f4d4b80a2:/compiler/typecheck/TcGenGenerics.hs this change]:\r\n\r\n{{{#!diff\r\ndiff --git a/compiler/typecheck/TcGenGenerics.hs b/compiler/typecheck/TcGenGenerics.hs\r\nindex 2c5b80e..fb18517 100644 (file)\r\n--- a/compiler/typecheck/TcGenGenerics.hs\r\n+++ b/compiler/typecheck/TcGenGenerics.hs\r\n@@ -147,7 +146,7 @@ canDoGenerics tc tc_args\r\n --\r\n -- Data family indices can be instantiated; the `tc_args` here are\r\n -- the representation tycon args\r\n- (if (all isTyVarTy (filterOut isKind tc_args))\r\n+ (if (all isTyVarTy (filterOutInvisibleTypes tc tc_args))\r\n then IsValid\r\n else NotValid (tc_name <+> text \"must not be instantiated;\" <+>\r\n text \"try deriving `\" <> tc_name <+> tc_tys <>\r\n}}}\r\n\r\nWhat exactly does `filterOutInvisibleTypes` do?","type_of_failure":"OtherFailure","blocking":[]} -->8.0.1Richard Eisenbergrae@richarde.devRichard Eisenbergrae@richarde.devhttps://gitlab.haskell.org/ghc/ghc/-/issues/11362T6137 doesn't pass with reversed uniques2019-07-07T18:30:44ZniteriaT6137 doesn't pass with reversed uniquesIt fails with (full trace https://phabricator.haskell.org/P81):
```
*** Core Lint errors : in result of Tidy Core ***
<no location info>: warning:
[in body of lambda with binder dt_a18nYf :: In
...It fails with (full trace https://phabricator.haskell.org/P81):
```
*** Core Lint errors : in result of Tidy Core ***
<no location info>: warning:
[in body of lambda with binder dt_a18nYf :: In
f_a18o2M
(Sum1 r_a18o2L (In ('F f_a18o2M) r_a18o2L))
o_a18o2K]
Kind application error in
coercion ‘Sym
(TFCo:R:InioFro[0]
<o_a18nYC>_N <i_a18nYD>_N <f_a18o2M>_N) <r_a18o2L>_N <o_a18o2K>_N’
Function kind = Code (Sum i_a18nYD o_a18nYC) o_a18nYC -> *
Arg kinds = [(o_a18o2K, o_a18nYC)]
<no location info>: warning:
[in body of lambda with binder dt_a18nYf :: In
f_a18o2M
(Sum1 r_a18o2L (In ('F f_a18o2M) r_a18o2L))
o_a18o2K]
Kind application error in
coercion ‘Sym
(TFCo:R:InioFro[0]
<o_a18nYC>_N <i_a18nYD>_N <f_a18o2M>_N) <r_a18o2L>_N <o_a18o2K>_N’
Function kind = Code (Sum i_a18nYD o_a18nYC) o_a18nYC -> *
Arg kinds = [(o_a18o2K, o_a18nYC)]
```
Steps to reproduce:
1. Add line
`TEST_HC_OPTS += -dinitial-unique=16777000 -dunique-increment=-1`
after line
`TEST_HC_OPTS = -fforce-recomp -dcore-lint -dcmm-lint -dno-debug-output -no-user-$(GhcPackageDbFlag) -rtsopts $(EXTRA_HC_OPTS)`
in `mk/test.mk`
1. `make TESTS=T6137`
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | --------------------------- |
| Version | 8.1 |
| Type | Bug |
| TypeOfFailure | OtherFailure |
| Priority | normal |
| Resolution | Unresolved |
| Component | Compiler |
| Test case | |
| Differential revisions | |
| BlockedBy | |
| Related | |
| Blocking | |
| CC | goldfire, simonmar, simonpj |
| Operating system | |
| Architecture | |
</details>
<!-- {"blocked_by":[],"summary":"T6137 doesn't pass with reversed uniques","status":"New","operating_system":"","component":"Compiler","related":[],"milestone":"","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"8.1","keywords":[],"differentials":[],"test_case":"","architecture":"","cc":["goldfire","simonmar","simonpj"],"type":"Bug","description":"It fails with (full trace https://phabricator.haskell.org/P81):\r\n\r\n{{{\r\n*** Core Lint errors : in result of Tidy Core ***\r\n<no location info>: warning:\r\n [in body of lambda with binder dt_a18nYf :: In\r\n f_a18o2M\r\n (Sum1 r_a18o2L (In ('F f_a18o2M) r_a18o2L))\r\n o_a18o2K]\r\n Kind application error in\r\n coercion ‘Sym\r\n (TFCo:R:InioFro[0]\r\n <o_a18nYC>_N <i_a18nYD>_N <f_a18o2M>_N) <r_a18o2L>_N <o_a18o2K>_N’\r\n Function kind = Code (Sum i_a18nYD o_a18nYC) o_a18nYC -> *\r\n Arg kinds = [(o_a18o2K, o_a18nYC)]\r\n<no location info>: warning:\r\n [in body of lambda with binder dt_a18nYf :: In\r\n f_a18o2M\r\n (Sum1 r_a18o2L (In ('F f_a18o2M) r_a18o2L))\r\n o_a18o2K]\r\n Kind application error in\r\n coercion ‘Sym\r\n (TFCo:R:InioFro[0]\r\n <o_a18nYC>_N <i_a18nYD>_N <f_a18o2M>_N) <r_a18o2L>_N <o_a18o2K>_N’\r\n Function kind = Code (Sum i_a18nYD o_a18nYC) o_a18nYC -> *\r\n Arg kinds = [(o_a18o2K, o_a18nYC)]\r\n}}}\r\n\r\n\r\nSteps to reproduce:\r\n\r\n1. Add line\r\n`TEST_HC_OPTS += -dinitial-unique=16777000 -dunique-increment=-1` \r\n\r\nafter line\r\n\r\n`TEST_HC_OPTS = -fforce-recomp -dcore-lint -dcmm-lint -dno-debug-output -no-user-$(GhcPackageDbFlag) -rtsopts $(EXTRA_HC_OPTS)` \r\n\r\nin `mk/test.mk`\r\n\r\n2. `make TESTS=T6137`\r\n","type_of_failure":"OtherFailure","blocking":[]} -->8.0.1niterianiteriahttps://gitlab.haskell.org/ghc/ghc/-/issues/11376Inconsistent specified type variables among functions and datatypes/classes w...2019-07-07T18:30:40ZRyan ScottInconsistent specified type variables among functions and datatypes/classes when using -XTypeApplicationsOriginally reported [here](https://mail.haskell.org/pipermail/ghc-devs/2016-January/010915.html). When applying types via `-XTypeApplications`, the type/kind that gets instantiated seems to be different depending on whether you're using ...Originally reported [here](https://mail.haskell.org/pipermail/ghc-devs/2016-January/010915.html). When applying types via `-XTypeApplications`, the type/kind that gets instantiated seems to be different depending on whether you're using functions, datatypes, or typeclasses.
Here's an example contrasting functions and datatypes:
```
$ /opt/ghc/head/bin/ghci
GHCi, version 8.1.20160106: http://www.haskell.org/ghc/ :? for help
λ> :set -fprint-explicit-kinds -XTypeApplications -XTypeInType
λ> data Prox a = Prox
λ> prox :: Prox a; prox = Prox
λ> :t prox
prox :: forall k (a :: k). Prox k a
λ> :t prox @Int
prox @Int :: Prox * Int
λ> :t Prox
Prox :: forall k (a :: k). Prox k a
λ> :t Prox @Int
Prox @Int :: Prox Int a
```
This is the core of the problem: with a function, `Int` seems to be applied to type variable `a`, whereas with data types, `Int` appears to be applied to the kind variable `k`. This confuses me, since `k` wasn't specified anywhere in the definition of `Prox`.
Andres Löh also [observed](https://mail.haskell.org/pipermail/ghc-devs/2016-January/010916.html) a similar discrepancy between functions and typeclasses:
```
λ> :set -XScopedTypeVariables
λ> class C a where c :: ()
λ> d :: forall a. C a => (); d = c @_ @a
λ> :t d
d :: forall k (a :: k). C k a => ()
λ> :t d @Int
d @Int :: C * Int => ()
λ> :t c
c :: forall k (a :: k). C k a => ()
λ> :t c @Int
c @Int :: C Int a => ()
λ> :t c @_ @Int
c @_ @Int :: C * Int => ()
```
EDIT: See also documentation infelicity in [ticket:11376\#comment:113518](https://gitlab.haskell.org//ghc/ghc/issues/11376#note_113518).
EDIT: Most of this is fix, as of March 25. But the data family stuff in [ticket:11376\#comment:114637](https://gitlab.haskell.org//ghc/ghc/issues/11376#note_114637) is still outstanding, and we need a test case.8.0.1Richard Eisenbergrae@richarde.devRichard Eisenbergrae@richarde.devhttps://gitlab.haskell.org/ghc/ghc/-/issues/11399Ill-kinded instance head involving -XTypeInType can invoke GHC panic2019-07-07T18:30:35ZRyan ScottIll-kinded instance head involving -XTypeInType can invoke GHC panicThis code:
```hs
{-# LANGUAGE FlexibleInstances, TypeInType #-}
module FvProvFallsIntoAHole where
import Data.Kind
newtype UhOh (k :: * -> *) (a :: k *) = UhOh (k *)
instance Functor k => Functor (UhOh k) where
```
produces this GHC ...This code:
```hs
{-# LANGUAGE FlexibleInstances, TypeInType #-}
module FvProvFallsIntoAHole where
import Data.Kind
newtype UhOh (k :: * -> *) (a :: k *) = UhOh (k *)
instance Functor k => Functor (UhOh k) where
```
produces this GHC panic:
```
$ /opt/ghc/head/bin/ghc FvProvFallsIntoAHole.hs
[1 of 1] Compiling FvProvFallsIntoAHole ( FvProvFallsIntoAHole.hs, FvProvFallsIntoAHole.o )
ghc: panic! (the 'impossible' happened)
(GHC version 8.1.20160108 for x86_64-unknown-linux):
fvProv falls into a hole {aq6}
Please report this as a GHC bug: http://www.haskell.org/ghc/reportabug
```
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | ----------------------- |
| Version | 8.1 |
| Type | Bug |
| TypeOfFailure | OtherFailure |
| Priority | normal |
| Resolution | Unresolved |
| Component | Compiler (Type checker) |
| Test case | |
| Differential revisions | |
| BlockedBy | |
| Related | |
| Blocking | |
| CC | goldfire |
| Operating system | |
| Architecture | |
</details>
<!-- {"blocked_by":[],"summary":"Ill-kinded instance head involving -XTypeInType can invoke GHC panic","status":"New","operating_system":"","component":"Compiler (Type checker)","related":[],"milestone":"","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"8.1","keywords":["TypeInType"],"differentials":[],"test_case":"","architecture":"","cc":["goldfire"],"type":"Bug","description":"This code:\r\n\r\n{{{#!hs\r\n{-# LANGUAGE FlexibleInstances, TypeInType #-}\r\nmodule FvProvFallsIntoAHole where\r\n\r\nimport Data.Kind\r\n\r\nnewtype UhOh (k :: * -> *) (a :: k *) = UhOh (k *)\r\ninstance Functor k => Functor (UhOh k) where\r\n}}}\r\n\r\nproduces this GHC panic:\r\n\r\n{{{\r\n$ /opt/ghc/head/bin/ghc FvProvFallsIntoAHole.hs\r\n[1 of 1] Compiling FvProvFallsIntoAHole ( FvProvFallsIntoAHole.hs, FvProvFallsIntoAHole.o )\r\nghc: panic! (the 'impossible' happened)\r\n (GHC version 8.1.20160108 for x86_64-unknown-linux):\r\n fvProv falls into a hole {aq6}\r\n\r\nPlease report this as a GHC bug: http://www.haskell.org/ghc/reportabug\r\n}}}","type_of_failure":"OtherFailure","blocking":[]} -->8.0.1Richard Eisenbergrae@richarde.devRichard Eisenbergrae@richarde.devhttps://gitlab.haskell.org/ghc/ghc/-/issues/11400* is not an indexed type family2019-07-07T18:30:35ZRyan Scott* is not an indexed type familyI can't seem to create an indexed data family using the kind `*` with `-XTypeInType` enabled. I have to work around it by using `Type`:
```
$ /opt/ghc/head/bin/ghci
GHCi, version 8.1.20160108: http://www.haskell.org/ghc/ :? for help
λ>...I can't seem to create an indexed data family using the kind `*` with `-XTypeInType` enabled. I have to work around it by using `Type`:
```
$ /opt/ghc/head/bin/ghci
GHCi, version 8.1.20160108: http://www.haskell.org/ghc/ :? for help
λ> :set -XTypeInType -XTypeFamilies
λ> import Data.Kind
λ> data family IdxProxy k (a :: k)
λ> data instance IdxProxy * a
<interactive>:5:1: error:
• Illegal family instance for ‘*’
(* is not an indexed type family)
• In the data instance declaration for ‘*’
λ> data instance IdxProxy Type a
λ> :kind! IdxProxy *
IdxProxy * :: * -> *
= IdxProxy *
λ> :kind! IdxProxy Type
IdxProxy Type :: Type -> *
= IdxProxy Type
```
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | ----------------------- |
| Version | 8.1 |
| Type | Bug |
| TypeOfFailure | OtherFailure |
| Priority | normal |
| Resolution | Unresolved |
| Component | Compiler (Type checker) |
| Test case | |
| Differential revisions | |
| BlockedBy | |
| Related | |
| Blocking | |
| CC | goldfire |
| Operating system | |
| Architecture | |
</details>
<!-- {"blocked_by":[],"summary":"* is not an indexed type family","status":"New","operating_system":"","component":"Compiler (Type checker)","related":[],"milestone":"","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"8.1","keywords":["TypeInType"],"differentials":[],"test_case":"","architecture":"","cc":["goldfire"],"type":"Bug","description":"I can't seem to create an indexed data family using the kind `*` with `-XTypeInType` enabled. I have to work around it by using `Type`:\r\n\r\n{{{\r\n$ /opt/ghc/head/bin/ghci\r\nGHCi, version 8.1.20160108: http://www.haskell.org/ghc/ :? for help\r\nλ> :set -XTypeInType -XTypeFamilies \r\nλ> import Data.Kind\r\nλ> data family IdxProxy k (a :: k)\r\nλ> data instance IdxProxy * a\r\n\r\n<interactive>:5:1: error:\r\n • Illegal family instance for ‘*’\r\n (* is not an indexed type family)\r\n • In the data instance declaration for ‘*’\r\nλ> data instance IdxProxy Type a\r\nλ> :kind! IdxProxy *\r\nIdxProxy * :: * -> *\r\n= IdxProxy *\r\nλ> :kind! IdxProxy Type\r\nIdxProxy Type :: Type -> *\r\n= IdxProxy Type\r\n}}}","type_of_failure":"OtherFailure","blocking":[]} -->8.2.2https://gitlab.haskell.org/ghc/ghc/-/issues/11401No match in record selector ctev_dest2019-07-07T18:30:35ZLemmingNo match in record selector ctev_destWith the llvm-tf package I got the following problem:
```
$ cat RecordSelectorCtevDest.hs
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE FlexibleInstances #-}
module RecordSelectorCtevDest where
newty...With the llvm-tf package I got the following problem:
```
$ cat RecordSelectorCtevDest.hs
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE FlexibleInstances #-}
module RecordSelectorCtevDest where
newtype Value a = Value a
newtype CodeGen r a = CodeGen a
bind :: CodeGen r a -> (a -> CodeGen r b) -> CodeGen r b
bind (CodeGen a) k = k a
class
(f ~ CalledFunction g, r ~ CallerResult g, g ~ CallerFunction f r) =>
CallArgs f g r where
type CalledFunction g :: *
type CallerResult g :: *
type CallerFunction f r :: *
call :: f -> g
instance CallArgs (IO a) (CodeGen r (Value a)) r where
type CalledFunction (CodeGen r (Value a)) = IO a
type CallerResult (CodeGen r (Value a)) = r
type CallerFunction (IO a) r = CodeGen r (Value a)
call = undefined
instance CallArgs b b' r => CallArgs (a -> b) (Value a -> b') r where
type CalledFunction (Value a -> b') = a -> CalledFunction b'
type CallerResult (Value a -> b') = CallerResult b'
type CallerFunction (a -> b) r = Value a -> CallerFunction b r
call = undefined
test :: IO a -> (a -> IO ()) -> CodeGen () (Value ())
test start stop = bind (call start) (call stop)
$ ghci-8.0.0.20160109 RecordSelectorCtevDest.hs
GHCi, version 8.0.0.20160109: http://www.haskell.org/ghc/ :? for help
[1 of 1] Compiling RecordSelectorCtevDest ( RecordSelectorCtevDest.hs, interpreted )
*** Exception: No match in record selector ctev_dest
```
The problem disappears when I remove the 'r' parameter from CodeGen, CallArgs and CallerFunction and remove the CallerResult consequently.8.0.1Richard Eisenbergrae@richarde.devRichard Eisenbergrae@richarde.devhttps://gitlab.haskell.org/ghc/ghc/-/issues/11404The type variable used in a kind is still used2019-07-07T18:30:34ZRichard Eisenbergrae@richarde.devThe type variable used in a kind is still usedFrom [D1739](https://phabricator.haskell.org/D1739).
When you say
```
undefined :: forall (v :: Levity) (a :: TYPE v). (?callStack :: CallStack) => a
```
you get a warning that `v` is unused.
I will fix.
<details><summary>Trac metad...From [D1739](https://phabricator.haskell.org/D1739).
When you say
```
undefined :: forall (v :: Levity) (a :: TYPE v). (?callStack :: CallStack) => a
```
you get a warning that `v` is unused.
I will fix.
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | ------------ |
| Version | 8.1 |
| 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":"The type variable used in a kind is still used","status":"New","operating_system":"","component":"Compiler","related":[],"milestone":"","resolution":"Unresolved","owner":{"tag":"OwnedBy","contents":"goldfire"},"version":"8.1","keywords":["TypeInType"],"differentials":[],"test_case":"","architecture":"","cc":[""],"type":"Bug","description":"From Phab:D1739.\r\n\r\nWhen you say\r\n\r\n{{{\r\nundefined :: forall (v :: Levity) (a :: TYPE v). (?callStack :: CallStack) => a\r\n}}}\r\n\r\nyou get a warning that `v` is unused.\r\n\r\nI will fix.","type_of_failure":"OtherFailure","blocking":[]} -->8.0.1Richard Eisenbergrae@richarde.devRichard Eisenbergrae@richarde.devhttps://gitlab.haskell.org/ghc/ghc/-/issues/11405Incorrect failure of type-level skolem escape check2019-07-07T18:30:34ZRichard Eisenbergrae@richarde.devIncorrect failure of type-level skolem escape checkFrom [D1739](https://phabricator.haskell.org/D1739).
When you say
```hs
undefined :: forall (v :: Levity). forall (a :: TYPE v). (?callStack :: CallStack) => a
```
you get a skolem escape failure because GHC things that the kind of `(...From [D1739](https://phabricator.haskell.org/D1739).
When you say
```hs
undefined :: forall (v :: Levity). forall (a :: TYPE v). (?callStack :: CallStack) => a
```
you get a skolem escape failure because GHC things that the kind of `(?callStack :: CallStack) => a` is `TYPE v`. It should be `*`.
I will fix.8.0.1Richard Eisenbergrae@richarde.devRichard Eisenbergrae@richarde.devhttps://gitlab.haskell.org/ghc/ghc/-/issues/11407-XTypeInType uses up all memory when used in data family instance2019-07-07T18:30:33ZRyan Scott-XTypeInType uses up all memory when used in data family instanceCompiling this code with GHC 8.1 causes all my memory to be used very quickly:
```hs
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeInType #-}
module TypeInTypeEatsAllMemory where
import Data.Kind
type Const a b = a
data family UhOh ...Compiling this code with GHC 8.1 causes all my memory to be used very quickly:
```hs
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeInType #-}
module TypeInTypeEatsAllMemory where
import Data.Kind
type Const a b = a
data family UhOh (f :: k1) (a :: k2) (b :: k3)
data instance UhOh (f :: * -> * -> *) (a :: forall a) (b :: Const * a) = UhOh
```
On the other hand, this code compiles without issue:
```hs
{-# LANGUAGE TypeInType #-}
module TypeInTypeEatsAllMemory where
import Data.Kind
type Const a b = a
data UhOh (f :: * -> * -> *) (a :: forall a) (b :: Const * a) = UhOh
```
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | ----------------------- |
| Version | 8.1 |
| Type | Bug |
| TypeOfFailure | OtherFailure |
| Priority | high |
| Resolution | Unresolved |
| Component | Compiler (Type checker) |
| Test case | |
| Differential revisions | |
| BlockedBy | |
| Related | |
| Blocking | |
| CC | goldfire |
| Operating system | |
| Architecture | |
</details>
<!-- {"blocked_by":[],"summary":"-XTypeInType uses up all memory when used in data family instance","status":"New","operating_system":"","component":"Compiler (Type checker)","related":[],"milestone":"","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"8.1","keywords":["TypeInType"],"differentials":[],"test_case":"","architecture":"","cc":["goldfire"],"type":"Bug","description":"Compiling this code with GHC 8.1 causes all my memory to be used very quickly:\r\n\r\n{{{#!hs\r\n{-# LANGUAGE TypeFamilies #-}\r\n{-# LANGUAGE TypeInType #-}\r\nmodule TypeInTypeEatsAllMemory where\r\n\r\nimport Data.Kind\r\n\r\ntype Const a b = a\r\n\r\ndata family UhOh (f :: k1) (a :: k2) (b :: k3)\r\ndata instance UhOh (f :: * -> * -> *) (a :: forall a) (b :: Const * a) = UhOh\r\n}}}\r\n\r\nOn the other hand, this code compiles without issue:\r\n\r\n{{{#!hs\r\n{-# LANGUAGE TypeInType #-}\r\nmodule TypeInTypeEatsAllMemory where\r\n\r\nimport Data.Kind\r\n\r\ntype Const a b = a\r\n\r\ndata UhOh (f :: * -> * -> *) (a :: forall a) (b :: Const * a) = UhOh\r\n}}}","type_of_failure":"OtherFailure","blocking":[]} -->8.0.1Richard Eisenbergrae@richarde.devRichard Eisenbergrae@richarde.devhttps://gitlab.haskell.org/ghc/ghc/-/issues/11410Quantification over unlifted type variable2019-07-07T18:30:32ZRichard Eisenbergrae@richarde.devQuantification over unlifted type variableThis silliness is accepted:
```
data X (a :: TYPE 'Unlifted) = X
```
I will fix.
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | ------------ |
| Version |...This silliness is accepted:
```
data X (a :: TYPE 'Unlifted) = X
```
I will fix.
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | ------------ |
| Version | 8.1 |
| 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":"Quantification over unlifted type variable","status":"New","operating_system":"","component":"Compiler","related":[],"milestone":"","resolution":"Unresolved","owner":{"tag":"OwnedBy","contents":"goldfire"},"version":"8.1","keywords":["TypeInType"],"differentials":[],"test_case":"","architecture":"","cc":[""],"type":"Bug","description":"This silliness is accepted:\r\n\r\n{{{\r\ndata X (a :: TYPE 'Unlifted) = X\r\n}}}\r\n\r\nI will fix.","type_of_failure":"OtherFailure","blocking":[]} -->Richard Eisenbergrae@richarde.devRichard Eisenbergrae@richarde.devhttps://gitlab.haskell.org/ghc/ghc/-/issues/11416GHC mistakenly believes datatype with type synonym in its type can't be eta-r...2019-07-07T18:30:31ZRyan ScottGHC mistakenly believes datatype with type synonym in its type can't be eta-reducedI uncovered this when playing around with `-XTypeInType`:
```hs
{-# LANGUAGE DeriveFunctor, TypeInType #-}
module CantEtaReduce1 where
import Data.Kind
type ConstantT a b = a
newtype T (f :: * -> *) (a :: ConstantT * f) = T (f a) deri...I uncovered this when playing around with `-XTypeInType`:
```hs
{-# LANGUAGE DeriveFunctor, TypeInType #-}
module CantEtaReduce1 where
import Data.Kind
type ConstantT a b = a
newtype T (f :: * -> *) (a :: ConstantT * f) = T (f a) deriving Functor
```
This fails because it thinks that you can't reduce the last type variable of `T`, since it mentions another type variable (`f`):
```
• Cannot eta-reduce to an instance of form
instance (...) => Functor (T f)
• In the newtype declaration for ‘T
```
But it *should* be able to, since `ConstantT * f` reduces to `*`, and the equivalent declaration `newtype T (f :: * -> *) (a :: *) = ...` eta-reduces just fine.
I marked this as appearing in GHC 8.1 since you need `-XTypeInType` to have kind synonyms, but this can also happen in earlier GHC versions with data families:
```hs
{-# LANGUAGE DeriveFunctor, PolyKinds, TypeFamilies #-}
module CantEtaReduce2 where
type ConstantT a b = a
data family T (f :: * -> *) (a :: *)
newtype instance T f (ConstantT a f) = T (f a) deriving Functor
```
I believe the fix will be to apply `coreView` with precision to parts of the code which typecheck `deriving` statements so that these type synonyms are peeled off.
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | ----------------------- |
| Version | 8.1 |
| Type | Bug |
| TypeOfFailure | OtherFailure |
| Priority | normal |
| Resolution | Unresolved |
| Component | Compiler (Type checker) |
| Test case | |
| Differential revisions | |
| BlockedBy | |
| Related | |
| Blocking | |
| CC | goldfire |
| Operating system | |
| Architecture | |
</details>
<!-- {"blocked_by":[],"summary":"GHC mistakenly believes datatype with type synonym in its type can't be eta-reduced","status":"New","operating_system":"","component":"Compiler (Type checker)","related":[],"milestone":"","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"8.1","keywords":["TypeInType"],"differentials":[],"test_case":"","architecture":"","cc":["goldfire"],"type":"Bug","description":"I uncovered this when playing around with `-XTypeInType`:\r\n\r\n{{{#!hs\r\n{-# LANGUAGE DeriveFunctor, TypeInType #-}\r\nmodule CantEtaReduce1 where\r\n\r\nimport Data.Kind\r\n\r\ntype ConstantT a b = a\r\nnewtype T (f :: * -> *) (a :: ConstantT * f) = T (f a) deriving Functor\r\n}}}\r\n\r\nThis fails because it thinks that you can't reduce the last type variable of `T`, since it mentions another type variable (`f`):\r\n\r\n{{{\r\n • Cannot eta-reduce to an instance of form\r\n instance (...) => Functor (T f)\r\n • In the newtype declaration for ‘T\r\n}}}\r\n\r\nBut it ''should'' be able to, since `ConstantT * f` reduces to `*`, and the equivalent declaration `newtype T (f :: * -> *) (a :: *) = ...` eta-reduces just fine.\r\n\r\nI marked this as appearing in GHC 8.1 since you need `-XTypeInType` to have kind synonyms, but this can also happen in earlier GHC versions with data families:\r\n\r\n{{{#!hs\r\n{-# LANGUAGE DeriveFunctor, PolyKinds, TypeFamilies #-}\r\nmodule CantEtaReduce2 where\r\n\r\ntype ConstantT a b = a\r\ndata family T (f :: * -> *) (a :: *)\r\nnewtype instance T f (ConstantT a f) = T (f a) deriving Functor\r\n}}}\r\n\r\nI believe the fix will be to apply `coreView` with precision to parts of the code which typecheck `deriving` statements so that these type synonyms are peeled off.","type_of_failure":"OtherFailure","blocking":[]} -->8.0.1https://gitlab.haskell.org/ghc/ghc/-/issues/11453Kinds in type synonym/data declarations can unexpectedly unify2019-07-07T18:30:21ZRyan ScottKinds in type synonym/data declarations can unexpectedly unifyWhile trying out ideas to fix [this lens issue](https://github.com/ekmett/lens/issues/626), I noticed a couple of peculiar things about kinds in type synonym and data declarations. For example:
```
$ /opt/ghc/head/bin/ghci -XTypeInType ...While trying out ideas to fix [this lens issue](https://github.com/ekmett/lens/issues/626), I noticed a couple of peculiar things about kinds in type synonym and data declarations. For example:
```
$ /opt/ghc/head/bin/ghci -XTypeInType -XRankNTypes -XTypeOperators
GHCi, version 8.1.20160113: http://www.haskell.org/ghc/ :? for help
Loaded GHCi configuration from /home/xnux/.ghci
λ> import Data.Kind
λ> type Wat (a :: k2) (b :: k3) = forall (f :: k1 -> *). Either (f a) (f b)
λ> :i Wat
type Wat (a :: k1) (b :: k1) =
forall (f :: k1 -> *). Either (f a) (f b)
-- Defined at <interactive>:2:1
```
This is pretty odd for two reasons. One, the kind `k1` was never specified (either existentially or as a visible kind binder), so that definition should have been rejected. But even if we do use an existential kind:
```
λ> type Wat (a :: k2) (b :: k3) = forall k1 (f :: k1 -> *). Either (f a) (f b)
λ> :i Wat
type Wat (a :: k1) (b :: k1) =
forall k2 (f :: k2 -> *). Either (f a) (f b)
-- Defined at <interactive>:4:1
```
We still see the second issue: GHC thinks that the type variables `a` and `b` have the same kind `k1`, when they should have separate kinds `k1` and `k2`! That behavior is very surprising to me, since it seems like GHC is choosing to unify two kind variables that should be rigid.
Note that this doesn't happen if you use explicit kind binders:
```
type Wat k2 k3 (a :: k2) (b :: k3) = forall k1 (f :: k1 -> *). Either (f a) (f b)
<interactive>:6:74: error:
• Expected kind ‘k1’, but ‘a’ has kind ‘k2’
• In the first argument of ‘f’, namely ‘a’
In the first argument of ‘Either’, namely ‘f a’
In the type ‘forall k1 (f :: k1 -> *). Either (f a) (f b)’
<interactive>:6:80: error:
• Expected kind ‘k1’, but ‘b’ has kind ‘k3’
• In the first argument of ‘f’, namely ‘b’
In the second argument of ‘Either’, namely ‘f b’
In the type ‘forall k1 (f :: k1 -> *). Either (f a) (f b)’
```
only when the kinds are specified but not visible.
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | ----------------------- |
| Version | 8.1 |
| Type | Bug |
| TypeOfFailure | OtherFailure |
| Priority | normal |
| Resolution | Unresolved |
| Component | Compiler (Type checker) |
| Test case | |
| Differential revisions | |
| BlockedBy | |
| Related | |
| Blocking | |
| CC | goldfire |
| Operating system | |
| Architecture | |
</details>
<!-- {"blocked_by":[],"summary":"Kinds in type synonym/data declarations can unexpectedly unify","status":"New","operating_system":"","component":"Compiler (Type checker)","related":[],"milestone":"","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"8.1","keywords":["TypeInType"],"differentials":[],"test_case":"","architecture":"","cc":["goldfire"],"type":"Bug","description":"While trying out ideas to fix [https://github.com/ekmett/lens/issues/626 this lens issue], I noticed a couple of peculiar things about kinds in type synonym and data declarations. For example:\r\n\r\n{{{\r\n$ /opt/ghc/head/bin/ghci -XTypeInType -XRankNTypes -XTypeOperators\r\nGHCi, version 8.1.20160113: http://www.haskell.org/ghc/ :? for help\r\nLoaded GHCi configuration from /home/xnux/.ghci\r\nλ> import Data.Kind\r\nλ> type Wat (a :: k2) (b :: k3) = forall (f :: k1 -> *). Either (f a) (f b)\r\nλ> :i Wat\r\ntype Wat (a :: k1) (b :: k1) =\r\n forall (f :: k1 -> *). Either (f a) (f b)\r\n -- Defined at <interactive>:2:1\r\n}}}\r\n\r\nThis is pretty odd for two reasons. One, the kind {{{k1}}} was never specified (either existentially or as a visible kind binder), so that definition should have been rejected. But even if we do use an existential kind:\r\n\r\n{{{\r\nλ> type Wat (a :: k2) (b :: k3) = forall k1 (f :: k1 -> *). Either (f a) (f b)\r\nλ> :i Wat\r\ntype Wat (a :: k1) (b :: k1) =\r\n forall k2 (f :: k2 -> *). Either (f a) (f b)\r\n -- Defined at <interactive>:4:1\r\n}}}\r\n\r\nWe still see the second issue: GHC thinks that the type variables `a` and `b` have the same kind `k1`, when they should have separate kinds `k1` and `k2`! That behavior is very surprising to me, since it seems like GHC is choosing to unify two kind variables that should be rigid.\r\n\r\nNote that this doesn't happen if you use explicit kind binders:\r\n\r\n{{{\r\ntype Wat k2 k3 (a :: k2) (b :: k3) = forall k1 (f :: k1 -> *). Either (f a) (f b)\r\n\r\n<interactive>:6:74: error:\r\n • Expected kind ‘k1’, but ‘a’ has kind ‘k2’\r\n • In the first argument of ‘f’, namely ‘a’\r\n In the first argument of ‘Either’, namely ‘f a’\r\n In the type ‘forall k1 (f :: k1 -> *). Either (f a) (f b)’\r\n\r\n<interactive>:6:80: error:\r\n • Expected kind ‘k1’, but ‘b’ has kind ‘k3’\r\n • In the first argument of ‘f’, namely ‘b’\r\n In the second argument of ‘Either’, namely ‘f b’\r\n In the type ‘forall k1 (f :: k1 -> *). Either (f a) (f b)’\r\n}}}\r\n\r\nonly when the kinds are specified but not visible.","type_of_failure":"OtherFailure","blocking":[]} -->https://gitlab.haskell.org/ghc/ghc/-/issues/11463Template Haskell applies too many arguments to kind synonym2022-02-08T15:14:11ZRyan ScottTemplate Haskell applies too many arguments to kind synonymRunning the following code:
```hs
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeInType #-}
module IdStarK where
import Data.Kind
import Language.Haskell.TH
type Id a = a
data Proxy (a :: Id k) = Proxy
$(return [])
main :: IO ()
...Running the following code:
```hs
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeInType #-}
module IdStarK where
import Data.Kind
import Language.Haskell.TH
type Id a = a
data Proxy (a :: Id k) = Proxy
$(return [])
main :: IO ()
main = do
putStrLn $(reify ''Proxy >>= stringE . pprint)
putStrLn $(reify ''Proxy >>= stringE . show)
```
Gives a result I wouldn't have expected:
```
$ /opt/ghc/head/bin/runghc IdStarK.hs
data IdStarK.Proxy (a_0 :: IdStarK.Id * k_1) = IdStarK.Proxy
TyConI (DataD [] IdStarK.Proxy [KindedTV a_1627394516 (AppT (AppT (ConT IdStarK.Id) StarT) (VarT k_1627394515))] Nothing [NormalC IdStarK.Proxy []] [])
```
From the output, it appears that `Id` is being applied to *two* arguments, both `*` and `k`! Perhaps this indirectly (or directly) a consequence of #11376?
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | ---------------- |
| Version | 8.0.1-rc1 |
| Type | Bug |
| TypeOfFailure | OtherFailure |
| Priority | normal |
| Resolution | Unresolved |
| Component | Template Haskell |
| Test case | |
| Differential revisions | |
| BlockedBy | |
| Related | #11376 |
| Blocking | |
| CC | goldfire |
| Operating system | |
| Architecture | |
</details>
<!-- {"blocked_by":[],"summary":"Template Haskell applies too many arguments to kind synonym","status":"New","operating_system":"","component":"Template Haskell","related":[11376],"milestone":"","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"8.0.1-rc1","keywords":["TypeApplications","TypeInType,"],"differentials":[],"test_case":"","architecture":"","cc":["goldfire"],"type":"Bug","description":"Running the following code:\r\n\r\n{{{#!hs\r\n{-# LANGUAGE TemplateHaskell #-}\r\n{-# LANGUAGE TypeInType #-}\r\nmodule IdStarK where\r\n\r\nimport Data.Kind\r\nimport Language.Haskell.TH\r\n\r\ntype Id a = a\r\ndata Proxy (a :: Id k) = Proxy\r\n\r\n$(return [])\r\n\r\nmain :: IO ()\r\nmain = do\r\n putStrLn $(reify ''Proxy >>= stringE . pprint)\r\n putStrLn $(reify ''Proxy >>= stringE . show)\r\n}}}\r\n\r\nGives a result I wouldn't have expected:\r\n\r\n{{{\r\n$ /opt/ghc/head/bin/runghc IdStarK.hs \r\ndata IdStarK.Proxy (a_0 :: IdStarK.Id * k_1) = IdStarK.Proxy\r\nTyConI (DataD [] IdStarK.Proxy [KindedTV a_1627394516 (AppT (AppT (ConT IdStarK.Id) StarT) (VarT k_1627394515))] Nothing [NormalC IdStarK.Proxy []] [])\r\n}}}\r\n\r\nFrom the output, it appears that `Id` is being applied to ''two'' arguments, both `*` and `k`! Perhaps this indirectly (or directly) a consequence of #11376?","type_of_failure":"OtherFailure","blocking":[]} -->8.0.1https://gitlab.haskell.org/ghc/ghc/-/issues/11471Kind polymorphism and unboxed types: bad things are happening2019-07-07T18:30:16ZBen GamariKind polymorphism and unboxed types: bad things are happeningThis Note, found in TyCoRep, needs to be updated to reflect `TypeInType`. It should not reference `OpenKind`.
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | ---...This Note, found in TyCoRep, needs to be updated to reflect `TypeInType`. It should not reference `OpenKind`.
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | ----------------------- |
| Version | 7.10.3 |
| Type | Task |
| 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":"Note [The kind invariant] in TyCoRep needs to be updated","status":"New","operating_system":"","component":"Compiler (Type checker)","related":[],"milestone":"","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"7.10.3","keywords":["TypeInType"],"differentials":[],"test_case":"","architecture":"","cc":[""],"type":"Task","description":"This Note, found in TyCoRep, needs to be updated to reflect `TypeInType`. It should not reference `OpenKind`.","type_of_failure":"OtherFailure","blocking":[]} -->8.0.1Richard Eisenbergrae@richarde.devRichard Eisenbergrae@richarde.devhttps://gitlab.haskell.org/ghc/ghc/-/issues/11473Levity polymorphism checks are inadequate2019-07-07T18:30:16ZSimon Peyton JonesLevity polymorphism checks are inadequateBen found
```hs
{-# LANGUAGE PolyKinds, TypeFamilies, MagicHash, DataKinds, TypeInType, RankNTypes #-}
import GHC.Exts
import GHC.Types
type family Boxed (a :: k) :: *
type instance Boxed Char# = Char
type instance Boxed Char = Char
...Ben found
```hs
{-# LANGUAGE PolyKinds, TypeFamilies, MagicHash, DataKinds, TypeInType, RankNTypes #-}
import GHC.Exts
import GHC.Types
type family Boxed (a :: k) :: *
type instance Boxed Char# = Char
type instance Boxed Char = Char
class BoxIt (a :: TYPE lev) where
boxed :: a -> Boxed a
instance BoxIt Char# where boxed x = C# x
instance BoxIt Char where boxed = id
hello :: forall (lev :: Levity). forall (a :: TYPE lev). BoxIt a => a -> Boxed a
hello x = boxed x
{-# NOINLINE hello #-}
main :: IO ()
main = do
print $ boxed 'c'#
print $ boxed 'c'
print $ hello 'c'
print $ hello 'c'#
```
This is plainly wrong because we have a polymorphic function `boxed` that is being passed both boxed and unboxed arguments.
You do get a Lint error with `-dcore-lint`.
But the original problem is with the type signature for `boxed`. We should never have a levity-polymorphic type to the left of an arrow. To the right yes, but to the left no. I suppose we could check that in `TcValidity`.
See also #114718.0.1Richard Eisenbergrae@richarde.devRichard Eisenbergrae@richarde.devhttps://gitlab.haskell.org/ghc/ghc/-/issues/11484Type synonym using -XTypeInType can't be spliced with TH2019-07-07T18:30:13ZRyan ScottType synonym using -XTypeInType can't be spliced with THThe following code compiles:
```hs
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeInType #-}
{-# OPTIONS_GHC -ddump-splices #-}
module Foo where
import Data.Kind
type TySyn (k :: *) (a :: k) = ()
-- $([d| type TySyn2 (k :: *) (a :...The following code compiles:
```hs
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeInType #-}
{-# OPTIONS_GHC -ddump-splices #-}
module Foo where
import Data.Kind
type TySyn (k :: *) (a :: k) = ()
-- $([d| type TySyn2 (k :: *) (a :: k) = () |])
```
But uncomment the last line, and it doesn't compile:
```
$ /opt/ghc/head/bin/ghc Foo.hs
[1 of 1] Compiling Foo ( Foo.hs, Foo.o )
Foo.hs:10:3-43: Splicing declarations
[d| type TySyn2_aBH (k_aBI :: *) (a_aBJ :: k_aBI) = () |]
======>
type TySyn2_a4BF (k_a4BG :: Type) (a_a4BH :: k_a4BG) = ()
Foo.hs:10:3: error:
• Couldn't match expected kind ‘GHC.Prim.Any’ with actual kind ‘k1’
• In the type declaration for ‘TySyn2’
Foo.hs:10:3: error:
• Kind variable ‘k_a4BG’ is implicitly bound in datatype
‘TySyn2’, but does not appear as the kind of any
of its type variables. Perhaps you meant
to bind it (with TypeInType) explicitly somewhere?
Type variables with inferred kinds: k_a4BG (a_a4BH :: GHC.Prim.Any)
• In the type declaration for ‘TySyn2’
```
There are two issues here:
1. The error message claims that `TySyn2` is a datatype when it is actually a type synonym. This should be easy enough to fix; just change [the code](http://git.haskell.org/ghc.git/blob/89bdac7635e6ed08927d760aa885d3e7ef3edb81:/compiler/typecheck/TcHsType.hs#l1874) that throws the error message to invoke [tyConFlavour](http://git.haskell.org/ghc.git/blob/89bdac7635e6ed08927d760aa885d3e7ef3edb81:/compiler/types/TyCon.hs#l1957).
1. For some reason, the type variable `a` in `TySyn2` fails to kind-check. Somehow, an `Any` got in there, but I'm not sure where it snuck in.
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | ---------------- |
| Version | 8.0.1-rc1 |
| Type | Bug |
| TypeOfFailure | OtherFailure |
| Priority | normal |
| Resolution | Unresolved |
| Component | Template Haskell |
| Test case | |
| Differential revisions | |
| BlockedBy | |
| Related | |
| Blocking | |
| CC | goldfire |
| Operating system | |
| Architecture | |
</details>
<!-- {"blocked_by":[],"summary":"Type synonym using -XTypeInType can't be spliced with TH","status":"New","operating_system":"","component":"Template Haskell","related":[],"milestone":"","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"8.0.1-rc1","keywords":["TypeInType"],"differentials":[],"test_case":"","architecture":"","cc":["goldfire"],"type":"Bug","description":"The following code compiles:\r\n\r\n{{{#!hs\r\n{-# LANGUAGE TemplateHaskell #-}\r\n{-# LANGUAGE TypeInType #-}\r\n{-# OPTIONS_GHC -ddump-splices #-}\r\nmodule Foo where\r\n\r\nimport Data.Kind\r\n\r\ntype TySyn (k :: *) (a :: k) = ()\r\n\r\n-- $([d| type TySyn2 (k :: *) (a :: k) = () |])\r\n}}}\r\n\r\nBut uncomment the last line, and it doesn't compile:\r\n\r\n{{{\r\n$ /opt/ghc/head/bin/ghc Foo.hs \r\n[1 of 1] Compiling Foo ( Foo.hs, Foo.o )\r\nFoo.hs:10:3-43: Splicing declarations\r\n [d| type TySyn2_aBH (k_aBI :: *) (a_aBJ :: k_aBI) = () |]\r\n ======>\r\n type TySyn2_a4BF (k_a4BG :: Type) (a_a4BH :: k_a4BG) = ()\r\n\r\nFoo.hs:10:3: error:\r\n • Couldn't match expected kind ‘GHC.Prim.Any’ with actual kind ‘k1’\r\n • In the type declaration for ‘TySyn2’\r\n\r\nFoo.hs:10:3: error:\r\n • Kind variable ‘k_a4BG’ is implicitly bound in datatype\r\n ‘TySyn2’, but does not appear as the kind of any\r\n of its type variables. Perhaps you meant\r\n to bind it (with TypeInType) explicitly somewhere?\r\n Type variables with inferred kinds: k_a4BG (a_a4BH :: GHC.Prim.Any)\r\n • In the type declaration for ‘TySyn2’\r\n}}}\r\n\r\nThere are two issues here:\r\n\r\n1. The error message claims that `TySyn2` is a datatype when it is actually a type synonym. This should be easy enough to fix; just change [http://git.haskell.org/ghc.git/blob/89bdac7635e6ed08927d760aa885d3e7ef3edb81:/compiler/typecheck/TcHsType.hs#l1874 the code] that throws the error message to invoke [http://git.haskell.org/ghc.git/blob/89bdac7635e6ed08927d760aa885d3e7ef3edb81:/compiler/types/TyCon.hs#l1957 tyConFlavour].\r\n2. For some reason, the type variable `a` in `TySyn2` fails to kind-check. Somehow, an `Any` got in there, but I'm not sure where it snuck in.","type_of_failure":"OtherFailure","blocking":[]} -->8.0.2https://gitlab.haskell.org/ghc/ghc/-/issues/11485Very unhelpful message resulting from kind mismatch2019-07-07T18:30:13ZRyan ScottVery unhelpful message resulting from kind mismatchThe following code:
```hs
module Foo where
import Data.Typeable
tyConOf :: Typeable a => Proxy a -> TyCon
tyConOf = typeRepTyCon . typeRep
tcList :: TyCon
tcList = tyConOf (Proxy :: Proxy [])
```
fails because `-XPolyKinds` is not e...The following code:
```hs
module Foo where
import Data.Typeable
tyConOf :: Typeable a => Proxy a -> TyCon
tyConOf = typeRepTyCon . typeRep
tcList :: TyCon
tcList = tyConOf (Proxy :: Proxy [])
```
fails because `-XPolyKinds` is not enabled. But the error message that you get is quite different on GHC 7.10 and 8.0.
On GHC 7.10.3:
```
[1 of 1] Compiling Foo ( Foo.hs, Foo.o )
Foo.hs:9:19:
Couldn't match kind ‘* -> *’ with ‘*’
Expected type: Proxy a0
Actual type: Proxy []
In the first argument of ‘tyConOf’, namely ‘(Proxy :: Proxy [])’
In the expression: tyConOf (Proxy :: Proxy [])
In an equation for ‘tcList’: tcList = tyConOf (Proxy :: Proxy [])
```
But on GHC 8.0.1-rc1:
```
Foo.hs:9:19: error:
• Expected kind ‘Proxy []’,
but ‘Data.Proxy.Proxy :: Proxy []’ has kind ‘Proxy []’
• In the first argument of ‘tyConOf’, namely ‘(Proxy :: Proxy [])’
In the expression: tyConOf (Proxy :: Proxy [])
In an equation for ‘tcList’: tcList = tyConOf (Proxy :: Proxy [])
```
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | ----------------------- |
| Version | 8.0.1-rc1 |
| 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":"Very unhelpful message resulting from kind mismatch","status":"New","operating_system":"","component":"Compiler (Type checker)","related":[],"milestone":"","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"8.0.1-rc1","keywords":[],"differentials":[],"test_case":"","architecture":"","cc":[""],"type":"Bug","description":"The following code:\r\n\r\n{{{#!hs\r\nmodule Foo where\r\n\r\nimport Data.Typeable\r\n\r\ntyConOf :: Typeable a => Proxy a -> TyCon\r\ntyConOf = typeRepTyCon . typeRep\r\n\r\ntcList :: TyCon\r\ntcList = tyConOf (Proxy :: Proxy [])\r\n}}}\r\n\r\nfails because `-XPolyKinds` is not enabled. But the error message that you get is quite different on GHC 7.10 and 8.0.\r\n\r\nOn GHC 7.10.3:\r\n\r\n{{{\r\n[1 of 1] Compiling Foo ( Foo.hs, Foo.o )\r\n\r\nFoo.hs:9:19:\r\n Couldn't match kind ‘* -> *’ with ‘*’\r\n Expected type: Proxy a0\r\n Actual type: Proxy []\r\n In the first argument of ‘tyConOf’, namely ‘(Proxy :: Proxy [])’\r\n In the expression: tyConOf (Proxy :: Proxy [])\r\n In an equation for ‘tcList’: tcList = tyConOf (Proxy :: Proxy [])\r\n}}}\r\n\r\nBut on GHC 8.0.1-rc1:\r\n\r\n{{{\r\nFoo.hs:9:19: error: \r\n • Expected kind ‘Proxy []’, \r\n but ‘Data.Proxy.Proxy :: Proxy []’ has kind ‘Proxy []’ \r\n • In the first argument of ‘tyConOf’, namely ‘(Proxy :: Proxy [])’ \r\n In the expression: tyConOf (Proxy :: Proxy [])\r\n In an equation for ‘tcList’: tcList = tyConOf (Proxy :: Proxy [])\r\n}}}","type_of_failure":"OtherFailure","blocking":[]} -->8.0.1https://gitlab.haskell.org/ghc/ghc/-/issues/11519Inferring non-tau kinds2019-07-07T18:30:05ZRichard Eisenbergrae@richarde.devInferring non-tau kindsWhile up to my usual type-level shenanigans, I found that I want this definition:
```
data TypeRep (a :: k) -- abstract
data TypeRepX :: (forall k. k -> Constraint) -> Type where
TypeRepX :: forall k (c :: forall k'. k' -> Constraint...While up to my usual type-level shenanigans, I found that I want this definition:
```
data TypeRep (a :: k) -- abstract
data TypeRepX :: (forall k. k -> Constraint) -> Type where
TypeRepX :: forall k (c :: forall k'. k' -> Constraint) (a :: k).
c a => TypeRep a -> TypeRepX c
```
Note `TypeRepX`'s higher-rank kind. The idea is that I want to optionally constrain `TypeRepX`'s payload. Without using a higher-rank kind, the constraint would necessary fix the kind of the payload, and I don't want that. For example, I sometimes use `TypeRepX ConstTrue`, where
```
class ConstTrue (a :: k)
instance ConstTrue a
```
This actually works just fine, and I've been using the above definition to good effect.
But then I wanted a `Show` instance:
```
instance Show (TypeRep a) -- elsewhere
instance Show (TypeRepX c) where
show (TypeRepX tr) = show t
```
Looks sensible. But GHC complains. This is because it tries to infer `c`'s kind, by inventing a unification variable and then unifying. But this doesn't work, of course, because `c`'s kind is not a tau-type, so unification fails, lest we let impredicativity sneak in. What's particularly vexing is that, even if I annotate `c` with the correct kind, unification *still* fails. This is because that `c` is a *usage* of `c`, not a *binding* of `c`. Indeed, there is no place in an instance declaration to bind a type variable explicitly, so I have no recourse.
I'm not sure what the solution is here. Somehow, it feels that inferring a non-tau kind for `c` is perfectly safe, because the kind is known from the use of `TypeRepX`. This would allow me to drop the kind annotation in the definition of `TypeRepX`, which looks redundant to me. But I'm not fully sure about this assumption.
At the least, we could introduce a spot for explicit binding of type variables in instance declarations.
I think, actually, I just figured it out. Use `ExpType`s when kind-checking types. Then I think the normal bidirectional thing (actually already implemented) will do the Right Thing.
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | ------------ |
| Version | 8.1 |
| 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":"Inferring non-tau kinds","status":"New","operating_system":"","component":"Compiler","related":[],"milestone":"","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"8.1","keywords":["TypeInType"],"differentials":[],"test_case":"","architecture":"","cc":[""],"type":"Bug","description":"While up to my usual type-level shenanigans, I found that I want this definition:\r\n\r\n{{{\r\ndata TypeRep (a :: k) -- abstract\r\n\r\ndata TypeRepX :: (forall k. k -> Constraint) -> Type where\r\n TypeRepX :: forall k (c :: forall k'. k' -> Constraint) (a :: k).\r\n c a => TypeRep a -> TypeRepX c\r\n}}}\r\n\r\nNote `TypeRepX`'s higher-rank kind. The idea is that I want to optionally constrain `TypeRepX`'s payload. Without using a higher-rank kind, the constraint would necessary fix the kind of the payload, and I don't want that. For example, I sometimes use `TypeRepX ConstTrue`, where\r\n\r\n{{{\r\nclass ConstTrue (a :: k)\r\ninstance ConstTrue a\r\n}}}\r\n\r\nThis actually works just fine, and I've been using the above definition to good effect.\r\n\r\nBut then I wanted a `Show` instance:\r\n\r\n{{{\r\ninstance Show (TypeRep a) -- elsewhere\r\n\r\ninstance Show (TypeRepX c) where\r\n show (TypeRepX tr) = show t\r\n}}}\r\n\r\nLooks sensible. But GHC complains. This is because it tries to infer `c`'s kind, by inventing a unification variable and then unifying. But this doesn't work, of course, because `c`'s kind is not a tau-type, so unification fails, lest we let impredicativity sneak in. What's particularly vexing is that, even if I annotate `c` with the correct kind, unification ''still'' fails. This is because that `c` is a ''usage'' of `c`, not a ''binding'' of `c`. Indeed, there is no place in an instance declaration to bind a type variable explicitly, so I have no recourse.\r\n\r\nI'm not sure what the solution is here. Somehow, it feels that inferring a non-tau kind for `c` is perfectly safe, because the kind is known from the use of `TypeRepX`. This would allow me to drop the kind annotation in the definition of `TypeRepX`, which looks redundant to me. But I'm not fully sure about this assumption.\r\n\r\nAt the least, we could introduce a spot for explicit binding of type variables in instance declarations.\r\n\r\nI think, actually, I just figured it out. Use `ExpType`s when kind-checking types. Then I think the normal bidirectional thing (actually already implemented) will do the Right Thing.","type_of_failure":"OtherFailure","blocking":[]} -->8.0.1https://gitlab.haskell.org/ghc/ghc/-/issues/11520GHC falls into a hole if given incorrect kind signature2019-07-07T18:30:05ZBen GamariGHC falls into a hole if given incorrect kind signatureIf one provides an incorrect kind signature GHC throws up. For instance, this non-sense,
```hs
{-# LANGUAGE RankNTypes, PolyKinds, TypeInType, GADTs, UndecidableSuperClasses #-}
module Play where
import GHC.Types hiding (TyCon)
data ...If one provides an incorrect kind signature GHC throws up. For instance, this non-sense,
```hs
{-# LANGUAGE RankNTypes, PolyKinds, TypeInType, GADTs, UndecidableSuperClasses #-}
module Play where
import GHC.Types hiding (TyCon)
data TypeRep (a :: k)
class Typeable k => Typeable (a :: k) where
typeRep :: TypeRep a
data Compose (f :: k1 -> *) (g :: k2 -> k1) (a :: k2) = Compose (f (g a))
-- Note how the kind signature on g is incorrect
instance (Typeable f, Typeable (g :: k), Typeable k) => Typeable (Compose f g) where
typeRep = undefined
```
fails with
```
λ> :load Bug.hs
[1 of 1] Compiling Play ( Bug.hs, interpreted )
ghc: panic! (the 'impossible' happened)
(GHC version 8.1.20160122 for x86_64-unknown-linux):
fvProv falls into a hole {abet}
Please report this as a GHC bug: http://www.haskell.org/ghc/reportabug
```8.0.1https://gitlab.haskell.org/ghc/ghc/-/issues/11548Absolutely misleading error message on kind error2019-07-07T18:29:53ZmniipAbsolutely misleading error message on kind error```hs
module Bug where
import Data.Proxy
fun :: Proxy a -> ()
fun Proxy = ()
bug :: ()
bug = fun (Proxy :: Proxy Maybe)
```
```hs
[1 of 1] Compiling Bug ( Bug.hs, Bug.o )
Bug.hs:9:12: error:
• Expected kind ‘Proxy M...```hs
module Bug where
import Data.Proxy
fun :: Proxy a -> ()
fun Proxy = ()
bug :: ()
bug = fun (Proxy :: Proxy Maybe)
```
```hs
[1 of 1] Compiling Bug ( Bug.hs, Bug.o )
Bug.hs:9:12: error:
• Expected kind ‘Proxy Maybe’,
but ‘Data.Proxy.Proxy :: Proxy Maybe’ has kind ‘Proxy Maybe’
• In the first argument of ‘fun’, namely ‘(Proxy :: Proxy Maybe)’
In the expression: fun (Proxy :: Proxy Maybe)
In an equation for ‘bug’: bug = fun (Proxy :: Proxy Maybe)
```
1. 10 gives the appropriate `Couldn't match kind ‘* -> *’ with ‘*’` message.
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | ------------ |
| Version | 8.1 |
| Type | Bug |
| TypeOfFailure | OtherFailure |
| Priority | high |
| Resolution | Unresolved |
| Component | Compiler |
| Test case | |
| Differential revisions | |
| BlockedBy | |
| Related | |
| Blocking | |
| CC | |
| Operating system | |
| Architecture | |
</details>
<!-- {"blocked_by":[],"summary":"Absolutely misleading error message on kind error","status":"New","operating_system":"","component":"Compiler","related":[],"milestone":"","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"8.1","keywords":[],"differentials":[],"test_case":"","architecture":"","cc":[""],"type":"Bug","description":"{{{#!hs\r\nmodule Bug where\r\n\r\nimport Data.Proxy\r\n\r\nfun :: Proxy a -> ()\r\nfun Proxy = ()\r\n\r\nbug :: ()\r\nbug = fun (Proxy :: Proxy Maybe)\r\n}}}\r\n\r\n{{{#!hs\r\n[1 of 1] Compiling Bug ( Bug.hs, Bug.o )\r\n\r\nBug.hs:9:12: error:\r\n • Expected kind ‘Proxy Maybe’,\r\n but ‘Data.Proxy.Proxy :: Proxy Maybe’ has kind ‘Proxy Maybe’\r\n • In the first argument of ‘fun’, namely ‘(Proxy :: Proxy Maybe)’\r\n In the expression: fun (Proxy :: Proxy Maybe)\r\n In an equation for ‘bug’: bug = fun (Proxy :: Proxy Maybe)\r\n}}}\r\n\r\n7.10 gives the appropriate `Couldn't match kind ‘* -> *’ with ‘*’` message.","type_of_failure":"OtherFailure","blocking":[]} -->8.0.1Richard Eisenbergrae@richarde.devRichard Eisenbergrae@richarde.devhttps://gitlab.haskell.org/ghc/ghc/-/issues/11549Add -fshow-runtime-rep2019-07-07T18:29:53ZRichard Eisenbergrae@richarde.devAdd -fshow-runtime-repAs discussed in several interwoven threads ([original](https://mail.haskell.org/pipermail/ghc-devs/2016-February/011268.html), [café](https://mail.haskell.org/pipermail/haskell-cafe/2016-February/122914.html)), it has been suggested to a...As discussed in several interwoven threads ([original](https://mail.haskell.org/pipermail/ghc-devs/2016-February/011268.html), [café](https://mail.haskell.org/pipermail/haskell-cafe/2016-February/122914.html)), it has been suggested to add a flag `-fshow-runtime-rep`. Without this flag enabled, the pretty printer will instantiate any `RuntimeRep` type parameters to `PtrRep Lifted`. This has the effect of changing
```
($) :: forall (r :: RuntimeRep) (a :: *) (b :: TYPE r). (a -> b) -> a -> b
```
to
```
($) :: (a -> b) -> a -> b
```
under the default GHCi settings.
Note that `Levity` becomes `RuntimeRep` after #11471 is complete.
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | ------------ |
| Version | 8.1 |
| Type | Bug |
| TypeOfFailure | OtherFailure |
| Priority | highest |
| Resolution | Unresolved |
| Component | Compiler |
| Test case | |
| Differential revisions | |
| BlockedBy | |
| Related | |
| Blocking | |
| CC | |
| Operating system | |
| Architecture | |
</details>
<!-- {"blocked_by":[],"summary":"Add -fshow-runtime-rep","status":"New","operating_system":"","component":"Compiler","related":[],"milestone":"8.0.1","resolution":"Unresolved","owner":{"tag":"OwnedBy","contents":"goldfire"},"version":"8.1","keywords":[],"differentials":[],"test_case":"","architecture":"","cc":[""],"type":"Bug","description":"As discussed in several interwoven threads ([https://mail.haskell.org/pipermail/ghc-devs/2016-February/011268.html original], [https://mail.haskell.org/pipermail/haskell-cafe/2016-February/122914.html café]), it has been suggested to add a flag `-fshow-runtime-rep`. Without this flag enabled, the pretty printer will instantiate any `RuntimeRep` type parameters to `PtrRep Lifted`. This has the effect of changing\r\n\r\n{{{\r\n($) :: forall (r :: RuntimeRep) (a :: *) (b :: TYPE r). (a -> b) -> a -> b\r\n}}}\r\n\r\nto\r\n\r\n{{{\r\n($) :: (a -> b) -> a -> b\r\n}}}\r\n\r\nunder the default GHCi settings.\r\n\r\nNote that `Levity` becomes `RuntimeRep` after #11471 is complete.","type_of_failure":"OtherFailure","blocking":[]} -->8.8.1Richard Eisenbergrae@richarde.devRichard Eisenbergrae@richarde.devhttps://gitlab.haskell.org/ghc/ghc/-/issues/11554Self quantification in GADT data declarations2020-09-19T20:01:19ZRafbillSelf quantification in GADT data declarationsGHC hangs on this (it was panicking on the same code before : [https://github.com/goldfirere/ghc/issues/56](https://github.com/goldfirere/ghc/issues/56)(https://github.com/goldfirere/ghc/issues/56) :
```hs
{-# LANGUAGE GADTs, TypeInType...GHC hangs on this (it was panicking on the same code before : [https://github.com/goldfirere/ghc/issues/56](https://github.com/goldfirere/ghc/issues/56)(https://github.com/goldfirere/ghc/issues/56) :
```hs
{-# LANGUAGE GADTs, TypeInType #-}
import Data.Kind
data A :: Type where
B :: forall (a :: A). A
```
I guess the typechecker tries to infer the kind of A from the type of the constructors and hangs. Maybe recursive occurrences of a type as a kind in its constructors should only be allowed when its kind signature is specified and can be used to typecheck the constructors.
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | ------------ |
| Version | 8.0.1-rc2 |
| 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":"Self quantification in GADT data declarations","status":"New","operating_system":"","component":"Compiler","related":[],"milestone":"","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"8.0.1-rc2","keywords":[],"differentials":[],"test_case":"","architecture":"","cc":[""],"type":"Bug","description":"GHC hangs on this (it was panicking on the same code before : [https://github.com/goldfirere/ghc/issues/56](https://github.com/goldfirere/ghc/issues/56) :\r\n{{{#!hs\r\n{-# LANGUAGE GADTs, TypeInType #-}\r\nimport Data.Kind\r\ndata A :: Type where\r\n B :: forall (a :: A). A\r\n}}}\r\n\r\nI guess the typechecker tries to infer the kind of A from the type of the constructors and hangs. Maybe recursive occurrences of a type as a kind in its constructors should only be allowed when its kind signature is specified and can be used to typecheck the constructors.\r\n\r\n","type_of_failure":"OtherFailure","blocking":[]} -->https://gitlab.haskell.org/ghc/ghc/-/issues/11560panic: isInjectiveTyCon sees a TcTyCon2019-07-07T18:29:48Zrwbartonpanic: isInjectiveTyCon sees a TcTyConI typed this into ghci and it panicked. Not sure whether the declaration is really valid anyways, but ghci shouldn't panic on it.
```
rwbarton@morphism:~/ghc-newest$ ./inplace/bin/ghc-stage2 --interactive
GHCi, version 8.1.20160201: htt...I typed this into ghci and it panicked. Not sure whether the declaration is really valid anyways, but ghci shouldn't panic on it.
```
rwbarton@morphism:~/ghc-newest$ ./inplace/bin/ghc-stage2 --interactive
GHCi, version 8.1.20160201: http://www.haskell.org/ghc/ :? for help
Prelude> :set -XTypeFamilies -XTypeInType
Prelude> :m +Data.Kind
Prelude Data.Kind> type family T (l :: *) (k :: l) :: * where { T * Int = * }
ghc-stage2: panic! (the 'impossible' happened)
(GHC version 8.1.20160201 for x86_64-unknown-linux):
isInjectiveTyCon sees a TcTyCon T
Please report this as a GHC bug: http://www.haskell.org/ghc/reportabug
```
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | ----------------------- |
| Version | 8.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":"panic: isInjectiveTyCon sees a TcTyCon","status":"New","operating_system":"","component":"Compiler (Type checker)","related":[],"milestone":"","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"8.1","keywords":[],"differentials":[],"test_case":"","architecture":"","cc":[""],"type":"Bug","description":"I typed this into ghci and it panicked. Not sure whether the declaration is really valid anyways, but ghci shouldn't panic on it.\r\n{{{\r\nrwbarton@morphism:~/ghc-newest$ ./inplace/bin/ghc-stage2 --interactive\r\nGHCi, version 8.1.20160201: http://www.haskell.org/ghc/ :? for help\r\nPrelude> :set -XTypeFamilies -XTypeInType\r\nPrelude> :m +Data.Kind\r\nPrelude Data.Kind> type family T (l :: *) (k :: l) :: * where { T * Int = * }\r\nghc-stage2: panic! (the 'impossible' happened)\r\n (GHC version 8.1.20160201 for x86_64-unknown-linux):\r\n\tisInjectiveTyCon sees a TcTyCon T\r\n\r\nPlease report this as a GHC bug: http://www.haskell.org/ghc/reportabug\r\n}}}","type_of_failure":"OtherFailure","blocking":[]} -->Richard Eisenbergrae@richarde.devRichard Eisenbergrae@richarde.devhttps://gitlab.haskell.org/ghc/ghc/-/issues/11592Self-kinded type variable accepted2019-07-07T18:29:41ZSimon Peyton JonesSelf-kinded type variable acceptedFound when chasing #11407
```
data T (a::a) = Blah -- Accepted
data S (b :: a) a = ...
-- Rejected with: variable ‘a’ used as a kind variable before being bound
-- as a type variable. Perhaps reorder your variables?
...Found when chasing #11407
```
data T (a::a) = Blah -- Accepted
data S (b :: a) a = ...
-- Rejected with: variable ‘a’ used as a kind variable before being bound
-- as a type variable. Perhaps reorder your variables?
```
But `T` should be rejected too, for the same reason as `S`
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | ------------ |
| Version | 7.10.3 |
| 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":"Self-kinded type varialbe accepted","status":"New","operating_system":"","component":"Compiler","related":[],"milestone":"","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"7.10.3","keywords":[],"differentials":[],"test_case":"","architecture":"","cc":[""],"type":"Bug","description":"Found when chasing #11407\r\n{{{\r\ndata T (a::a) = Blah -- Accepted\r\n\r\ndata S (b :: a) a = ...\r\n -- Rejected with: variable ‘a’ used as a kind variable before being bound\r\n -- as a type variable. Perhaps reorder your variables?\r\n}}}\r\nBut `T` should be rejected too, for the same reason as `S`","type_of_failure":"OtherFailure","blocking":[]} -->8.2.1johnleojohnleohttps://gitlab.haskell.org/ghc/ghc/-/issues/11614document TypeInType2019-07-07T18:29:36Zrwbartondocument TypeInType(Just to keep track of the status for 8.0.1.)
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | ------------- |
| Version | 8.0.1-rc2 |
| Type ...(Just to keep track of the status for 8.0.1.)
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | ------------- |
| Version | 8.0.1-rc2 |
| Type | Task |
| TypeOfFailure | OtherFailure |
| Priority | highest |
| Resolution | Unresolved |
| Component | Documentation |
| Test case | |
| Differential revisions | |
| BlockedBy | |
| Related | |
| Blocking | |
| CC | |
| Operating system | |
| Architecture | |
</details>
<!-- {"blocked_by":[],"summary":"document TypeInType","status":"New","operating_system":"","component":"Documentation","related":[],"milestone":"8.0.1","resolution":"Unresolved","owner":{"tag":"OwnedBy","contents":"goldfire"},"version":"8.0.1-rc2","keywords":["TypeInType"],"differentials":[],"test_case":"","architecture":"","cc":[""],"type":"Task","description":"(Just to keep track of the status for 8.0.1.)","type_of_failure":"OtherFailure","blocking":[]} -->8.0.1Richard Eisenbergrae@richarde.devRichard Eisenbergrae@richarde.devhttps://gitlab.haskell.org/ghc/ghc/-/issues/11635Higher-rank kind in datatype definition rejected2019-07-07T18:29:23ZOleg GrenrusHigher-rank kind in datatype definition rejectedExample program:
```hs
{-# LANGUAGE TypeInType, KindSignatures, ExplicitForAll #-}
import Data.Kind
data X (a :: forall k. k -> * ) = X
```
errors with
```
polykind.hs:3:1: error:
Expecting one more argument to ‘a’
Expected ki...Example program:
```hs
{-# LANGUAGE TypeInType, KindSignatures, ExplicitForAll #-}
import Data.Kind
data X (a :: forall k. k -> * ) = X
```
errors with
```
polykind.hs:3:1: error:
Expecting one more argument to ‘a’
Expected kind ‘k0’, but ‘a’ has kind ‘forall k. k -> *’
```
Without `TypeInType`, the error is better, yet gives false hint:
```
polykind.hs:3:23: error:
Illegal kind: forall k. k -> *
Did you mean to enable TypeInType?
```
---
For the record 7.10.3 doesn't recognise polymorphic kinds at all (same program, without `Data.Kind` import):
```
polykind.hs:3:23: parse error on input ‘forall’
```
Which makes me think that polymorphic kinds are somehow supported, but maybe not.8.0.1Richard Eisenbergrae@richarde.devRichard Eisenbergrae@richarde.devhttps://gitlab.haskell.org/ghc/ghc/-/issues/11642Heterogeneous type equality evidence ignored2019-07-07T18:29:20ZBen GamariHeterogeneous type equality evidence ignoredEither that or I am missing something...
Consider the following,
```hs
{-# LANGUAGE GADTs, PolyKinds, PatternSynonyms, RankNTypes,
TypeOperators, ViewPatterns #-}
module Test where
data TypeRep (a :: k) where
TypeCon :...Either that or I am missing something...
Consider the following,
```hs
{-# LANGUAGE GADTs, PolyKinds, PatternSynonyms, RankNTypes,
TypeOperators, ViewPatterns #-}
module Test where
data TypeRep (a :: k) where
TypeCon :: String -> TypeRep a
TypeApp :: TypeRep f -> TypeRep x -> TypeRep (f x)
data TypeRepX where
TypeRepX :: TypeRep a -> TypeRepX
data (a :: k1) :~~: (b :: k2) where
HRefl :: a :~~: a
trArrow :: TypeRep (->)
trArrow = undefined
eqTypeRep :: TypeRep (a :: k1) -> TypeRep (b :: k2) -> Maybe (a :~~: b)
eqTypeRep = undefined
typeRepKind :: forall (k :: *). forall (a :: k). TypeRep a -> TypeRep k
typeRepKind = undefined
pattern TRFun :: forall fun. ()
=> forall arg res. (fun ~ (arg -> res))
=> TypeRep arg
-> TypeRep res
-> TypeRep fun
pattern TRFun arg res <- TypeApp (TypeApp (eqTypeRep trArrow -> Just HRefl) arg) res
buildApp :: TypeRepX -> TypeRepX -> TypeRepX
buildApp (TypeRepX f) (TypeRepX x) =
case typeRepKind f of
TRFun arg _ ->
case eqTypeRep arg x of
Just HRefl ->
TypeRepX $ TypeApp f x
```
This fails with,
```
$ ghc Test.hs -fprint-explicit-kinds
[1 of 1] Compiling Test ( Test.hs, Test.o )
Test.hs:38:30: error:
• Expected kind ‘TypeRep (k1 -> res) a’,
but ‘f’ has kind ‘TypeRep k a’
• In the first argument of ‘TypeApp’, namely ‘f’
In the second argument of ‘($)’, namely ‘TypeApp f x’
In the expression: TypeRepX $ TypeApp f x
• Relevant bindings include
arg :: TypeRep * arg (bound at Test.hs:35:11)
```
That is, the typechecker doesn't believe that `f`'s type (why is it saying "kind" here?), `TypeRep k a`, will unify with `TypeRep (k1 -> res) a`, despite the `TRFun` pattern match, which should have brought into scope that `k ~ (arg -> res)`.
This was tested with a recent snapshot from `ghc-8.0` (23baff798aca5856650508ad0f7727045efe3680).
Am I missing something here or is this a bug?
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | ----------------------- |
| Version | 7.10.3 |
| 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":"Typechecker doesn't use evidence available from pattern synonym?","status":"New","operating_system":"","component":"Compiler (Type checker)","related":[],"milestone":"8.0.1","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"7.10.3","keywords":[],"differentials":[],"test_case":"","architecture":"","cc":[""],"type":"Bug","description":"Either that or I am missing something...\r\n\r\nConsider the following,\r\n{{{#!hs\r\n{-# LANGUAGE GADTs, PolyKinds, PatternSynonyms, RankNTypes,\r\n TypeOperators, ViewPatterns #-}\r\n\r\nmodule Test where\r\n\r\ndata TypeRep (a :: k) where\r\n TypeCon :: String -> TypeRep a\r\n TypeApp :: TypeRep f -> TypeRep x -> TypeRep (f x)\r\n\r\ndata TypeRepX where\r\n TypeRepX :: TypeRep a -> TypeRepX\r\n\r\ndata (a :: k1) :~~: (b :: k2) where\r\n HRefl :: a :~~: a\r\n\r\ntrArrow :: TypeRep (->)\r\ntrArrow = undefined\r\n\r\neqTypeRep :: TypeRep (a :: k1) -> TypeRep (b :: k2) -> Maybe (a :~~: b)\r\neqTypeRep = undefined\r\n\r\ntypeRepKind :: forall (k :: *). forall (a :: k). TypeRep a -> TypeRep k\r\ntypeRepKind = undefined\r\n\r\npattern TRFun :: forall fun. ()\r\n => forall arg res. (fun ~ (arg -> res))\r\n => TypeRep arg\r\n -> TypeRep res\r\n -> TypeRep fun\r\npattern TRFun arg res <- TypeApp (TypeApp (eqTypeRep trArrow -> Just HRefl) arg) res\r\n\r\nbuildApp :: TypeRepX -> TypeRepX -> TypeRepX\r\nbuildApp (TypeRepX f) (TypeRepX x) =\r\n case typeRepKind f of\r\n TRFun arg _ ->\r\n case eqTypeRep arg x of\r\n Just HRefl ->\r\n TypeRepX $ TypeApp f x\r\n}}}\r\n\r\nThis fails with,\r\n{{{\r\n$ ghc Test.hs -fprint-explicit-kinds\r\n[1 of 1] Compiling Test ( Test.hs, Test.o )\r\n\r\nTest.hs:38:30: error:\r\n • Expected kind ‘TypeRep (k1 -> res) a’,\r\n but ‘f’ has kind ‘TypeRep k a’\r\n • In the first argument of ‘TypeApp’, namely ‘f’\r\n In the second argument of ‘($)’, namely ‘TypeApp f x’\r\n In the expression: TypeRepX $ TypeApp f x\r\n • Relevant bindings include\r\n arg :: TypeRep * arg (bound at Test.hs:35:11)\r\n}}}\r\n\r\nThat is, the typechecker doesn't believe that `f`'s type (why is it saying \"kind\" here?), `TypeRep k a`, will unify with `TypeRep (k1 -> res) a`, despite the `TRFun` pattern match, which should have brought into scope that `k ~ (arg -> res)`.\r\n\r\nThis was tested with a recent snapshot from `ghc-8.0` (23baff798aca5856650508ad0f7727045efe3680).\r\n\r\nAm I missing something here or is this a bug?","type_of_failure":"OtherFailure","blocking":[]} -->8.0.1Richard Eisenbergrae@richarde.devRichard Eisenbergrae@richarde.devhttps://gitlab.haskell.org/ghc/ghc/-/issues/11648assertPprPanic, called at compiler/types/TyCoRep.hs:19322019-07-07T18:29:18ZThomas MiedemaassertPprPanic, called at compiler/types/TyCoRep.hs:1932As mentioned in https://mail.haskell.org/pipermail/ghc-devs/2016-February/011455.html, the following tests currently hit an assert when the compiler is built with -DDEBUG:
```
patsyn/should_compile MoreEx [exit code non-0] (normal)
...As mentioned in https://mail.haskell.org/pipermail/ghc-devs/2016-February/011455.html, the following tests currently hit an assert when the compiler is built with -DDEBUG:
```
patsyn/should_compile MoreEx [exit code non-0] (normal)
patsyn/should_compile T11224b [exit code non-0] (normal)
polykinds MonoidsTF [exit code non-0] (normal)
polykinds T11480b [exit code non-0] (normal)
polykinds T11523 [exit code non-0] (normal)
```
```
Compile failed (status 256) errors were:
ghc-stage2: panic! (the 'impossible' happened)
(GHC version 8.1.20160218 for x86_64-unknown-linux):
ASSERT failed!
CallStack (from HasCallStack):
assertPprPanic, called at compiler/types/TyCoRep.hs:1932:56 in ghc:TyCoRep
checkValidSubst, called at compiler/types/TyCoRep.hs:1991:17 in
ghc:TyCoRep
substTys, called at compiler/types/TyCoRep.hs:2012:14 in ghc:TyCoRep
substTheta, called at compiler/typecheck/TcPatSyn.hs:255:20 in
ghc:TcPatSyn
in_scope InScope {d_ap0 c_apv}
tenv [ap1 :-> c_apv[tau:5]]
tenvFVs [aps :-> t_aps[tau:1], apv :-> c_apv[tau:5]]
cenv []
cenvFVs []
tys []
cos []
```
[D1951](https://phabricator.haskell.org/D1951) contained a stopgap patch, but since it wasn't accepted, I'll just mark the tests as expect_broken for this ticket, so that other developers aren't bothered by this issue.
The offending commit is b5292557dcf2e3844b4837172230575d40a8917e.
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | ------------ |
| Version | 8.1 |
| 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":"assertPprPanic, called at compiler/types/TyCoRep.hs:1932","status":"New","operating_system":"","component":"Compiler","related":[],"milestone":"","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"8.1","keywords":[],"differentials":[],"test_case":"","architecture":"","cc":[""],"type":"Bug","description":"As mentioned in https://mail.haskell.org/pipermail/ghc-devs/2016-February/011455.html, the following tests currently hit an assert when the compiler is built with -DDEBUG:\r\n\r\n{{{\r\n patsyn/should_compile MoreEx [exit code non-0] (normal)\r\n patsyn/should_compile T11224b [exit code non-0] (normal)\r\n polykinds MonoidsTF [exit code non-0] (normal)\r\n polykinds T11480b [exit code non-0] (normal)\r\n polykinds T11523 [exit code non-0] (normal)\r\n}}}\r\n\r\n{{{\r\nCompile failed (status 256) errors were:\r\nghc-stage2: panic! (the 'impossible' happened)\r\n (GHC version 8.1.20160218 for x86_64-unknown-linux):\r\nASSERT failed!\r\n CallStack (from HasCallStack):\r\n assertPprPanic, called at compiler/types/TyCoRep.hs:1932:56 in ghc:TyCoRep\r\n checkValidSubst, called at compiler/types/TyCoRep.hs:1991:17 in\r\nghc:TyCoRep\r\n substTys, called at compiler/types/TyCoRep.hs:2012:14 in ghc:TyCoRep\r\n substTheta, called at compiler/typecheck/TcPatSyn.hs:255:20 in\r\nghc:TcPatSyn\r\n in_scope InScope {d_ap0 c_apv}\r\n tenv [ap1 :-> c_apv[tau:5]]\r\n tenvFVs [aps :-> t_aps[tau:1], apv :-> c_apv[tau:5]]\r\n cenv []\r\n cenvFVs []\r\n tys []\r\n cos []\r\n}}}\r\n\r\nPhab:D1951 contained a stopgap patch, but since it wasn't accepted, I'll just mark the tests as expect_broken for this ticket, so that other developers aren't bothered by this issue.\r\n\r\nThe offending commit is b5292557dcf2e3844b4837172230575d40a8917e.","type_of_failure":"OtherFailure","blocking":[]} -->8.0.1Richard Eisenbergrae@richarde.devRichard Eisenbergrae@richarde.devhttps://gitlab.haskell.org/ghc/ghc/-/issues/11672Poor error message2019-07-07T18:29:09ZAdam GundryPoor error message[Daniel Díaz recently pointed out](https://mail.haskell.org/pipermail/haskell-cafe/2016-February/123262.html) a particularly terrible error message. Here's a reduced example:
```hs
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE KindSignatures ...[Daniel Díaz recently pointed out](https://mail.haskell.org/pipermail/haskell-cafe/2016-February/123262.html) a particularly terrible error message. Here's a reduced example:
```hs
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE KindSignatures #-}
module BadError where
import GHC.TypeLits
import Data.Proxy
f :: Proxy (a :: Symbol) -> Int
f _ = f (Proxy :: Proxy (Int -> Bool))
```
With GHC 8.0 RC2, this leads to the following error:
```
• Expected kind ‘Proxy ((->) Int Bool)’,
but ‘Data.Proxy.Proxy :: Proxy (Int -> Bool)’ has kind ‘Proxy
(Int -> Bool)’
• In the first argument of ‘f’, namely
‘(Proxy :: Proxy (Int -> Bool))’
In the expression: f (Proxy :: Proxy (Int -> Bool))
In an equation for ‘f’: f _ = f (Proxy :: Proxy (Int -> Bool))
```
or with `-fprint-explicit-kinds -fprint-explicit-coercions`:
```
• Expected kind ‘Proxy
Symbol
(((->) |> <*>_N -> <*>_N -> U(hole:{aCy}, *, Symbol)_N) Int Bool)’,
but ‘(Data.Proxy.Proxy) @ k_aCv @ t_aCw ::
Proxy (Int -> Bool)’ has kind ‘Proxy * (Int -> Bool)’
```
As Iavor, Richard and I discussed, this message has at least three separate problems:
- It says `kind` when it should say `type`.
- `((->) Int Bool)` is printed instead of `Int -> Bool` (because there is a coercion hiding in the type).
- The real error is the insoluble constraint `Symbol ~ *`, which is not reported at all!
The first two should be fairly easy to fix. For the third, when reporting insoluble constraints, we should prefer to report those on which no other constraints depend. (In this case, the presence of `hole:{aCy}` in the constraint is an explicit dependency on the other constraint.)
I'll try to take a look at this. It is no doubt related to #11198.
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | ----------------------- |
| Version | 8.0.1-rc2 |
| Type | Bug |
| TypeOfFailure | OtherFailure |
| Priority | normal |
| Resolution | Unresolved |
| Component | Compiler (Type checker) |
| Test case | |
| Differential revisions | |
| BlockedBy | |
| Related | |
| Blocking | |
| CC | diatchki, goldfire |
| Operating system | |
| Architecture | |
</details>
<!-- {"blocked_by":[],"summary":"Poor error message","status":"New","operating_system":"","component":"Compiler (Type checker)","related":[],"milestone":"","resolution":"Unresolved","owner":{"tag":"OwnedBy","contents":"adamgundry"},"version":"8.0.1-rc2","keywords":["ErrorMessages"],"differentials":[],"test_case":"","architecture":"","cc":["diatchki","goldfire"],"type":"Bug","description":"[https://mail.haskell.org/pipermail/haskell-cafe/2016-February/123262.html Daniel Díaz recently pointed out] a particularly terrible error message. Here's a reduced example:\r\n{{{#!hs\r\n{-# LANGUAGE DataKinds #-}\r\n{-# LANGUAGE KindSignatures #-}\r\nmodule BadError where\r\n\r\nimport GHC.TypeLits\r\nimport Data.Proxy\r\n\r\nf :: Proxy (a :: Symbol) -> Int\r\nf _ = f (Proxy :: Proxy (Int -> Bool))\r\n}}}\r\n\r\nWith GHC 8.0 RC2, this leads to the following error:\r\n{{{\r\n • Expected kind ‘Proxy ((->) Int Bool)’,\r\n but ‘Data.Proxy.Proxy :: Proxy (Int -> Bool)’ has kind ‘Proxy\r\n (Int -> Bool)’\r\n • In the first argument of ‘f’, namely\r\n ‘(Proxy :: Proxy (Int -> Bool))’\r\n In the expression: f (Proxy :: Proxy (Int -> Bool))\r\n In an equation for ‘f’: f _ = f (Proxy :: Proxy (Int -> Bool))\r\n}}}\r\nor with `-fprint-explicit-kinds -fprint-explicit-coercions`:\r\n{{{\r\n • Expected kind ‘Proxy\r\n Symbol\r\n (((->) |> <*>_N -> <*>_N -> U(hole:{aCy}, *, Symbol)_N) Int Bool)’,\r\n but ‘(Data.Proxy.Proxy) @ k_aCv @ t_aCw ::\r\n Proxy (Int -> Bool)’ has kind ‘Proxy * (Int -> Bool)’\r\n}}}\r\n\r\nAs Iavor, Richard and I discussed, this message has at least three separate problems:\r\n\r\n * It says `kind` when it should say `type`.\r\n\r\n * `((->) Int Bool)` is printed instead of `Int -> Bool` (because there is a coercion hiding in the type).\r\n\r\n * The real error is the insoluble constraint `Symbol ~ *`, which is not reported at all!\r\n\r\nThe first two should be fairly easy to fix. For the third, when reporting insoluble constraints, we should prefer to report those on which no other constraints depend. (In this case, the presence of `hole:{aCy}` in the constraint is an explicit dependency on the other constraint.)\r\n\r\nI'll try to take a look at this. It is no doubt related to #11198.","type_of_failure":"OtherFailure","blocking":[]} -->Adam GundryAdam Gundryhttps://gitlab.haskell.org/ghc/ghc/-/issues/11699Type families mistakingly report kind variables as unbound type variables2019-07-07T18:29:02ZmniipType families mistakingly report kind variables as unbound type variablesGHC verifies that if some equation of a type family binds a type variable, that this type variable actually exists and doesn't disappear through type synonym/family application (#7536). However this also mistakingly catches kind variable...GHC verifies that if some equation of a type family binds a type variable, that this type variable actually exists and doesn't disappear through type synonym/family application (#7536). However this also mistakingly catches kind variables that aren't present in the type family head.
Simplest test case:
```hs
{-# LANGUAGE TypeFamilies, PolyKinds #-}
type family F a where F (f a) = f a
```
As seen on 8.0.1-rc2 and 7.10.2:
```
../File.hs:3:23:
Family instance purports to bind type variable ‘k1’
but the real LHS (expanding synonyms) is: F (f a) = ...
In the equations for closed type family ‘F’
In the type family declaration for ‘F’
```
The culprit seems to be in `exactTyCoVarsOfType`, which doesn't grab kind variables from a type variable's kind, even though `tyCoVarsOfType` does.
Now, I'm not too sure whether this is a "GHC rejects valid program", or "Incorrect warning at compile time", as I'm not sure if type families like the aforementioned `F` are actually okay. (Are they?)
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | ------------ |
| Version | 8.0.1-rc2 |
| 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":"Type families mistakingly report kind variables as unbound type variables","status":"New","operating_system":"","component":"Compiler","related":[],"milestone":"","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"8.0.1-rc2","keywords":[],"differentials":[],"test_case":"","architecture":"","cc":[""],"type":"Bug","description":"GHC verifies that if some equation of a type family binds a type variable, that this type variable actually exists and doesn't disappear through type synonym/family application (#7536). However this also mistakingly catches kind variables that aren't present in the type family head.\r\n\r\nSimplest test case:\r\n{{{#!hs\r\n{-# LANGUAGE TypeFamilies, PolyKinds #-}\r\ntype family F a where F (f a) = f a\r\n}}}\r\nAs seen on 8.0.1-rc2 and 7.10.2:\r\n{{{\r\n../File.hs:3:23:\r\n Family instance purports to bind type variable ‘k1’\r\n but the real LHS (expanding synonyms) is: F (f a) = ...\r\n In the equations for closed type family ‘F’\r\n In the type family declaration for ‘F’\r\n}}}\r\n\r\nThe culprit seems to be in `exactTyCoVarsOfType`, which doesn't grab kind variables from a type variable's kind, even though `tyCoVarsOfType` does.\r\n\r\nNow, I'm not too sure whether this is a \"GHC rejects valid program\", or \"Incorrect warning at compile time\", as I'm not sure if type families like the aforementioned `F` are actually okay. (Are they?)","type_of_failure":"OtherFailure","blocking":[]} -->8.0.1Richard Eisenbergrae@richarde.devRichard Eisenbergrae@richarde.devhttps://gitlab.haskell.org/ghc/ghc/-/issues/11716Make TypeInType stress test work2019-07-07T18:28:57ZRichard Eisenbergrae@richarde.devMake TypeInType stress test workI used the attached file during my job talk. It is good `TypeInType` stress test. This bug is to track several fixes that have been necessary to get it working. I have these fixes locally and will push in due course.
<details><summary>T...I used the attached file during my job talk. It is good `TypeInType` stress test. This bug is to track several fixes that have been necessary to get it working. I have these fixes locally and will push in due course.
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | ------------ |
| Version | 8.1 |
| 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":"Make TypeInType stress test work","status":"New","operating_system":"","component":"Compiler","related":[],"milestone":"8.0.1","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"8.1","keywords":["TypeInType"],"differentials":[],"test_case":"","architecture":"","cc":[""],"type":"Bug","description":"I used the attached file during my job talk. It is good `TypeInType` stress test. This bug is to track several fixes that have been necessary to get it working. I have these fixes locally and will push in due course.","type_of_failure":"OtherFailure","blocking":[]} -->8.0.1https://gitlab.haskell.org/ghc/ghc/-/issues/11719Cannot use higher-rank kinds with type families2019-07-07T18:28:55ZOllie CharlesCannot use higher-rank kinds with type familiesThis ticket came out of a discussion with Richard in this mailing list post: https://mail.haskell.org/pipermail/haskell-cafe/2016-March/123462.html
Here's the code that should work, but doesn't:
```hs
import Data.Kind
data TyFun :: * ...This ticket came out of a discussion with Richard in this mailing list post: https://mail.haskell.org/pipermail/haskell-cafe/2016-March/123462.html
Here's the code that should work, but doesn't:
```hs
import Data.Kind
data TyFun :: * -> * -> *
type a ~> b = TyFun a b -> *
type family (f :: a ~> b) @@ (x :: a) :: b
data Null a = Nullable a | NotNullable a
type family ((f :: b ~> c) ∘ (g :: a ~> b)) (x :: a) :: c where
(f ∘ g) x = f @@ (g @@ x)
type family BaseType (k :: forall a. a ~> Type) (x :: b) :: Type where -- this fails :(
-- BaseType k x = (@@) k x
```8.8.1https://gitlab.haskell.org/ghc/ghc/-/issues/11732Deriving Generic1 interacts poorly with TypeInType2019-07-07T18:28:52ZRichard Eisenbergrae@richarde.devDeriving Generic1 interacts poorly with TypeInTypeFrom \@RyanGlScott, [ticket:11357\#comment:117922](https://gitlab.haskell.org//ghc/ghc/issues/11357#note_117922):
Vanilla datatypes and data family instances are still inconsistent w.r.t. which type variables are considered "instantiate...From \@RyanGlScott, [ticket:11357\#comment:117922](https://gitlab.haskell.org//ghc/ghc/issues/11357#note_117922):
Vanilla datatypes and data family instances are still inconsistent w.r.t. which type variables are considered "instantiated" in a `Generic1` instance. For instance, this is rejected:
```
λ> data Proxy k (a :: k) = ProxyCon deriving Generic1
```
```
<interactive>:32:43: error:
• Can't make a derived instance of ‘Generic1 (Proxy *)’:
Proxy must not be instantiated; try deriving `Proxy k a' instead
• In the data declaration for ‘Proxy’
```
And rightfully so, since the visible kind binder `k` is instantiated to `*`. But now it's possible to have an equivalent instance for a data family that squeaks past this check!
```
λ> data family ProxyFam (a :: y) (b :: z)
λ> data instance ProxyFam k (a :: k) = ProxyFamCon deriving Generic1
==================== Derived instances ====================
Derived instances:
instance GHC.Generics.Generic1 (Ghci13.ProxyFam *) where
...
```
\[Ryan needs\] to investigate further to see why this is the case.
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | ------------ |
| Version | 8.1 |
| 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":"Deriving Generic1 interacts poorly with TypeInType","status":"New","operating_system":"","component":"Compiler","related":[],"milestone":"","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"8.1","keywords":["Generics","TypeInType,"],"differentials":[],"test_case":"","architecture":"","cc":[""],"type":"Bug","description":"From @RyanGlScott, comment:9:ticket:11357:\r\n\r\nVanilla datatypes and data family instances are still inconsistent w.r.t. which type variables are considered \"instantiated\" in a `Generic1` instance. For instance, this is rejected:\r\n\r\n{{{\r\nλ> data Proxy k (a :: k) = ProxyCon deriving Generic1\r\n}}}\r\n\r\n{{{\r\n<interactive>:32:43: error:\r\n • Can't make a derived instance of ‘Generic1 (Proxy *)’:\r\n Proxy must not be instantiated; try deriving `Proxy k a' instead\r\n • In the data declaration for ‘Proxy’\r\n}}}\r\n\r\nAnd rightfully so, since the visible kind binder `k` is instantiated to `*`. But now it's possible to have an equivalent instance for a data family that squeaks past this check!\r\n\r\n{{{\r\nλ> data family ProxyFam (a :: y) (b :: z)\r\nλ> data instance ProxyFam k (a :: k) = ProxyFamCon deriving Generic1\r\n\r\n==================== Derived instances ====================\r\nDerived instances:\r\n instance GHC.Generics.Generic1 (Ghci13.ProxyFam *) where\r\n ...\r\n}}}\r\n\r\n[Ryan needs] to investigate further to see why this is the case. ","type_of_failure":"OtherFailure","blocking":[]} -->8.0.1https://gitlab.haskell.org/ghc/ghc/-/issues/11754Error in optCoercion2019-07-07T18:28:42ZSimon Peyton JonesError in optCoercionThis program fails Lint after a run of the simplifier.
```hs
{-# LANGUAGE TypeOperators, UndecidableSuperClasses, KindSignatures, TypeFamilies, FlexibleContexts #-}
module T11728a where
import Data.Kind
import Data.Void
newtype K a x...This program fails Lint after a run of the simplifier.
```hs
{-# LANGUAGE TypeOperators, UndecidableSuperClasses, KindSignatures, TypeFamilies, FlexibleContexts #-}
module T11728a where
import Data.Kind
import Data.Void
newtype K a x = K a
newtype I x = I x
data (f + g) x = L (f x) | R (g x)
data (f × g) x = f x :×: g x
class Differentiable (D f) => Differentiable f where
type D (f :: Type -> Type) :: Type -> Type
instance Differentiable (K a) where
type D (K a) = K Void
instance Differentiable I where
type D I = K ()
instance (Differentiable f₁, Differentiable f₂) => Differentiable (f₁ + f₂) where
type D (f₁ + f₂) = D f₁ + D f₂
instance (Differentiable f₁, Differentiable f₂) => Differentiable (f₁ × f₂) where
type D (f₁ × f₂) = (D f₁ × f₂) + (f₁ × D f₂)
```
Originally reported in #11728, but it's a totally different problem.
Richard has nailed it already... patch coming from him.8.0.1Richard Eisenbergrae@richarde.devRichard Eisenbergrae@richarde.devhttps://gitlab.haskell.org/ghc/ghc/-/issues/11785Merge types and kinds in Template Haskell2019-07-07T18:28:33ZRichard Eisenbergrae@richarde.devMerge types and kinds in Template Haskell!TcSplice handles kinds differently than types. Now that they are the same, it's probably best to rewrite this code.
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | ---...!TcSplice handles kinds differently than types. Now that they are the same, it's probably best to rewrite this code.
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | ---------------- |
| Version | 8.1 |
| Type | Task |
| TypeOfFailure | OtherFailure |
| Priority | normal |
| Resolution | Unresolved |
| Component | Template Haskell |
| Test case | |
| Differential revisions | |
| BlockedBy | |
| Related | |
| Blocking | |
| CC | |
| Operating system | |
| Architecture | |
</details>
<!-- {"blocked_by":[],"summary":"Kinds should be treated like types in TcSplice","status":"New","operating_system":"","component":"Template Haskell","related":[],"milestone":"","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"8.1","keywords":[],"differentials":[],"test_case":"","architecture":"","cc":[""],"type":"Task","description":"!TcSplice handles kinds differently than types. Now that they are the same, it's probably best to rewrite this code.","type_of_failure":"OtherFailure","blocking":[]} -->8.4.1https://gitlab.haskell.org/ghc/ghc/-/issues/11811GHC sometimes misses a CUSK2019-07-07T18:28:26ZRichard Eisenbergrae@richarde.devGHC sometimes misses a CUSK```
{-# LANGUAGE TypeInType #-}
data Test (a :: x) (b :: x) :: x -> *
where K :: Test Int Bool Double
```
fails, because GHC thinks that `Test` does not have a CUSK.
It should have a CUSK, because while there is no `forall x` in the...```
{-# LANGUAGE TypeInType #-}
data Test (a :: x) (b :: x) :: x -> *
where K :: Test Int Bool Double
```
fails, because GHC thinks that `Test` does not have a CUSK.
It should have a CUSK, because while there is no `forall x` in the result kind, the `x` is in scope from previous use in kinds.
Fix en route.
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | ------------ |
| Version | 8.1 |
| 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":"GHC sometimes misses a CUSK","status":"New","operating_system":"","component":"Compiler","related":[],"milestone":"","resolution":"Unresolved","owner":{"tag":"OwnedBy","contents":"goldfire"},"version":"8.1","keywords":[],"differentials":[],"test_case":"","architecture":"","cc":[""],"type":"Bug","description":"{{{\r\n{-# LANGUAGE TypeInType #-}\r\n\r\ndata Test (a :: x) (b :: x) :: x -> *\r\n where K :: Test Int Bool Double\r\n}}}\r\n\r\nfails, because GHC thinks that `Test` does not have a CUSK.\r\n\r\nIt should have a CUSK, because while there is no `forall x` in the result kind, the `x` is in scope from previous use in kinds.\r\n\r\nFix en route.","type_of_failure":"OtherFailure","blocking":[]} -->8.0.1Richard Eisenbergrae@richarde.devRichard Eisenbergrae@richarde.devhttps://gitlab.haskell.org/ghc/ghc/-/issues/11821Internal error: not in scope during type checking, but it passed the renamer2019-07-07T18:28:23ZdarchonInternal error: not in scope during type checking, but it passed the renamerWhile trying to get the singletons package to compile on GHC8 (https://github.com/goldfirere/singletons/pull/142), I encountered the following error while trying to track down a bug:
```
[1 of 1] Compiling NotInScope ( NotInScope....While trying to get the singletons package to compile on GHC8 (https://github.com/goldfirere/singletons/pull/142), I encountered the following error while trying to track down a bug:
```
[1 of 1] Compiling NotInScope ( NotInScope.hs, interpreted )
NotInScope.hs:22:20: error:
• GHC internal error: ‘b’ is not in scope during type checking, but it passed the renamer
tcl_env of environment: [a1lm :-> Type variable ‘b’ = b,
a1lA :-> Type variable ‘l1’ = l1, a1lB :-> Type variable ‘l2’ = l2,
a1lC :-> Type variable ‘l3’ = l3, a1lE :-> Type variable ‘a’ = a,
a1lF :-> Type variable ‘l4’ = l4, r1aq :-> ATcTyCon Lgo,
r1aG :-> ATcTyCon Lgo1, r1aI :-> ATcTyCon Lgo2]
• In the kind ‘b’
In the definition of data constructor ‘Lgo1KindInference’
In the data declaration for ‘Lgo1’
```
for the following code:
```
{-# LANGUAGE RankNTypes, DataKinds, PolyKinds, GADTs, TypeFamilies, UndecidableInstances #-}
module NotInScope where
import Data.Proxy
type KindOf (a :: k) = ('KProxy :: KProxy k)
data TyFun :: * -> * -> *
type family Apply (f :: TyFun k1 k2 -> *) (x :: k1) :: k2
data Lgo2 l1
l2
l3
(l4 :: b)
(l5 :: TyFun [a] b)
= forall (arg :: [a]) . KindOf (Apply (Lgo2 l1 l2 l3 l4) arg) ~ KindOf (Lgo l1 l2 l3 l4 arg) =>
Lgo2KindInference
data Lgo1 l1
l2
l3
(l4 :: TyFun b (TyFun [a] b -> *))
= forall (arg :: b) . KindOf (Apply (Lgo1 l1 l2 l3) arg) ~ KindOf (Lgo2 l1 l2 l3 arg) =>
Lgo1KindInference
type family Lgo f
z0
xs0
(a1 :: b)
(a2 :: [a]) :: b where
Lgo f z0 xs0 z '[] = z
Lgo f z0 xs0 z ('(:) x xs) = Apply (Apply (Lgo1 f z0 xs0) (Apply (Apply f z) x)) xs
```
Note that the above code works fine in GHC 7.10.2.
There are two options to make the code compile on GHC8-rc3:
- Remove the kind annotations on the `forall arg .` binders
- Or make the following changes using TypeInType:
```
{-# LANGUAGE RankNTypes, DataKinds, PolyKinds, GADTs, TypeFamilies, UndecidableInstances, TypeInType #-}
module NotInScope where
import Data.Proxy
import GHC.Types
type KindOf (a :: k) = ('KProxy :: KProxy k)
data TyFun :: * -> * -> *
type family Apply (f :: TyFun k1 k2 -> *) (x :: k1) :: k2
data Lgo2 a
b
l1
l2
l3
(l4 :: b)
(l5 :: TyFun [a] b)
= forall (arg :: [a]) . KindOf (Apply (Lgo2 a b l1 l2 l3 l4) arg) ~ KindOf (Lgo a b l1 l2 l3 l4 arg) =>
Lgo2KindInference
data Lgo1 a
b
l1
l2
l3
(l4 :: TyFun b (TyFun [a] b -> *))
= forall (arg :: b) . KindOf (Apply (Lgo1 a b l1 l2 l3) arg) ~ KindOf (Lgo2 a b l1 l2 l3 arg) =>
Lgo1KindInference
type family Lgo a
b
f
z0
xs0
(a1 :: b)
(a2 :: [a]) :: b where
Lgo a b f z0 xs0 z '[] = z
Lgo a b f z0 xs0 z ('(:) x xs) = Apply (Apply (Lgo1 a b f z0 xs0) (Apply (Apply f z) x)) xs
```
I'm sorry I didn't create a smaller test case. Let me know if one is required and I'll try.
The error seems to be related to the recursive aspect of the three definitions and how implicit kind variables are handled in ghc8.
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | ------------ |
| Version | 8.0.1-rc3 |
| 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":"Internal error: not in scope during type checking, but it passed the renamer","status":"New","operating_system":"","component":"Compiler","related":[],"milestone":"8.0.1","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"8.0.1-rc3","keywords":[],"differentials":[],"test_case":"","architecture":"","cc":[""],"type":"Bug","description":"While trying to get the singletons package to compile on GHC8 (https://github.com/goldfirere/singletons/pull/142), I encountered the following error while trying to track down a bug:\r\n\r\n{{{\r\n[1 of 1] Compiling NotInScope ( NotInScope.hs, interpreted )\r\n\r\nNotInScope.hs:22:20: error:\r\n • GHC internal error: ‘b’ is not in scope during type checking, but it passed the renamer\r\n tcl_env of environment: [a1lm :-> Type variable ‘b’ = b,\r\n a1lA :-> Type variable ‘l1’ = l1, a1lB :-> Type variable ‘l2’ = l2,\r\n a1lC :-> Type variable ‘l3’ = l3, a1lE :-> Type variable ‘a’ = a,\r\n a1lF :-> Type variable ‘l4’ = l4, r1aq :-> ATcTyCon Lgo,\r\n r1aG :-> ATcTyCon Lgo1, r1aI :-> ATcTyCon Lgo2]\r\n • In the kind ‘b’\r\n In the definition of data constructor ‘Lgo1KindInference’\r\n In the data declaration for ‘Lgo1’\r\n}}}\r\n\r\nfor the following code:\r\n\r\n{{{\r\n{-# LANGUAGE RankNTypes, DataKinds, PolyKinds, GADTs, TypeFamilies, UndecidableInstances #-}\r\nmodule NotInScope where\r\n\r\nimport Data.Proxy\r\n\r\ntype KindOf (a :: k) = ('KProxy :: KProxy k)\r\ndata TyFun :: * -> * -> *\r\ntype family Apply (f :: TyFun k1 k2 -> *) (x :: k1) :: k2\r\n\r\ndata Lgo2 l1\r\n l2\r\n l3\r\n (l4 :: b)\r\n (l5 :: TyFun [a] b)\r\n = forall (arg :: [a]) . KindOf (Apply (Lgo2 l1 l2 l3 l4) arg) ~ KindOf (Lgo l1 l2 l3 l4 arg) =>\r\n Lgo2KindInference\r\n\r\ndata Lgo1 l1\r\n l2\r\n l3\r\n (l4 :: TyFun b (TyFun [a] b -> *))\r\n = forall (arg :: b) . KindOf (Apply (Lgo1 l1 l2 l3) arg) ~ KindOf (Lgo2 l1 l2 l3 arg) =>\r\n Lgo1KindInference\r\n\r\ntype family Lgo f\r\n z0\r\n xs0\r\n (a1 :: b)\r\n (a2 :: [a]) :: b where\r\n Lgo f z0 xs0 z '[] = z\r\n Lgo f z0 xs0 z ('(:) x xs) = Apply (Apply (Lgo1 f z0 xs0) (Apply (Apply f z) x)) xs\r\n}}}\r\n\r\nNote that the above code works fine in GHC 7.10.2.\r\n\r\nThere are two options to make the code compile on GHC8-rc3:\r\n* Remove the kind annotations on the {{{forall arg .}}} binders\r\n* Or make the following changes using TypeInType:\r\n\r\n{{{\r\n{-# LANGUAGE RankNTypes, DataKinds, PolyKinds, GADTs, TypeFamilies, UndecidableInstances, TypeInType #-}\r\nmodule NotInScope where\r\n\r\nimport Data.Proxy\r\nimport GHC.Types\r\n\r\ntype KindOf (a :: k) = ('KProxy :: KProxy k)\r\ndata TyFun :: * -> * -> *\r\ntype family Apply (f :: TyFun k1 k2 -> *) (x :: k1) :: k2\r\n\r\ndata Lgo2 a\r\n b\r\n l1\r\n l2\r\n l3\r\n (l4 :: b)\r\n (l5 :: TyFun [a] b)\r\n = forall (arg :: [a]) . KindOf (Apply (Lgo2 a b l1 l2 l3 l4) arg) ~ KindOf (Lgo a b l1 l2 l3 l4 arg) =>\r\n Lgo2KindInference\r\n\r\ndata Lgo1 a\r\n b\r\n l1\r\n l2\r\n l3\r\n (l4 :: TyFun b (TyFun [a] b -> *))\r\n = forall (arg :: b) . KindOf (Apply (Lgo1 a b l1 l2 l3) arg) ~ KindOf (Lgo2 a b l1 l2 l3 arg) =>\r\n Lgo1KindInference\r\n\r\ntype family Lgo a\r\n b\r\n f\r\n z0\r\n xs0\r\n (a1 :: b)\r\n (a2 :: [a]) :: b where\r\n Lgo a b f z0 xs0 z '[] = z\r\n Lgo a b f z0 xs0 z ('(:) x xs) = Apply (Apply (Lgo1 a b f z0 xs0) (Apply (Apply f z) x)) xs\r\n}}}\r\n\r\nI'm sorry I didn't create a smaller test case. Let me know if one is required and I'll try.\r\nThe error seems to be related to the recursive aspect of the three definitions and how implicit kind variables are handled in ghc8.","type_of_failure":"OtherFailure","blocking":[]} -->8.0.2https://gitlab.haskell.org/ghc/ghc/-/issues/11962Support induction recursion2021-12-29T18:28:30ZRichard Eisenbergrae@richarde.devSupport induction recursionNow that we have `-XTypeInType`, let's take it a step further and allow induction recursion. This feature exists in Agda and Idris. Here is a short example of what can be done in Agda:
```
mutual
-- Codes for types.
data U : Set...Now that we have `-XTypeInType`, let's take it a step further and allow induction recursion. This feature exists in Agda and Idris. Here is a short example of what can be done in Agda:
```
mutual
-- Codes for types.
data U : Set where
nat : U
pi : (a : U) → (El a → U) → U
-- A function that interprets codes as actual types.
El : U → Set
El nat = ℕ
El (pi a b) = (x : El a) → El (b x)
```
Note that the `U` datatype and the `El` function depend on each other. But if you look more closely, the header for `U` does not depend on `El`; only the constructors of `U` depend on `El`. So if we typecheck `U : Set` first, then `El : U → Set`, then the constructors of `U`, then the equations of `El`, we're OK.
Translation into Haskell:
```
import Data.Kind
data family Sing (a :: k) -- we still require singletons
data U :: Type where
Nat :: U
Pi :: Sing (a :: U) -> (El a -> U) -> U
type family El (u :: U) :: Type where
El 'Nat = Int
El (Pi a b) = forall (x :: El a). Sing x -> El (b x)
```
This currently errors with
```
• Type constructor ‘U’ cannot be used here
(it is defined and used in the same recursive group)
• In the kind ‘U’
```
It needn't error. (I'm cheating a bit here, because for unrelated reasons, we can't return a `forall` on the right-hand side of a type family. But that's not the issue at hand.)
I have some very sketchy notes on how we might do this [here](https://gitlab.haskell.org/ghc/ghc/wikis/dependent-haskell/internal#separating-type-signatures-from-definitions).
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | -------------- |
| Version | 8.1 |
| 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":"Support induction recursion","status":"New","operating_system":"","component":"Compiler","related":[],"milestone":"","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"8.1","keywords":[],"differentials":[],"test_case":"","architecture":"","cc":[""],"type":"FeatureRequest","description":"Now that we have `-XTypeInType`, let's take it a step further and allow induction recursion. This feature exists in Agda and Idris. Here is a short example of what can be done in Agda:\r\n\r\n{{{\r\n mutual\r\n -- Codes for types.\r\n\r\n data U : Set where\r\n nat : U\r\n pi : (a : U) → (El a → U) → U\r\n\r\n -- A function that interprets codes as actual types.\r\n\r\n El : U → Set\r\n El nat = ℕ\r\n El (pi a b) = (x : El a) → El (b x)\r\n}}}\r\n\r\nNote that the `U` datatype and the `El` function depend on each other. But if you look more closely, the header for `U` does not depend on `El`; only the constructors of `U` depend on `El`. So if we typecheck `U : Set` first, then `El : U → Set`, then the constructors of `U`, then the equations of `El`, we're OK.\r\n\r\nTranslation into Haskell:\r\n\r\n{{{\r\nimport Data.Kind\r\n\r\ndata family Sing (a :: k) -- we still require singletons\r\n\r\ndata U :: Type where\r\n Nat :: U\r\n Pi :: Sing (a :: U) -> (El a -> U) -> U\r\n\r\ntype family El (u :: U) :: Type where\r\n El 'Nat = Int\r\n El (Pi a b) = forall (x :: El a). Sing x -> El (b x)\r\n}}}\r\n\r\nThis currently errors with\r\n\r\n{{{\r\n • Type constructor ‘U’ cannot be used here\r\n (it is defined and used in the same recursive group)\r\n • In the kind ‘U’\r\n}}}\r\n\r\nIt needn't error. (I'm cheating a bit here, because for unrelated reasons, we can't return a `forall` on the right-hand side of a type family. But that's not the issue at hand.)\r\n\r\nI have some very sketchy notes on how we might do this [wiki:DependentHaskell/Internal#Separatingtypesignaturesfromdefinitions here].","type_of_failure":"OtherFailure","blocking":[]} -->https://gitlab.haskell.org/ghc/ghc/-/issues/11963GHC introduces kind equality without TypeInType2019-07-07T18:28:14ZEdward Z. YangGHC introduces kind equality without TypeInTypeThe following program is accepted by GHC 8.0 rc2
```
{-# LANGUAGE GADTs, PolyKinds, RankNTypes #-}
data Typ k t where
Typ :: (forall (a :: k -> *). a t -> a t) -> Typ k t
```
This probably shouldn't be accepted, because this is a ...The following program is accepted by GHC 8.0 rc2
```
{-# LANGUAGE GADTs, PolyKinds, RankNTypes #-}
data Typ k t where
Typ :: (forall (a :: k -> *). a t -> a t) -> Typ k t
```
This probably shouldn't be accepted, because this is a circuitous way of saying:
```
{-# LANGUAGE TypeInType #-}
data Typ k (t :: k) = Typ
```
which does not work without `TypeInType`. Or perhaps both should be accepted without `TypeInType`?
Printing with explicit kinds makes it clear why the obvious check didn't fire:
```
ezyang@sabre:~$ ghc-8.0 --interactive B.hs -fprint-explicit-kinds
GHCi, version 8.0.0.20160204: http://www.haskell.org/ghc/ :? for help
[1 of 1] Compiling Main ( B.hs, interpreted )
Ok, modules loaded: Main.
*Main> :info Typ
type role Typ nominal nominal nominal
data Typ k k1 (t :: k) where
Typ :: forall k (t :: k).
(forall (a :: k -> *). a t -> a t) -> Typ k k t
-- Defined at B.hs:2:1
```
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | ----------------------- |
| Version | 8.0.1-rc2 |
| 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 introduces kind equality without TypeInType","status":"New","operating_system":"","component":"Compiler (Type checker)","related":[],"milestone":"","resolution":"Unresolved","owner":{"tag":"OwnedBy","contents":"goldfire"},"version":"8.0.1-rc2","keywords":[],"differentials":[],"test_case":"","architecture":"","cc":[""],"type":"Bug","description":"The following program is accepted by GHC 8.0 rc2\r\n\r\n{{{\r\n{-# LANGUAGE GADTs, PolyKinds, RankNTypes #-}\r\ndata Typ k t where\r\n Typ :: (forall (a :: k -> *). a t -> a t) -> Typ k t\r\n}}}\r\n\r\nThis probably shouldn't be accepted, because this is a circuitous way of saying:\r\n\r\n{{{\r\n{-# LANGUAGE TypeInType #-}\r\ndata Typ k (t :: k) = Typ\r\n}}}\r\n\r\nwhich does not work without `TypeInType`. Or perhaps both should be accepted without `TypeInType`?\r\n\r\nPrinting with explicit kinds makes it clear why the obvious check didn't fire:\r\n\r\n{{{\r\nezyang@sabre:~$ ghc-8.0 --interactive B.hs -fprint-explicit-kinds\r\nGHCi, version 8.0.0.20160204: http://www.haskell.org/ghc/ :? for help\r\n[1 of 1] Compiling Main ( B.hs, interpreted )\r\nOk, modules loaded: Main.\r\n*Main> :info Typ\r\ntype role Typ nominal nominal nominal\r\ndata Typ k k1 (t :: k) where\r\n Typ :: forall k (t :: k).\r\n (forall (a :: k -> *). a t -> a t) -> Typ k k t\r\n \t-- Defined at B.hs:2:1\r\n}}}","type_of_failure":"OtherFailure","blocking":[]} -->8.4.1johnleojohnleohttps://gitlab.haskell.org/ghc/ghc/-/issues/11964Without TypeInType, inconsistently accepts Data.Kind.Type but not type synonym2019-07-07T18:28:14ZEdward Z. YangWithout TypeInType, inconsistently accepts Data.Kind.Type but not type synonymFor convenience, I'll use GHCi to demonstrate flag behavior. First, we define a file:
```
{-# LANGUAGE TypeInType #-}
import Data.Kind
type Star = Type
newtype T k (t :: k) = T ()
```
Next, we load it up in GHCi, WITHOUT `-XTypeInType`...For convenience, I'll use GHCi to demonstrate flag behavior. First, we define a file:
```
{-# LANGUAGE TypeInType #-}
import Data.Kind
type Star = Type
newtype T k (t :: k) = T ()
```
Next, we load it up in GHCi, WITHOUT `-XTypeInType`. Now we observe strange behavior:
```
ezyang@sabre:~$ ghc-8.0 --interactive C.hs
GHCi, version 8.0.0.20160204: http://www.haskell.org/ghc/ :? for help
[1 of 1] Compiling Main ( C.hs, interpreted )
Ok, modules loaded: Main.
*Main> :k T Type Int
T Type Int :: *
*Main> :k T Star Int
<interactive>:1:3: error:
• Data constructor ‘Star’ cannot be used here
(Perhaps you intended to use DataKinds)
• In the first argument of ‘T’, namely ‘Star’
In the type ‘T Star Int’
```
Of course, if we pass `-TypeInType` to GHCi that fixes the problem (BTW, `DataKinds` does NOT solve the problem.)Richard Eisenbergrae@richarde.devRichard Eisenbergrae@richarde.devhttps://gitlab.haskell.org/ghc/ghc/-/issues/11966Surprising behavior with higher-rank quantification of kind variables2019-07-07T18:28:13ZOllie CharlesSurprising behavior with higher-rank quantification of kind variablesSorry about the rubbish title. I wrote the following code, which type checks:
```hs
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE RankNTypes #-}
{-# LANG...Sorry about the rubbish title. I wrote the following code, which type checks:
```hs
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE TypeInType #-}
{-# LANGUAGE TypeOperators #-}
module Test where
import Data.Kind (Type)
-- Simplification
type family Col (f :: k -> j) (x :: k) :: Type
-- Base types
data PGBaseType = PGInteger | PGText
-- Transformations
data Column t = Column Symbol t
newtype Nullable t = Nullable t
newtype HasDefault t = HasDefault t
-- Interpretations
data Expr k
data Record (f :: forall k. k -> Type) =
Record {rX :: Col f ('Column "x" 'PGInteger)
,rY :: Col f ('Column "y" ('Nullable 'PGInteger))
,rZ :: Col f ('HasDefault 'PGText)}
```
However, if I play with this in GHCI, I can get the following error:
```
λ> let x = undefined :: Record Expr
<interactive>:136:29-32: error:
• Expected kind ‘forall k. k -> Type’,
but ‘Expr’ has kind ‘forall k. k -> *’
• In the first argument of ‘Record’, namely ‘Expr’
In an expression type signature: Record Expr
In the expression: undefined :: Record Expr
```
It seems that if I write
```hs
data Expr :: forall k. k -> Type
```
things work, but I'm unclear if/why that is necessary, and the error message certainly needs to be fixed.
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | ----------------------- |
| Version | 8.0.1-rc3 |
| 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":"Surprising behavior with higher-rank quantification of kind variables","status":"New","operating_system":"","component":"Compiler (Type checker)","related":[],"milestone":"","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"8.0.1-rc3","keywords":["TypeInType"],"differentials":[],"test_case":"","architecture":"","cc":[""],"type":"Bug","description":"Sorry about the rubbish title. I wrote the following code, which type checks:\r\n\r\n{{{#!hs\r\n{-# LANGUAGE TypeFamilies #-}\r\n{-# LANGUAGE DataKinds #-}\r\n{-# LANGUAGE KindSignatures #-}\r\n{-# LANGUAGE PolyKinds #-}\r\n{-# LANGUAGE RankNTypes #-}\r\n{-# LANGUAGE TypeInType #-}\r\n{-# LANGUAGE TypeOperators #-}\r\n\r\nmodule Test where\r\n\r\nimport Data.Kind (Type)\r\n\r\n-- Simplification\r\ntype family Col (f :: k -> j) (x :: k) :: Type\r\n\r\n-- Base types\r\ndata PGBaseType = PGInteger | PGText\r\n\r\n-- Transformations\r\ndata Column t = Column Symbol t\r\nnewtype Nullable t = Nullable t\r\nnewtype HasDefault t = HasDefault t\r\n\r\n-- Interpretations\r\ndata Expr k\r\n\r\ndata Record (f :: forall k. k -> Type) =\r\n Record {rX :: Col f ('Column \"x\" 'PGInteger)\r\n ,rY :: Col f ('Column \"y\" ('Nullable 'PGInteger))\r\n ,rZ :: Col f ('HasDefault 'PGText)}\r\n\r\n}}}\r\n\r\nHowever, if I play with this in GHCI, I can get the following error:\r\n\r\n{{{\r\nλ> let x = undefined :: Record Expr\r\n\r\n<interactive>:136:29-32: error:\r\n • Expected kind ‘forall k. k -> Type’,\r\n but ‘Expr’ has kind ‘forall k. k -> *’\r\n • In the first argument of ‘Record’, namely ‘Expr’\r\n In an expression type signature: Record Expr\r\n In the expression: undefined :: Record Expr\r\n}}}\r\n\r\nIt seems that if I write\r\n\r\n{{{#!hs\r\ndata Expr :: forall k. k -> Type\r\n}}}\r\n\r\nthings work, but I'm unclear if/why that is necessary, and the error message certainly needs to be fixed.","type_of_failure":"OtherFailure","blocking":[]} -->8.2.1https://gitlab.haskell.org/ghc/ghc/-/issues/11995Can't infer type2019-07-07T18:28:05ZIcelandjackCan't infer type```hs
{-# LANGUAGE RankNTypes, LambdaCase, TypeOperators,
TypeInType, UnicodeSyntax, GADTs #-}
module T11995 where
import Data.Kind
data NP :: forall k. (ĸ → Type) → ([k] → Type) where
Nil :: NP f '[]
(:*) :: f x → N...```hs
{-# LANGUAGE RankNTypes, LambdaCase, TypeOperators,
TypeInType, UnicodeSyntax, GADTs #-}
module T11995 where
import Data.Kind
data NP :: forall k. (ĸ → Type) → ([k] → Type) where
Nil :: NP f '[]
(:*) :: f x → NP f xs → NP f (x:xs)
newtype K a b = K a deriving Show
unK (K a) = a
h'collapse :: NP (K a) xs -> [a]
h'collapse = \case
Nil -> []
K x:*xs -> x : h'collapse xs
```
if we replace `xs` by an underscore:
```
tJN0.hs:13:29-30: error: …
• Could not deduce: (xs :: [ĸ]) ~~ ((':) ĸ x xs :: [ĸ])
from the context: ((k :: *) ~~ (ĸ :: *),
(t :: [k]) ~~ ((':) ĸ x xs :: [ĸ]))
bound by a pattern with constructor:
:* :: forall k (f :: k -> *) (x :: k) (xs :: [k]).
f x -> NP k k f xs -> NP k k f ((':) k x xs),
in a case alternative
at /tmp/tJN0.hs:13:3-9
‘xs’ is a rigid type variable bound by
a pattern with constructor:
:* :: forall k (f :: k -> *) (x :: k) (xs :: [k]).
f x -> NP k k f xs -> NP k k f ((':) k x xs),
in a case alternative
at /tmp/tJN0.hs:13:3
Expected type: NP ĸ k (K ĸ a) t
Actual type: NP ĸ ĸ (K ĸ a) xs
• In the first argument of ‘h'collapse’, namely ‘xs’
In the second argument of ‘(:)’, namely ‘h'collapse xs’
In the expression: x : h'collapse xs
• Relevant bindings include
xs :: NP ĸ ĸ (K ĸ a) xs (bound at /tmp/tJN0.hs:13:8)
h'collapse :: NP ĸ k (K ĸ a) t -> [a] (bound at /tmp/tJN0.hs:11:1)
Compilation failed.
```
Should it not be able to infer that?
The Glorious Glasgow Haskell Compilation System, version 8.1.201604198.2.2https://gitlab.haskell.org/ghc/ghc/-/issues/12029Notify user to import * from Data.Kind with TypeInType on2019-07-07T18:27:55ZIcelandjackNotify user to import * from Data.Kind with TypeInType onWith `TypeInType` asking for the kind of `*` gives the user a warning to import it
```
ghci> :set -XTypeInType
ghci> :k *
<interactive>:1:1: error:
Not in scope: type constructor or class ‘*’
NB: With TypeInType, you must impo...With `TypeInType` asking for the kind of `*` gives the user a warning to import it
```
ghci> :set -XTypeInType
ghci> :k *
<interactive>:1:1: error:
Not in scope: type constructor or class ‘*’
NB: With TypeInType, you must import * from Data.Kind
<interactive>:1:1: error:
Illegal operator ‘*’ in type ‘*’
Use TypeOperators to allow operators in types
<interactive>:1:1: error: Operator applied to too few arguments: *
```
Should a similar warning be issued when she asks for information on it
```
ghci> :i *
class Num a where
...
(*) :: a -> a -> a
...
-- Defined in ‘GHC.Num’
infixl 7 *
```
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | -------------- |
| Version | 8.1 |
| Type | FeatureRequest |
| TypeOfFailure | OtherFailure |
| Priority | lowest |
| Resolution | Unresolved |
| Component | GHCi |
| Test case | |
| Differential revisions | |
| BlockedBy | |
| Related | |
| Blocking | |
| CC | |
| Operating system | |
| Architecture | |
</details>
<!-- {"blocked_by":[],"summary":"Notify user to import * from Data.Kind with TypeInType on","status":"New","operating_system":"","component":"GHCi","related":[],"milestone":"","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"8.1","keywords":["TypeInType"],"differentials":[],"test_case":"","architecture":"","cc":[""],"type":"FeatureRequest","description":"With `TypeInType` asking for the kind of `*` gives the user a warning to import it\r\n\r\n{{{\r\nghci> :set -XTypeInType \r\nghci> :k *\r\n\r\n<interactive>:1:1: error:\r\n Not in scope: type constructor or class ‘*’\r\n NB: With TypeInType, you must import * from Data.Kind\r\n\r\n<interactive>:1:1: error:\r\n Illegal operator ‘*’ in type ‘*’\r\n Use TypeOperators to allow operators in types\r\n\r\n<interactive>:1:1: error: Operator applied to too few arguments: *\r\n}}}\r\n\r\nShould a similar warning be issued when she asks for information on it\r\n\r\n{{{\r\nghci> :i *\r\nclass Num a where\r\n ...\r\n (*) :: a -> a -> a\r\n ...\r\n -- Defined in ‘GHC.Num’\r\ninfixl 7 *\r\n}}}","type_of_failure":"OtherFailure","blocking":[]} -->johnleojohnleohttps://gitlab.haskell.org/ghc/ghc/-/issues/12030GHCi Proposal: Display (Data.Kind.)Type instead of *2019-07-07T18:27:55ZIcelandjackGHCi Proposal: Display (Data.Kind.)Type instead of *This is premature but what the darn,
```
>>> :kind Maybe
Maybe :: Type -> Type
>>> :kind StateT
StateT :: Type -> (Type -> Type) -> Type -> Type
>>> :kind Eq
Eq :: Type -> Constraint
>>> :info Functor
class Functor (f :: Type -> Type) ...This is premature but what the darn,
```
>>> :kind Maybe
Maybe :: Type -> Type
>>> :kind StateT
StateT :: Type -> (Type -> Type) -> Type -> Type
>>> :kind Eq
Eq :: Type -> Constraint
>>> :info Functor
class Functor (f :: Type -> Type) where
...
```
`*` throws students off in my experience, makes it seem scarier than it is. Symbols are harder to search for and understand without documentation, `Type` on the other hand is descriptive.
There are arguments against:
1. It's a recent feature that is subject to change.
1. `*` is established in questions online, educational material, logs and blogs.
1. `Type` is not in scope by default: user cannot query GHCi.
`*` is established and searching for “Haskell asterisk” yields a lot resources but [‘\*’ is also a wildcard](https://support.google.com/websearch/answer/2466433?hl=en) in Google and ignored by GitHub. With time `Type` would be a good search term but currently it's chicken-and-the-egg.
Previous versions of GHCi error on `:kind *` and `:info *` only shows multiplication so that wouldn't be a huge difference but we can qualify by default:
```
>>> :kind Maybe
Maybe :: Data.Kind.Type -> Data.Kind.Type
>>> :kind StateT
StateT :: Data.Kind.Type -> (Data.Kind.Type -> Data.Kind.Type) -> Data.Kind.Type -> Data.Kind.Type
>>> :kind Eq
Eq :: Data.Kind.Type -> Constraint
>>> :info Functor
class Functor (f :: Data.Kind.Type -> Data.Kind.Type) where
...
```
or display `*` normally and only when `TypeInType` is set do we display `Type`. I don't love it (and love `GHC.Types.Type` slightly less) but there is a precedent for unqualified names, browsing the Prelude for example:
```hs
($) ::
forall (r :: GHC.Types.RuntimeRep) a (b :: TYPE r).
(a -> b) -> a -> b
undefined ::
forall (r :: GHC.Types.RuntimeRep) (a :: TYPE r).
GHC.Stack.Types.HasCallStack =>
a
```
__If__ the consensus is that this will happen sometime down the line consider that each passing release means many more books and blog posts get written using `*`.
I wasn't planning on resulting to scare tactics but [here we are](https://www.peoria.com/spaw/spawimages/members/member60763/shoot_this_dog.jpg)...
----
If needed a migration plan can be drafted like the Semigroup/FTP/AMP/BBP/MonadFail/expanding Float/... proposals, possibly culminating in `Type` fully replacing `*` and being imported by default. I'm sure there are some further reaching consequences to this and better arguments against.8.6.1johnleojohnleohttps://gitlab.haskell.org/ghc/ghc/-/issues/12045Visible kind application2019-07-07T18:27:52ZIcelandjackVisible kind applicationI've wanted this for a while
```
ghci> :kind (:~:)
(:~:) :: k -> k -> Type
```
```
ghci> :kind (:~:) @(Type -> Type)
(:~:) @(Type -> Type) :: (Type -> Type) -> (Type -> Type) -> Type
ghci> :kind (:~:) @(Type -> Type) []
(:~:) @(Type -...I've wanted this for a while
```
ghci> :kind (:~:)
(:~:) :: k -> k -> Type
```
```
ghci> :kind (:~:) @(Type -> Type)
(:~:) @(Type -> Type) :: (Type -> Type) -> (Type -> Type) -> Type
ghci> :kind (:~:) @(Type -> Type) []
(:~:) @(Type -> Type) [] :: (Type -> Type) -> Type
ghci> :kind (:~:) @(Type -> Type) [] Maybe
(:~:) @(Type -> Type) [] Maybe :: Type
```
Working like
```
ghci> type Same k (a::k) (b::k) = a :~: b
ghci> :kind Same
Same :: forall k -> k -> k -> *
```
```
ghci> :kind Same (Type -> Type)
Same (Type -> Type) :: (Type -> Type) -> (Type -> Type) -> *
ghci> :kind Same (Type -> Type) []
Same (Type -> Type) [] :: (Type -> Type) -> *
ghci> :kind Same (Type -> Type) [] Maybe
Same (Type -> Type) [] Maybe :: *
```
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | -------------- |
| Version | 8.1 |
| 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":"Visible kind application","status":"New","operating_system":"","component":"Compiler","related":[],"milestone":"","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"8.1","keywords":["TypeApplications","TypeInType"],"differentials":[],"test_case":"","architecture":"","cc":[""],"type":"FeatureRequest","description":"I've wanted this for a while\r\n\r\n{{{\r\nghci> :kind (:~:)\r\n(:~:) :: k -> k -> Type\r\n}}}\r\n\r\n{{{\r\nghci> :kind (:~:) @(Type -> Type)\r\n(:~:) @(Type -> Type) :: (Type -> Type) -> (Type -> Type) -> Type\r\n\r\nghci> :kind (:~:) @(Type -> Type) []\r\n(:~:) @(Type -> Type) [] :: (Type -> Type) -> Type\r\n\r\nghci> :kind (:~:) @(Type -> Type) [] Maybe\r\n(:~:) @(Type -> Type) [] Maybe :: Type\r\n}}}\r\n\r\nWorking like\r\n\r\n{{{\r\nghci> type Same k (a::k) (b::k) = a :~: b\r\nghci> :kind Same\r\nSame :: forall k -> k -> k -> *\r\n}}}\r\n\r\n{{{\r\nghci> :kind Same (Type -> Type)\r\nSame (Type -> Type) :: (Type -> Type) -> (Type -> Type) -> *\r\nghci> :kind Same (Type -> Type) []\r\nSame (Type -> Type) [] :: (Type -> Type) -> *\r\nghci> :kind Same (Type -> Type) [] Maybe\r\nSame (Type -> Type) [] Maybe :: *\r\n}}}","type_of_failure":"OtherFailure","blocking":[]} -->8.8.1My NguyenMy Nguyenhttps://gitlab.haskell.org/ghc/ghc/-/issues/12081TypeInType Compile-time Panic2020-09-19T19:52:25ZMichaelKTypeInType Compile-time PanicI've been playing around with GHC 8.0.1-rc4 release and got a panic from the following (stripped down) code:
```hs
{-# LANGUAGE TypeInType #-}
data Nat = Z | S Nat
class C (n :: Nat) where
type T n :: Nat
f :: (a :: T n)
```
```
...I've been playing around with GHC 8.0.1-rc4 release and got a panic from the following (stripped down) code:
```hs
{-# LANGUAGE TypeInType #-}
data Nat = Z | S Nat
class C (n :: Nat) where
type T n :: Nat
f :: (a :: T n)
```
```
ghc: panic! (the 'impossible' happened)
(GHC version 8.0.0.20160421 for x86_64-apple-darwin):
isInjectiveTyCon sees a TcTyCon T
```
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | ------------ |
| Version | 8.0.1-rc4 |
| 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":"TypeInType Compile-time Panic","status":"New","operating_system":"","component":"Compiler","related":[],"milestone":"","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"8.0.1-rc4","keywords":[],"differentials":[],"test_case":"","architecture":"","cc":[""],"type":"Bug","description":"I've been playing around with GHC 8.0.1-rc4 release and got a panic from the following (stripped down) code:\r\n\r\n{{{#!hs\r\n{-# LANGUAGE TypeInType #-}\r\n\r\ndata Nat = Z | S Nat\r\n\r\nclass C (n :: Nat) where\r\n type T n :: Nat\r\n f :: (a :: T n)\r\n}}}\r\n\r\n{{{\r\nghc: panic! (the 'impossible' happened)\r\n (GHC version 8.0.0.20160421 for x86_64-apple-darwin):\r\n\tisInjectiveTyCon sees a TcTyCon T\r\n}}}\r\n","type_of_failure":"OtherFailure","blocking":[]} -->https://gitlab.haskell.org/ghc/ghc/-/issues/12102“Constraints in kinds” illegal family application in instance (+ documentatio...2022-10-22T21:03:44ZIcelandjack“Constraints in kinds” illegal family application in instance (+ documentation issues?)GHC 8.0.0.20160511. Example from the user guide: [Constraints in kinds](https://downloads.haskell.org/~ghc/8.0.1/docs/html/users_guide/glasgow_exts.html#constraints-in-kinds)
```hs
type family IsTypeLit a where
IsTypeLit Nat = 'Tru...GHC 8.0.0.20160511. Example from the user guide: [Constraints in kinds](https://downloads.haskell.org/~ghc/8.0.1/docs/html/users_guide/glasgow_exts.html#constraints-in-kinds)
```hs
type family IsTypeLit a where
IsTypeLit Nat = 'True
IsTypeLit Symbol = 'True
IsTypeLit a = 'False
data T :: forall a. (IsTypeLit a ~ 'True) => a -> * where
MkNat :: T 42
MkSymbol :: T "Don't panic!"
```
Deriving a standalone `Show` instance \*without\* the constraint `(IsTypeLit a ~ 'True) => ` works fine
```hs
deriving instance Show (T a)
```
but I couldn't define a `Show` instance given the constraints:
```hs
-- • Couldn't match expected kind ‘'True’
-- with actual kind ‘IsTypeLit a0’
-- The type variable ‘a0’ is ambiguous
-- • In the first argument of ‘Show’, namely ‘T a’
-- In the stand-alone deriving instance for ‘Show (T a)’
deriving instance Show (T a)
```
let's add constraints
```hs
-- • Couldn't match expected kind ‘'True’
-- with actual kind ‘IsTypeLit lit’
-- • In the first argument of ‘Show’, namely ‘T (a :: lit)’
-- In the instance declaration for ‘Show (T (a :: lit))’
instance IsTypeLit lit ~ 'True => Show (T (a :: lit)) where
```
let's derive for a single literal
```hs
-- • Illegal type synonym family application in instance:
-- T Nat
-- ('Data.Type.Equality.C:~
-- Bool
-- (IsTypeLit Nat)
-- 'True
-- ('GHC.Types.Eq# Bool Bool (IsTypeLit Nat) 'True <>))
-- 42
-- • In the stand-alone deriving instance for ‘Show (T (42 :: Nat))’
deriving instance Show (T (42 :: Nat))
```
same happens with
```hs
instance Show (T 42) where
```
----
The documentation
> Note that explicitly quantifying with `forall a` is not necessary here.
seems to be wrong since removing it results in
```
tVDv.hs:10:17-18: error: …
• Expected kind ‘a’, but ‘42’ has kind ‘Nat’
• In the first argument of ‘T’, namely ‘42’
In the type ‘T 42’
In the definition of data constructor ‘MkNat’
Compilation failed.
```8.10.1https://gitlab.haskell.org/ghc/ghc/-/issues/12174Recursive use of type-in-type results in infinite loop2020-09-19T19:52:25ZEdward Z. YangRecursive use of type-in-type results in infinite loopTypechecking this module results in an infinite loop:
```
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE ExistentialQuantification #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE TypeInType #-}
module X where
data V a
data T = forall (a :: S...Typechecking this module results in an infinite loop:
```
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE ExistentialQuantification #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE TypeInType #-}
module X where
data V a
data T = forall (a :: S). MkT (V a)
data S = forall (a :: T). MkS (V a)
```
There's a mutually recursive reference so it should be rejected but maybe the check is not happening early enough (or the existing check is only for self-reference.)
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | ----------------------- |
| Version | 8.0.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":"Recursive use of type-in-type results in infinite loop","status":"New","operating_system":"","component":"Compiler (Type checker)","related":[],"milestone":"","resolution":"Unresolved","owner":{"tag":"OwnedBy","contents":"goldfire"},"version":"8.0.1","keywords":[],"differentials":[],"test_case":"","architecture":"","cc":[""],"type":"Bug","description":"Typechecking this module results in an infinite loop:\r\n\r\n{{{\r\n{-# LANGUAGE DataKinds #-}\r\n{-# LANGUAGE ExistentialQuantification #-}\r\n{-# LANGUAGE KindSignatures #-}\r\n{-# LANGUAGE TypeInType #-}\r\nmodule X where\r\n\r\ndata V a\r\ndata T = forall (a :: S). MkT (V a)\r\ndata S = forall (a :: T). MkS (V a)\r\n}}}\r\n\r\nThere's a mutually recursive reference so it should be rejected but maybe the check is not happening early enough (or the existing check is only for self-reference.)","type_of_failure":"OtherFailure","blocking":[]} -->8.2.1Richard Eisenbergrae@richarde.devRichard Eisenbergrae@richarde.devhttps://gitlab.haskell.org/ghc/ghc/-/issues/12176Failure of bidirectional type inference at the kind level2019-07-07T18:27:19ZRichard Eisenbergrae@richarde.devFailure of bidirectional type inference at the kind levelI'm feeling particularly sadistic towards GHC at the moment, and so I fed it this:
```hs
import Data.Kind
data Proxy :: forall k. k -> Type where
MkProxy :: forall k (a :: k). Proxy a
data X where
MkX :: forall (k :: Type) (a :: k...I'm feeling particularly sadistic towards GHC at the moment, and so I fed it this:
```hs
import Data.Kind
data Proxy :: forall k. k -> Type where
MkProxy :: forall k (a :: k). Proxy a
data X where
MkX :: forall (k :: Type) (a :: k). Proxy a -> X
type Expr = (MkX :: forall (a :: Bool). Proxy a -> X)
type family Foo (x :: forall (a :: k). Proxy a -> X) where
Foo (MkX :: forall (a :: k). Proxy a -> X) = (MkProxy :: Proxy k)
```
Incredibly, GHC accepts it! And it even means what I wish it to, with GHCi telling me the following (with `-fprint-explicit-kinds`):
```
λ> :i Foo
type family Foo k (x :: forall (a :: k). Proxy k a -> X)
:: Proxy * k
where [k] Foo k ('MkX k) = 'MkProxy * k
```
That is, I wished to extract the kind parameter to `MkK`, matching against a partially-applied `MkX`, and GHC understood that intention.
However, sadly, writing `Foo Expr` produces
```
• Expected kind ‘forall (a :: k0). Proxy k0 a -> X’,
but ‘Expr a0’ has kind ‘Proxy Bool a0 -> X’
• In the first argument of ‘Foo’, namely ‘Expr’
In the type ‘Foo Expr’
In the type family declaration for ‘XXX’
```
For some reason, `Expr` is getting instantiated when it shouldn't be.
Perhaps there's a simpler test case demonstrating the bug, but I feel so gleeful that this chicanery is accepted at all that I wanted to post.8.4.1Richard Eisenbergrae@richarde.devRichard Eisenbergrae@richarde.devhttps://gitlab.haskell.org/ghc/ghc/-/issues/12239Dependent type family does not reduce2024-02-27T13:56:52ZVladislav ZavialovDependent type family does not reduceWhen a type family is used in a kind of an argument for another type family, it does not reduce. Here's example code:
```
{-# LANGUAGE TypeInType, GADTs, TypeFamilies #-}
import Data.Kind (Type)
data N = Z | S N
data Fin :: N -> Type...When a type family is used in a kind of an argument for another type family, it does not reduce. Here's example code:
```
{-# LANGUAGE TypeInType, GADTs, TypeFamilies #-}
import Data.Kind (Type)
data N = Z | S N
data Fin :: N -> Type where
FZ :: Fin (S n)
FS :: Fin n -> Fin (S n)
type family FieldCount (t :: Type) :: N
type family FieldType (t :: Type) (i :: Fin (FieldCount t)) :: Type
data T
type instance FieldCount T = S (S (S Z))
type instance FieldType T FZ = Int
type instance FieldType T (FS FZ) = Bool
type instance FieldType T (FS (FS FZ)) = String
```
Unfortunately, I get these errors during typechecking:
```
[1 of 1] Compiling Main ( fieldtype.hs, fieldtype.o )
fieldtype.hs:19:27: error:
• Expected kind ‘Fin (FieldCount T)’,
but ‘'FZ’ has kind ‘Fin ('S n0)’
• In the second argument of ‘FieldType’, namely ‘FZ’
In the type instance declaration for ‘FieldType’
fieldtype.hs:20:28: error:
• Expected kind ‘Fin (FieldCount T)’,
but ‘'FS 'FZ’ has kind ‘Fin ('S ('S n0))’
• In the second argument of ‘FieldType’, namely ‘FS FZ’
In the type instance declaration for ‘FieldType’
fieldtype.hs:21:28: error:
• Expected kind ‘Fin (FieldCount T)’,
but ‘'FS ('FS 'FZ)’ has kind ‘Fin ('S ('S ('S n0)))’
• In the second argument of ‘FieldType’, namely ‘FS (FS FZ)’
In the type instance declaration for ‘FieldType’
```
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | ----------------------- |
| Version | 8.0.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":"Dependent type family does not reduce","status":"New","operating_system":"","component":"Compiler (Type checker)","related":[],"milestone":"","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"8.0.1","keywords":["TypeFamilies","TypeInType,"],"differentials":[],"test_case":"","architecture":"","cc":[""],"type":"Bug","description":"When a type family is used in a kind of an argument for another type family, it does not reduce. Here's example code:\r\n\r\n\r\n{{{\r\n{-# LANGUAGE TypeInType, GADTs, TypeFamilies #-}\r\n\r\nimport Data.Kind (Type)\r\n\r\ndata N = Z | S N\r\n\r\ndata Fin :: N -> Type where\r\n FZ :: Fin (S n)\r\n FS :: Fin n -> Fin (S n)\r\n\r\ntype family FieldCount (t :: Type) :: N\r\n\r\ntype family FieldType (t :: Type) (i :: Fin (FieldCount t)) :: Type\r\n\r\ndata T\r\n\r\ntype instance FieldCount T = S (S (S Z))\r\n\r\ntype instance FieldType T FZ = Int\r\ntype instance FieldType T (FS FZ) = Bool\r\ntype instance FieldType T (FS (FS FZ)) = String\r\n}}}\r\n\r\nUnfortunately, I get these errors during typechecking:\r\n\r\n{{{\r\n[1 of 1] Compiling Main ( fieldtype.hs, fieldtype.o )\r\n\r\nfieldtype.hs:19:27: error:\r\n • Expected kind ‘Fin (FieldCount T)’,\r\n but ‘'FZ’ has kind ‘Fin ('S n0)’\r\n • In the second argument of ‘FieldType’, namely ‘FZ’\r\n In the type instance declaration for ‘FieldType’\r\n\r\nfieldtype.hs:20:28: error:\r\n • Expected kind ‘Fin (FieldCount T)’,\r\n but ‘'FS 'FZ’ has kind ‘Fin ('S ('S n0))’\r\n • In the second argument of ‘FieldType’, namely ‘FS FZ’\r\n In the type instance declaration for ‘FieldType’\r\n\r\nfieldtype.hs:21:28: error:\r\n • Expected kind ‘Fin (FieldCount T)’,\r\n but ‘'FS ('FS 'FZ)’ has kind ‘Fin ('S ('S ('S n0)))’\r\n • In the second argument of ‘FieldType’, namely ‘FS (FS FZ)’\r\n In the type instance declaration for ‘FieldType’\r\n}}}","type_of_failure":"OtherFailure","blocking":[]} -->Vladislav ZavialovVladislav Zavialovhttps://gitlab.haskell.org/ghc/ghc/-/issues/12369data families shouldn't be required to have return kind *, data instances should2021-09-09T23:17:59ZEdward Kmettdata families shouldn't be required to have return kind *, data instances shouldI'd like to be able to define
```hs
{-# language PolyKinds, KindSignatures, GADTs, TypeFamilies #-}
data family Fix :: (k -> *) -> k
newtype instance Fix f = In { out :: f (Fix f) }
```
But currently this is disallowed:
```
Fix.hs:2:1...I'd like to be able to define
```hs
{-# language PolyKinds, KindSignatures, GADTs, TypeFamilies #-}
data family Fix :: (k -> *) -> k
newtype instance Fix f = In { out :: f (Fix f) }
```
But currently this is disallowed:
```
Fix.hs:2:1: error:
• Kind signature on data type declaration has non-* return kind
(k -> *) -> k
• In the data family declaration for ‘Fix’
```
Ultimately I think the issue here is that data __instances__ should be required to end in kind \*, not the families, but this generalization didn't mean anything until we had `PolyKinds`.
As an example of a usecase, with the above, I could define a bifunctor fixed point such as
```hs
newtype instance Fix f a = In2 { out2 :: f (Fix f a) a }
```
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | ----------------------- |
| Version | 8.0.1 |
| Type | FeatureRequest |
| 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 families shouldn't be required to have return kind *, data instances should","status":"New","operating_system":"","component":"Compiler (Type checker)","related":[],"milestone":"8.2.1","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"8.0.1","keywords":[],"differentials":[],"test_case":"","architecture":"","cc":[""],"type":"FeatureRequest","description":"I'd like to be able to define\r\n\r\n{{{#!hs\r\n{-# language PolyKinds, KindSignatures, GADTs, TypeFamilies #-}\r\ndata family Fix :: (k -> *) -> k\r\nnewtype instance Fix f = In { out :: f (Fix f) }\r\n}}}\r\n\r\nBut currently this is disallowed:\r\n\r\n{{{\r\nFix.hs:2:1: error:\r\n • Kind signature on data type declaration has non-* return kind\r\n (k -> *) -> k\r\n • In the data family declaration for ‘Fix’\r\n}}}\r\n\r\nUltimately I think the issue here is that data __instances__ should be required to end in kind *, not the families, but this generalization didn't mean anything until we had `PolyKinds`.\r\n\r\nAs an example of a usecase, with the above, I could define a bifunctor fixed point such as\r\n\r\n{{{#!hs\r\nnewtype instance Fix f a = In2 { out2 :: f (Fix f a) a }\r\n}}}","type_of_failure":"OtherFailure","blocking":[]} -->8.4.1https://gitlab.haskell.org/ghc/ghc/-/issues/12442Pure unifier usually doesn't need to unify kinds2019-07-07T18:26:36ZRichard Eisenbergrae@richarde.devPure unifier usually doesn't need to unify kindsThe pure unifier (in `types/Unify.hs`) is used to match up instances with actual types. Since GHC 8, it matches up the kinds with the types in a separate pass. But this is often wasteful, and sometimes downright wrong.
It's wasteful bec...The pure unifier (in `types/Unify.hs`) is used to match up instances with actual types. Since GHC 8, it matches up the kinds with the types in a separate pass. But this is often wasteful, and sometimes downright wrong.
It's wasteful because most invocations of the unifier on a list of types pass in well-kinded arguments to some type constructor. Because the kinds of type constructors are closed, if we process the list left-to-right, we will always unify the kinds of later arguments before we get to them. So we shouldn't take another pass on the kinds.
It's wrong because it's conceivable for the kind to include a type family application, and using a type family application as a template in the pure unifier is very silly, indeed.
I cam across this while trying to translate Idris's algebraic effects library to Haskell. My reduced test case is attached.
Patch on the way.
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | ------------ |
| Version | 8.0.1 |
| 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":"Pure unifier usually doesn't need to unify kinds","status":"New","operating_system":"","component":"Compiler","related":[],"milestone":"","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"8.0.1","keywords":["TypeInType"],"differentials":[],"test_case":"","architecture":"","cc":[""],"type":"Bug","description":"The pure unifier (in `types/Unify.hs`) is used to match up instances with actual types. Since GHC 8, it matches up the kinds with the types in a separate pass. But this is often wasteful, and sometimes downright wrong.\r\n\r\nIt's wasteful because most invocations of the unifier on a list of types pass in well-kinded arguments to some type constructor. Because the kinds of type constructors are closed, if we process the list left-to-right, we will always unify the kinds of later arguments before we get to them. So we shouldn't take another pass on the kinds.\r\n\r\nIt's wrong because it's conceivable for the kind to include a type family application, and using a type family application as a template in the pure unifier is very silly, indeed.\r\n\r\nI cam across this while trying to translate Idris's algebraic effects library to Haskell. My reduced test case is attached.\r\n\r\nPatch on the way.","type_of_failure":"OtherFailure","blocking":[]} -->Richard Eisenbergrae@richarde.devRichard Eisenbergrae@richarde.devhttps://gitlab.haskell.org/ghc/ghc/-/issues/12503Template Haskell regression: GHC erroneously thinks a type variable is also a...2019-07-07T18:26:20ZRyan ScottTemplate Haskell regression: GHC erroneously thinks a type variable is also a kindThe following program compiles without issue on GHC 7.6.3 through GHC 7.10.3, but fails to compile on GHC 8.0.1 and GHC HEAD. (I added a CPP guard simply because the `DataD` constructor changed between 7.10 and 8.0.)
```hs
{-# LANGUAGE ...The following program compiles without issue on GHC 7.6.3 through GHC 7.10.3, but fails to compile on GHC 8.0.1 and GHC HEAD. (I added a CPP guard simply because the `DataD` constructor changed between 7.10 and 8.0.)
```hs
{-# LANGUAGE CPP #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE TemplateHaskell #-}
{-# OPTIONS_GHC -ddump-splices #-}
module Regression where
import Language.Haskell.TH
data T k
class C a
$(do TyConI (DataD [] tName [ KindedTV kName kKind]
#if __GLASGOW_HASKELL__ >= 800
_
#endif
_ _) <- reify ''T
d <- instanceD (cxt []) (conT ''C `appT` (conT tName `appT` sigT (varT kName) kKind)) []
return [d])
```
```
$ /opt/ghc/8.0.1/bin/ghc Regression.hs
[1 of 1] Compiling Regression ( Regression.hs, Regression.o )
Regression.hs:(13,3)-(19,15): Splicing declarations
do { TyConI (DataD []
tName_a2RT
[KindedTV kName_a2RU kKind_a2RV]
_
_
_) <- reify ''T;
d_a31Y <- instanceD
(cxt [])
(conT ''C
`appT` (conT tName_a2RT `appT` sigT (varT kName_a2RU) kKind_a2RV))
[];
return [d_a31Y] }
======>
instance C (T (k_avB :: k_avC))
Regression.hs:13:3: error:
Variable ‘k_avB’ used as both a kind and a type
Did you intend to use TypeInType?
```
Somewhat confusingly, you can use `instance C (T (k_avB :: k_avC))` on its own, and it will compile without issue. Also, quoting it doesn't seem to trip up this bug, as this also compiles without issue:
```hs
{-# LANGUAGE CPP #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE TemplateHaskell #-}
{-# OPTIONS_GHC -ddump-splices #-}
module WorksSomehow where
import Language.Haskell.TH
data T k
class C a
$([d| instance C (T k) |])
```
The original program has several workarounds:
1. Turn off `PolyKinds` (OK, this isn't a very good workaround...)
1. Add an explicit kind signature to `T`, e.g., `data T (k :: k1)`
1. Change the type variable of `T` to some other letter, e.g., `data T p` or `data T k1`
Given that (3) is a successful workaround, I strongly suspect that GHC is confusing the type variable `k` (which gets `ddump-splice`d as `k_avB`) with the kind variable `k` (which gets `ddump-splice`d as `k_avC`) due to their common prefix `k`.
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | ---------------- |
| Version | 8.0.1 |
| Type | Bug |
| TypeOfFailure | OtherFailure |
| Priority | high |
| Resolution | Unresolved |
| Component | Template Haskell |
| Test case | |
| Differential revisions | |
| BlockedBy | |
| Related | |
| Blocking | |
| CC | goldfire |
| Operating system | |
| Architecture | |
</details>
<!-- {"blocked_by":[],"summary":"Template Haskell regression: GHC erroneously thinks a type variable is also a kind","status":"New","operating_system":"","component":"Template Haskell","related":[],"milestone":"","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"8.0.1","keywords":["TypeInType"],"differentials":[],"test_case":"","architecture":"","cc":["goldfire"],"type":"Bug","description":"The following program compiles without issue on GHC 7.6.3 through GHC 7.10.3, but fails to compile on GHC 8.0.1 and GHC HEAD. (I added a CPP guard simply because the `DataD` constructor changed between 7.10 and 8.0.)\r\n\r\n{{{#!hs\r\n{-# LANGUAGE CPP #-}\r\n{-# LANGUAGE KindSignatures #-}\r\n{-# LANGUAGE PolyKinds #-}\r\n{-# LANGUAGE TemplateHaskell #-}\r\n{-# OPTIONS_GHC -ddump-splices #-}\r\nmodule Regression where\r\n\r\nimport Language.Haskell.TH\r\n\r\ndata T k\r\nclass C a\r\n\r\n$(do TyConI (DataD [] tName [ KindedTV kName kKind]\r\n#if __GLASGOW_HASKELL__ >= 800\r\n _\r\n#endif\r\n _ _) <- reify ''T\r\n d <- instanceD (cxt []) (conT ''C `appT` (conT tName `appT` sigT (varT kName) kKind)) []\r\n return [d])\r\n}}}\r\n\r\n{{{\r\n$ /opt/ghc/8.0.1/bin/ghc Regression.hs \r\n[1 of 1] Compiling Regression ( Regression.hs, Regression.o )\r\nRegression.hs:(13,3)-(19,15): Splicing declarations\r\n do { TyConI (DataD []\r\n tName_a2RT\r\n [KindedTV kName_a2RU kKind_a2RV]\r\n _\r\n _\r\n _) <- reify ''T;\r\n d_a31Y <- instanceD\r\n (cxt [])\r\n (conT ''C\r\n `appT` (conT tName_a2RT `appT` sigT (varT kName_a2RU) kKind_a2RV))\r\n [];\r\n return [d_a31Y] }\r\n ======>\r\n instance C (T (k_avB :: k_avC))\r\n\r\nRegression.hs:13:3: error:\r\n Variable ‘k_avB’ used as both a kind and a type\r\n Did you intend to use TypeInType?\r\n}}}\r\n\r\nSomewhat confusingly, you can use `instance C (T (k_avB :: k_avC))` on its own, and it will compile without issue. Also, quoting it doesn't seem to trip up this bug, as this also compiles without issue:\r\n\r\n{{{#!hs\r\n{-# LANGUAGE CPP #-}\r\n{-# LANGUAGE KindSignatures #-}\r\n{-# LANGUAGE PolyKinds #-}\r\n{-# LANGUAGE TemplateHaskell #-}\r\n{-# OPTIONS_GHC -ddump-splices #-}\r\nmodule WorksSomehow where\r\n\r\nimport Language.Haskell.TH\r\n\r\ndata T k\r\nclass C a\r\n\r\n$([d| instance C (T k) |])\r\n}}}\r\n\r\nThe original program has several workarounds:\r\n\r\n1. Turn off `PolyKinds` (OK, this isn't a very good workaround...)\r\n2. Add an explicit kind signature to `T`, e.g., `data T (k :: k1)`\r\n3. Change the type variable of `T` to some other letter, e.g., `data T p` or `data T k1`\r\n\r\nGiven that (3) is a successful workaround, I strongly suspect that GHC is confusing the type variable `k` (which gets `ddump-splice`d as `k_avB`) with the kind variable `k` (which gets `ddump-splice`d as `k_avC`) due to their common prefix `k`.","type_of_failure":"OtherFailure","blocking":[]} -->8.2.1Richard Eisenbergrae@richarde.devRichard Eisenbergrae@richarde.devhttps://gitlab.haskell.org/ghc/ghc/-/issues/12534GHC 8.0 accepts recursive kind signature that GHC 7.10 rejects2019-07-07T18:26:11ZRyan ScottGHC 8.0 accepts recursive kind signature that GHC 7.10 rejectsGHC 7.10 rejects this datatype:
```hs
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE PolyKinds #-}
module Bug where
data T (a :: a)
```
```
$ /opt/ghc/7.10.3/bin/ghc Bug.hs
[1 of 1] Compiling Bug ( Bug.hs, Bug.o )
Bug.hs:5...GHC 7.10 rejects this datatype:
```hs
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE PolyKinds #-}
module Bug where
data T (a :: a)
```
```
$ /opt/ghc/7.10.3/bin/ghc Bug.hs
[1 of 1] Compiling Bug ( Bug.hs, Bug.o )
Bug.hs:5:1:
Kind variable also used as type variable: ‘a’
In the data type declaration for ‘T’
```
But GHC 8.0 accepts the above code! It appears that GHC implicitly freshens the kind-level `a` so as to have a different name, since the following modification to `T`:
```hs
data T a (a :: a)
```
Results in this error:
```
$ /opt/ghc/8.0.1/bin/ghc Bug.hs
[1 of 1] Compiling Bug ( Bug.hs, Bug.o )
Bug.hs:5:8: error:
Conflicting definitions for ‘a’
Bound at: Bug.hs:5:8
Bug.hs:5:11
Bug.hs:5:16: error:
Type variable ‘a’ used in a kind.
Did you mean to use TypeInType?
the data type declaration for ‘T’
```
But with this modification:
```hs
data T (a :: a) a
```
You won't get an error message about `a` being used as both a kind and type:
```
$ /opt/ghc/8.0.1/bin/ghc Bug.hs
[1 of 1] Compiling Bug ( Bug.hs, Bug.o )
Bug.hs:5:9: error:
Conflicting definitions for ‘a’
Bound at: Bug.hs:5:9
Bug.hs:5:17
```
To make things even more confusing, this behavior doesn't seem to carry over to typeclass instances. For example: GHC 8.0 will (rightfully) reject this code:
```hs
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE PolyKinds #-}
module Bug where
data T (a :: a)
class C x
instance C (T (a :: a))
```
```
$ /opt/ghc/8.0.1/bin/ghc Bug.hs
[1 of 1] Compiling Bug ( Bug.hs, Bug.o )
Bug.hs:8:16: error:
Variable ‘a’ used as both a kind and a type
Did you intend to use TypeInType?
```
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | ----------------------- |
| Version | 8.0.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":"GHC 8.0 accepts recursive kind signature that GHC 7.10 rejects","status":"New","operating_system":"","component":"Compiler (Type checker)","related":[],"milestone":"","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"8.0.1","keywords":["TypeInType"],"differentials":[],"test_case":"","architecture":"","cc":[""],"type":"Bug","description":"GHC 7.10 rejects this datatype:\r\n\r\n{{{#!hs\r\n{-# LANGUAGE KindSignatures #-}\r\n{-# LANGUAGE PolyKinds #-}\r\nmodule Bug where\r\n\r\ndata T (a :: a)\r\n}}}\r\n\r\n{{{\r\n$ /opt/ghc/7.10.3/bin/ghc Bug.hs\r\n[1 of 1] Compiling Bug ( Bug.hs, Bug.o )\r\n\r\nBug.hs:5:1:\r\n Kind variable also used as type variable: ‘a’\r\n In the data type declaration for ‘T’\r\n}}}\r\n\r\nBut GHC 8.0 accepts the above code! It appears that GHC implicitly freshens the kind-level `a` so as to have a different name, since the following modification to `T`:\r\n\r\n{{{#!hs\r\ndata T a (a :: a)\r\n}}}\r\n\r\nResults in this error:\r\n\r\n{{{\r\n$ /opt/ghc/8.0.1/bin/ghc Bug.hs\r\n[1 of 1] Compiling Bug ( Bug.hs, Bug.o )\r\n\r\nBug.hs:5:8: error:\r\n Conflicting definitions for ‘a’\r\n Bound at: Bug.hs:5:8\r\n Bug.hs:5:11\r\n\r\nBug.hs:5:16: error:\r\n Type variable ‘a’ used in a kind.\r\n Did you mean to use TypeInType?\r\n the data type declaration for ‘T’\r\n}}}\r\n\r\nBut with this modification:\r\n\r\n{{{#!hs\r\ndata T (a :: a) a\r\n}}}\r\n\r\nYou won't get an error message about `a` being used as both a kind and type:\r\n\r\n{{{\r\n$ /opt/ghc/8.0.1/bin/ghc Bug.hs\r\n[1 of 1] Compiling Bug ( Bug.hs, Bug.o )\r\n\r\nBug.hs:5:9: error:\r\n Conflicting definitions for ‘a’\r\n Bound at: Bug.hs:5:9\r\n Bug.hs:5:17\r\n}}}\r\n\r\nTo make things even more confusing, this behavior doesn't seem to carry over to typeclass instances. For example: GHC 8.0 will (rightfully) reject this code:\r\n\r\n{{{#!hs\r\n{-# LANGUAGE KindSignatures #-}\r\n{-# LANGUAGE PolyKinds #-}\r\nmodule Bug where\r\n\r\ndata T (a :: a)\r\n\r\nclass C x\r\ninstance C (T (a :: a))\r\n}}}\r\n\r\n{{{\r\n$ /opt/ghc/8.0.1/bin/ghc Bug.hs\r\n[1 of 1] Compiling Bug ( Bug.hs, Bug.o )\r\n\r\nBug.hs:8:16: error:\r\n Variable ‘a’ used as both a kind and a type\r\n Did you intend to use TypeInType?\r\n}}}","type_of_failure":"OtherFailure","blocking":[]} -->Richard Eisenbergrae@richarde.devRichard Eisenbergrae@richarde.devhttps://gitlab.haskell.org/ghc/ghc/-/issues/12553Reference kind in a type instance declaration defined in another instance dec...2019-07-07T18:26:08ZIcelandjackReference kind in a type instance declaration defined in another instance declarationOld code:
```hs
data Full :: Type -> Type
data AST :: (Type -> Type) -> (Type -> Type)
-- ASTF :: (Type -> Type) -> (Type -> Type)
type ASTF dom a = AST dom (Full a)
class Syntactic a where
type Domain a :: Type -> Type
type In...Old code:
```hs
data Full :: Type -> Type
data AST :: (Type -> Type) -> (Type -> Type)
-- ASTF :: (Type -> Type) -> (Type -> Type)
type ASTF dom a = AST dom (Full a)
class Syntactic a where
type Domain a :: Type -> Type
type Internal a :: Type
desugar :: a -> ASTF (Domain a) (Internal a)
sugar :: ASTF (Domain a) (Internal a) -> a
```
----
New code with richer kinds
```hs
data Sig a = Full a | a :-> Sig a
data AST :: (Sig a -> Type) -> (Sig a -> Type)
data Sig a = Full a | a :-> Sig a
-- ASTF :: (Sig a -> Type) -> (a -> Type)
type ASTF dom a = AST dom (Full a)
class Syntactic a where
type Domain a :: Sig Type -> Type
type Internal a :: Type
desugar :: a -> ASTF (Domain a) (Internal a)
sugar :: ASTF (Domain a) (Internal a) -> a
```
As the type of `ASTF` hints at it could accept arguments of kind `Sig a -> Type` and `a`. I would like to reference the variable `a` from the kind of `Domain` in the kind of `Internal`, but this fails:
```hs
-- • Kind variable ‘u’ is implicitly bound in datatype
-- ‘Internal’, but does not appear as the kind of any
-- of its type variables. Perhaps you meant
-- to bind it (with TypeInType) explicitly somewhere?
-- Type variables with inferred kinds: a
-- • In the class declaration for ‘Syntactic’
class Syntactic a where
type Domain a :: Sig u -> Type
type Internal a :: u
desugar :: a -> ASTF (Domain a) (Internal a)
sugar :: ASTF (Domain a) (Internal a) -> a
```
----
Should the `u` in the kind of `Domain a` be quantified over (which makes this compile)?
```hs
type Domain a :: forall k. Sig k -> Type
```
- \*Edit\*\*: This doesn't work.https://gitlab.haskell.org/ghc/ghc/-/issues/12564Type family in type pattern kind2023-08-19T13:41:26ZVladislav ZavialovType family in type pattern kindI want to write a type family that is analogous to `!!` for lists but requires the index to be no bigger than the length of the list. Usually, in dependently typed languages finite sets are used for this purpose, here's an attempt to do ...I want to write a type family that is analogous to `!!` for lists but requires the index to be no bigger than the length of the list. Usually, in dependently typed languages finite sets are used for this purpose, here's an attempt to do so in Haskell:
```haskell
{-# LANGUAGE TypeInType, TypeFamilies, GADTs, TypeOperators #-}
import Data.Kind
data N = Z | S N
type family Len (xs :: [a]) :: N where
Len '[] = Z
Len (_ ': xs) = S (Len xs)
data Fin :: N -> Type where
FZ :: Fin (S n)
FS :: Fin n -> Fin (S n)
type family At (xs :: [a]) (i :: Fin (Len xs)) :: a where
At (x ': _) FZ = x
At (_ ': xs) (FS i) = At xs i
```
It fails to compile with this error:
```
FinAt.hs:16:3: error:
• Illegal type synonym family application in instance: 'FZ
• In the equations for closed type family ‘At’
In the type family declaration for ‘At’
```
That's because the kind of the `FZ` pattern (first clause of `At`) has the kind `Fin (Len xs)` and the application of `Len` cannot reduce completely. `checkValidTypePat` then disallows the pattern, as it contains a type family application.
I tried to suppress `checkValidTypePat` and the definition of `At` has compiled; however, it's of little use, since `At` doesn't reduce:
```haskell
x :: At '[Bool] FZ
x = True
```
results in
```
FinAt.hs:20:5: error:
• Couldn't match expected type ‘At
* ((':) * Bool ('[] *)) ('FZ 'Z)’
with actual type ‘Bool’
• In the expression: True
In an equation for ‘x’: x = True
```
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | ----------------------- |
| Version | 8.0.1 |
| Type | Bug |
| TypeOfFailure | OtherFailure |
| Priority | normal |
| Resolution | Unresolved |
| Component | Compiler (Type checker) |
| Test case | |
| Differential revisions | |
| BlockedBy | |
| Related | |
| Blocking | |
| CC | goldfire, int-index |
| Operating system | |
| Architecture | |
</details>
<!-- {"blocked_by":[],"summary":"Type family in type pattern kind","status":"New","operating_system":"","component":"Compiler (Type checker)","related":[],"milestone":"8.2.1","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"8.0.1","keywords":["TypeFamilies","TypeInType,"],"differentials":[],"test_case":"","architecture":"","cc":["goldfire","int-index"],"type":"Bug","description":"I want to write a type family that is analogous to `!!` for lists but requires the index to be no bigger than the length of the list. Usually, in dependently typed languages finite sets are used for this purpose, here's an attempt to do so in Haskell:\r\n\r\n{{{#!haskell\r\n{-# LANGUAGE TypeInType, TypeFamilies, GADTs, TypeOperators #-}\r\n\r\nimport Data.Kind\r\n\r\ndata N = Z | S N\r\n\r\ntype family Len (xs :: [a]) :: N where\r\n Len '[] = Z\r\n Len (_ ': xs) = S (Len xs)\r\n\r\ndata Fin :: N -> Type where\r\n FZ :: Fin (S n)\r\n FS :: Fin n -> Fin (S n)\r\n\r\ntype family At (xs :: [a]) (i :: Fin (Len xs)) :: a where\r\n At (x ': _) FZ = x\r\n At (_ ': xs) (FS i) = At xs i\r\n}}}\r\n\r\nIt fails to compile with this error:\r\n\r\n{{{\r\nFinAt.hs:16:3: error:\r\n • Illegal type synonym family application in instance: 'FZ\r\n • In the equations for closed type family ‘At’\r\n In the type family declaration for ‘At’\r\n}}}\r\n\r\nThat's because the kind of the `FZ` pattern (first clause of `At`) has the kind `Fin (Len xs)` and the application of `Len` cannot reduce completely. `checkValidTypePat` then disallows the pattern, as it contains a type family application.\r\n\r\nI tried to suppress `checkValidTypePat` and the definition of `At` has compiled; however, it's of little use, since `At` doesn't reduce:\r\n\r\n{{{#!haskell\r\nx :: At '[Bool] FZ\r\nx = True\r\n}}}\r\n\r\nresults in\r\n\r\n{{{\r\nFinAt.hs:20:5: error:\r\n • Couldn't match expected type ‘At\r\n * ((':) * Bool ('[] *)) ('FZ 'Z)’\r\n with actual type ‘Bool’\r\n • In the expression: True\r\n In an equation for ‘x’: x = True\r\n}}}","type_of_failure":"OtherFailure","blocking":[]} -->Richard Eisenbergrae@richarde.devRichard Eisenbergrae@richarde.devhttps://gitlab.haskell.org/ghc/ghc/-/issues/12612Allow kinds of associated types to depend on earlier associated types2023-12-22T08:53:22ZdavemenendezAllow kinds of associated types to depend on earlier associated typesGHC rejects the following code:
```hs
class C t where
type K t :: Type
type T t :: K t -> Type
m :: t -> T t a
```
with this error message
```
• Type constructor ‘K’ cannot be used here
(it is defined and used...GHC rejects the following code:
```hs
class C t where
type K t :: Type
type T t :: K t -> Type
m :: t -> T t a
```
with this error message
```
• Type constructor ‘K’ cannot be used here
(it is defined and used in the same recursive group)
• In the kind ‘K t -> Type’
```
See [e-mail discussion](https://mail.haskell.org/pipermail/glasgow-haskell-users/2016-September/026402.html). This is connected to #12088, at least as far as defining instances of C.
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | ------------ |
| Version | 8.0.1 |
| 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":"Allow kinds of associated types to depend on earlier associated types","status":"New","operating_system":"","component":"Compiler","related":[],"milestone":"","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"8.0.1","keywords":[],"differentials":[],"test_case":"","architecture":"","cc":[""],"type":"Bug","description":"GHC rejects the following code:\r\n\r\n{{{#!hs\r\nclass C t where\r\n type K t :: Type\r\n type T t :: K t -> Type\r\n\r\n m :: t -> T t a\r\n}}}\r\n\r\nwith this error message\r\n\r\n{{{\r\n • Type constructor ‘K’ cannot be used here\r\n (it is defined and used in the same recursive group)\r\n • In the kind ‘K t -> Type’\r\n}}}\r\n\r\nSee [https://mail.haskell.org/pipermail/glasgow-haskell-users/2016-September/026402.html e-mail discussion]. This is connected to #12088, at least as far as defining instances of C.","type_of_failure":"OtherFailure","blocking":[]} -->https://gitlab.haskell.org/ghc/ghc/-/issues/12742Instantiation of invisible type family arguments is too eager2019-07-07T18:25:20ZRichard Eisenbergrae@richarde.devInstantiation of invisible type family arguments is too eagerThis module looks, to me, like it should be accepted:
```
{-# LANGUAGE TypeInType, RankNTypes, TypeFamilies #-}
module Bug where
import Data.Kind
type family F :: forall k2. (k1, k2)
data T :: (forall k2. (Bool, k2)) -> Type
type S...This module looks, to me, like it should be accepted:
```
{-# LANGUAGE TypeInType, RankNTypes, TypeFamilies #-}
module Bug where
import Data.Kind
type family F :: forall k2. (k1, k2)
data T :: (forall k2. (Bool, k2)) -> Type
type S = T F
```
But it's not. The problem is that `TcHsType.handle_tyfams` eagerly instantiates *all* invisible arguments to a type family at every occurrence. Instead, it should instantiate only those that are counted in the TF's arity -- that is, those "before the colon".
Will fix.
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | ------------ |
| Version | 8.0.1 |
| 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":"Instantiation of invisible type family arguments is too eager","status":"New","operating_system":"","component":"Compiler","related":[],"milestone":"","resolution":"Unresolved","owner":{"tag":"OwnedBy","contents":"goldfire"},"version":"8.0.1","keywords":[],"differentials":[],"test_case":"","architecture":"","cc":[""],"type":"Bug","description":"This module looks, to me, like it should be accepted:\r\n\r\n{{{\r\n{-# LANGUAGE TypeInType, RankNTypes, TypeFamilies #-}\r\n\r\nmodule Bug where\r\n\r\nimport Data.Kind\r\n\r\ntype family F :: forall k2. (k1, k2)\r\n\r\ndata T :: (forall k2. (Bool, k2)) -> Type\r\n\r\ntype S = T F\r\n}}}\r\n\r\nBut it's not. The problem is that `TcHsType.handle_tyfams` eagerly instantiates ''all'' invisible arguments to a type family at every occurrence. Instead, it should instantiate only those that are counted in the TF's arity -- that is, those \"before the colon\".\r\n\r\nWill fix.","type_of_failure":"OtherFailure","blocking":[]} -->Richard Eisenbergrae@richarde.devRichard Eisenbergrae@richarde.devhttps://gitlab.haskell.org/ghc/ghc/-/issues/12766Allow runtime-representation polymorphic data families2019-07-07T18:25:14ZIcelandjackAllow runtime-representation polymorphic data familiesThis is an offshoot of #12369 (‘data families shouldn't be required to have return kind \*, data instances should’), allowing family declarations something like:
```hs
data family Array a :: TYPE rep
```This is an offshoot of #12369 (‘data families shouldn't be required to have return kind \*, data instances should’), allowing family declarations something like:
```hs
data family Array a :: TYPE rep
```8.10.1https://gitlab.haskell.org/ghc/ghc/-/issues/12919Equality not used for substitution2019-07-07T18:24:38ZVladislav ZavialovEquality not used for substitutionThis code
```hs
{-# LANGUAGE TypeInType, TypeFamilies, GADTs, ConstraintKinds #-}
module T12919 where
import Data.Kind
data N = Z
data V :: N -> Type where
VZ :: V Z
type family VC (n :: N) :: Type where
VC Z = Type
type famil...This code
```hs
{-# LANGUAGE TypeInType, TypeFamilies, GADTs, ConstraintKinds #-}
module T12919 where
import Data.Kind
data N = Z
data V :: N -> Type where
VZ :: V Z
type family VC (n :: N) :: Type where
VC Z = Type
type family VF (xs :: V n) (f :: VC n) :: Type where
VF VZ f = f
data Dict c where
Dict :: c => Dict c
prop :: xs ~ VZ => Dict (VF xs f ~ f)
prop = Dict
```
fails with this error:
```
T12919.hs:22:8: error:
• Couldn't match type ‘f’ with ‘VF 'VZ f’
arising from a use of ‘Dict’
‘f’ is a rigid type variable bound by
the type signature for:
prop :: forall (xs :: V 'Z) f. xs ~ 'VZ => Dict VF xs f ~ f
at T12919.hs:21:9
• In the expression: Dict
In an equation for ‘prop’: prop = Dict
• Relevant bindings include
prop :: Dict VF xs f ~ f (bound at T12919.hs:22:1)
```
However, if I substitute `xs` with `VZ` (by hand) in the type of `prop`, it compiles. Can be reproduced with GHC 8.0.1 but not HEAD.8.4.1Richard Eisenbergrae@richarde.devRichard Eisenbergrae@richarde.devhttps://gitlab.haskell.org/ghc/ghc/-/issues/12922Kind classes compile with PolyKinds2019-07-07T18:24:37ZMatthías Páll GissurarsonKind classes compile with PolyKindsI was asking around on \#haskell to better understand the new language extension, -XTypeInType, and how it is different from -XPolyKinds.
To study it, I was working with the following small example:
```
{-# LANGUAGE TypeFamilies, TypeO...I was asking around on \#haskell to better understand the new language extension, -XTypeInType, and how it is different from -XPolyKinds.
To study it, I was working with the following small example:
```
{-# LANGUAGE TypeFamilies, TypeOperators, DataKinds, PolyKinds #-}
module Main where
-- Define a Type for the natural numbers, zero and a successor
data Nat = Z | S Nat
class Addable k where
type (a :: k) + (b :: k) :: k
instance Addable Nat where
type (Z + a) = a
type (S a) + b = S (a + b)
main :: IO ()
main = putStrLn "Shouldn't this need TypeInType?"
```
(for more context, see https://gist.github.com/Tritlo/ce5510e80935ac398a33934ee47c7930)
Since according to a responder on \#haskell, the ability to have kind classes required TypeInType, and should not work with PolyKinds.
As the documentation mentions that there could be leakage between PolyKinds and TypeInType and to report such leaks, I felt that I should report it.Richard Eisenbergrae@richarde.devRichard Eisenbergrae@richarde.devhttps://gitlab.haskell.org/ghc/ghc/-/issues/12931tc_infer_args does not set in-scope set correctly2023-07-16T13:20:59Zjohnleotc_infer_args does not set in-scope set correctlyAs noted in #12785\##12931, `TcHsType.tc_infer_args` does not set its in-scope set correctly, which means the call to `TcMType.new_meta_tv_x` will fail if `substTyUnchecked` is replaced by `substTy` in the line
```
kind = substTyUnche...As noted in #12785\##12931, `TcHsType.tc_infer_args` does not set its in-scope set correctly, which means the call to `TcMType.new_meta_tv_x` will fail if `substTyUnchecked` is replaced by `substTy` in the line
```
kind = substTyUnchecked subst (tyVarKind tv)
```
This is the only known caller of `new_meta_tv_x` to not set the in-scope set, now that #12549 has been fixed. Once this bug is fixed, change `substTyUnchecked` back to `substTy` in the line noted above.
Note that other calls to `substTyUnchecked` that need to be converted to `substTy` are covered in the general ticket #11371.
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | ------------ |
| Version | 8.0.1 |
| 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":"tc_infer_args does not set in-scope set correctly","status":"New","operating_system":"","component":"Compiler","related":[],"milestone":"","resolution":"Unresolved","owner":{"tag":"OwnedBy","contents":"goldfire"},"version":"8.0.1","keywords":[],"differentials":[],"test_case":"","architecture":"","cc":[""],"type":"Bug","description":"As noted in https://ghc.haskell.org/trac/ghc/ticket/12785#comment:6, `TcHsType.tc_infer_args` does not set its in-scope set correctly, which means the call to `TcMType.new_meta_tv_x` will fail if `substTyUnchecked` is replaced by `substTy` in the line\r\n{{{\r\nkind = substTyUnchecked subst (tyVarKind tv)\r\n}}}\r\n\r\nThis is the only known caller of `new_meta_tv_x` to not set the in-scope set, now that #12549 has been fixed. Once this bug is fixed, change `substTyUnchecked` back to `substTy` in the line noted above.\r\n\r\nNote that other calls to `substTyUnchecked` that need to be converted to `substTy` are covered in the general ticket #11371.","type_of_failure":"OtherFailure","blocking":[]} -->Richard Eisenbergrae@richarde.devRichard Eisenbergrae@richarde.devhttps://gitlab.haskell.org/ghc/ghc/-/issues/12933Wrong class instance selection with Data.Kind.Type2022-08-04T22:32:56ZjulmWrong class instance selection with Data.Kind.TypeIf you consider the following code:
```hs
{-# LANGUAGE GADTs #-}
{-# LANGUAGE FlexibleInstances #-}
module Bug where
import GHC.Exts (Constraint)
import Data.Kind
-- | Partial singleton for a kind type.
data SKind k where
SKiTy :: S...If you consider the following code:
```hs
{-# LANGUAGE GADTs #-}
{-# LANGUAGE FlexibleInstances #-}
module Bug where
import GHC.Exts (Constraint)
import Data.Kind
-- | Partial singleton for a kind type.
data SKind k where
SKiTy :: SKind Type
SKiCo :: SKind Constraint
instance Show (SKind k) where
show SKiTy = "*"
show SKiCo = "Constraint"
class IKind k where
kind :: SKind k
instance IKind Constraint where
kind = SKiCo
```
Then, the main below will compile even though there is no (IKind Type) instance, and it will print "Constraint" two times,
instead of an expected "Constraint" then "\*":
```hs
main :: IO ()
main = do
print (kind::SKind Constraint)
print (kind::SKind Type)
```
And, the main below will print "\*" two times,
instead of an expected "\*" then "Constraint":
```hs
instance IKind Type where
kind = SKiTy
main :: IO ()
main = do
print (kind::SKind Type)
print (kind::SKind Constraint)
```
This can be worked around by replacing Type with a new data type Ty to select the right class instances, using two type families Ty_of_Type and Type_of_Ty, as done in the attached Workaround.hs.
Sorry if this bug has already been fixed in HEAD: I was unable to find neither a bug report similar, nor a Linux x86_64 build of HEAD for me to test.
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | ------------ |
| Version | 8.0.1 |
| Type | Bug |
| TypeOfFailure | OtherFailure |
| Priority | highest |
| Resolution | Unresolved |
| Component | Compiler |
| Test case | |
| Differential revisions | |
| BlockedBy | |
| Related | |
| Blocking | |
| CC | |
| Operating system | |
| Architecture | |
</details>
<!-- {"blocked_by":[],"summary":"Wrong class instance selection with Data.Kind.Type","status":"New","operating_system":"","component":"Compiler","related":[],"milestone":"","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"8.0.1","keywords":["TypeInType"],"differentials":[],"test_case":"","architecture":"","cc":[""],"type":"Bug","description":"If you consider the following code:\r\n{{{#!hs\r\n{-# LANGUAGE GADTs #-}\r\n{-# LANGUAGE FlexibleInstances #-}\r\nmodule Bug where\r\n\r\nimport GHC.Exts (Constraint)\r\nimport Data.Kind\r\n\r\n-- | Partial singleton for a kind type.\r\ndata SKind k where\r\n SKiTy :: SKind Type\r\n SKiCo :: SKind Constraint\r\n\r\ninstance Show (SKind k) where\r\n show SKiTy = \"*\"\r\n show SKiCo = \"Constraint\"\r\n\r\nclass IKind k where\r\n kind :: SKind k\r\ninstance IKind Constraint where\r\n kind = SKiCo\r\n}}}\r\n\r\nThen, the main below will compile even though there is no (IKind Type) instance, and it will print \"Constraint\" two times,\r\ninstead of an expected \"Constraint\" then \"*\":\r\n{{{#!hs\r\nmain :: IO ()\r\nmain = do\r\n print (kind::SKind Constraint)\r\n print (kind::SKind Type)\r\n}}}\r\n\r\nAnd, the main below will print \"*\" two times,\r\ninstead of an expected \"*\" then \"Constraint\":\r\n{{{#!hs\r\ninstance IKind Type where\r\n kind = SKiTy\r\n\r\nmain :: IO ()\r\nmain = do\r\n print (kind::SKind Type)\r\n print (kind::SKind Constraint)\r\n}}}\r\n\r\nThis can be worked around by replacing Type with a new data type Ty to select the right class instances, using two type families Ty_of_Type and Type_of_Ty, as done in the attached Workaround.hs.\r\n\r\nSorry if this bug has already been fixed in HEAD: I was unable to find neither a bug report similar, nor a Linux x86_64 build of HEAD for me to test.","type_of_failure":"OtherFailure","blocking":[]} -->https://gitlab.haskell.org/ghc/ghc/-/issues/12938Polykinded associated type family rejected on false pretenses2019-07-07T18:24:33ZRichard Eisenbergrae@richarde.devPolykinded associated type family rejected on false pretensesIf I say
```
class HasRep a where
type Rep a :: TYPE r
```
I get
```
• Kind variable ‘r’ is implicitly bound in datatype
‘Rep’, but does not appear as the kind of any
of its type variables. Perhaps you meant
to...If I say
```
class HasRep a where
type Rep a :: TYPE r
```
I get
```
• Kind variable ‘r’ is implicitly bound in datatype
‘Rep’, but does not appear as the kind of any
of its type variables. Perhaps you meant
to bind it (with TypeInType) explicitly somewhere?
Type variables with inferred kinds: a
• In the class declaration for ‘HasRep’
```
This definition should be accepted, though, as `r` is just an invisible parameter to the associated type family. (I don't know how *useful* this is, but it's not bogus.)
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | ------------ |
| Version | 8.0.1 |
| 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":"Polykinded associated type family rejected on false pretenses","status":"New","operating_system":"","component":"Compiler","related":[],"milestone":"8.2.1","resolution":"Unresolved","owner":{"tag":"OwnedBy","contents":"goldfire"},"version":"8.0.1","keywords":["TypeInType"],"differentials":[],"test_case":"","architecture":"","cc":[""],"type":"Bug","description":"If I say\r\n\r\n{{{\r\nclass HasRep a where\r\n type Rep a :: TYPE r\r\n}}}\r\n\r\nI get\r\n\r\n{{{\r\n • Kind variable ‘r’ is implicitly bound in datatype\r\n ‘Rep’, but does not appear as the kind of any\r\n of its type variables. Perhaps you meant\r\n to bind it (with TypeInType) explicitly somewhere?\r\n Type variables with inferred kinds: a\r\n • In the class declaration for ‘HasRep’\r\n}}}\r\n\r\nThis definition should be accepted, though, as `r` is just an invisible parameter to the associated type family. (I don't know how ''useful'' this is, but it's not bogus.)","type_of_failure":"OtherFailure","blocking":[]} -->8.6.1Richard Eisenbergrae@richarde.devRichard Eisenbergrae@richarde.devhttps://gitlab.haskell.org/ghc/ghc/-/issues/13333Typeable regression in GHC HEAD2019-07-07T18:22:24ZRyan ScottTypeable regression in GHC HEADI recently wrote some code while exploring a fix for #13327 that heavily uses poly-kinded `Typeable`. This compiles without issue on GHC 8.0.1 and 8.0.2:
```hs
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGU...I recently wrote some code while exploring a fix for #13327 that heavily uses poly-kinded `Typeable`. This compiles without issue on GHC 8.0.1 and 8.0.2:
```hs
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeInType #-}
{-# LANGUAGE TypeOperators #-}
module DataCast where
import Data.Data
import GHC.Exts (Constraint)
data T (phantom :: k) = T
data D (p :: k -> Constraint) (x :: j) where
D :: forall (p :: k -> Constraint) (x :: k). p x => D p x
class Possibly p x where
possibly :: proxy1 p -> proxy2 x -> Maybe (D p x)
dataCast1T :: forall k c t (phantom :: k).
(Typeable k, Typeable t, Typeable phantom, Possibly Data phantom)
=> (forall d. Data d => c (t d))
-> Maybe (c (T phantom))
dataCast1T f = case possibly (Proxy :: Proxy Data) (Proxy :: Proxy phantom) of
Nothing -> Nothing
Just D -> gcast1 f
```
But on GHC HEAD, it barfs this error:
```
$ ~/Software/ghc2/inplace/bin/ghc-stage2 --interactive Bug.hs
GHCi, version 8.1.20170223: http://www.haskell.org/ghc/ :? for help
Loaded GHCi configuration from /home/rgscott/.ghci
[1 of 1] Compiling DataCast ( Bug.hs, interpreted )
Bug.hs:28:29: error:
• Could not deduce (Typeable T) arising from a use of ‘gcast1’
GHC can't yet do polykinded Typeable (T :: * -> *)
from the context: (Typeable k, Typeable t, Typeable phantom,
Possibly Data phantom)
bound by the type signature for:
dataCast1T :: (Typeable k, Typeable t, Typeable phantom,
Possibly Data phantom) =>
(forall d. Data d => c (t d)) -> Maybe (c (T phantom))
at Bug.hs:(22,1)-(25,35)
or from: (k ~ *, (phantom :: k) ~~ (x :: *), Data x)
bound by a pattern with constructor:
D :: forall k (p :: k -> Constraint) (x :: k). p x => D p x,
in a case alternative
at Bug.hs:28:23
• In the expression: gcast1 f
In a case alternative: Just D -> gcast1 f
In the expression:
case possibly (Proxy :: Proxy Data) (Proxy :: Proxy phantom) of
Nothing -> Nothing
Just D -> gcast1 f
|
28 | Just D -> gcast1 f
| ^^^^^^^^
```
That error message itself is hilariously strange, since GHC certainly has the power to do polykinded `Typeable` nowadays.
Marking as high priority since this is a regression—feel free to lower the priority if you disagree.8.2.1Richard Eisenbergrae@richarde.devRichard Eisenbergrae@richarde.devhttps://gitlab.haskell.org/ghc/ghc/-/issues/13337GHC doesn't think a type is of kind *, despite having evidence for it2019-07-07T18:22:23ZRyan ScottGHC doesn't think a type is of kind *, despite having evidence for itThe easiest way to illustrate this bug is this:
```hs
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeFamilies #-}
module Foo where
import Data.Kind (Type)
blah :: forall (a :: k). k ~ Type => a -> a
b...The easiest way to illustrate this bug is this:
```hs
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeFamilies #-}
module Foo where
import Data.Kind (Type)
blah :: forall (a :: k). k ~ Type => a -> a
blah x = x
```
```
$ ghci Foo.hs
GHCi, version 8.0.2: http://www.haskell.org/ghc/ :? for help
Loaded GHCi configuration from /home/rgscott/.ghci
[1 of 1] Compiling Foo ( Foo.hs, interpreted )
Foo.hs:8:43: error:
• Expected a type, but ‘a’ has kind ‘k’
• In the type signature:
blah :: forall (a :: k). k ~ Type => a -> a
```
I find this behavior quite surprising, especially since we have evidence that `k ~ Type` in scope!
If the program above looks too contrived, consider a similar program that uses `Typeable`. I want to write something like this:
```hs
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeInType #-}
{-# LANGUAGE TypeOperators #-}
module Foo where
import Data.Kind (Type)
import Data.Typeable
foo :: forall k (a :: k) proxy. (Typeable k, Typeable a)
=> proxy a -> String
foo _ =
case eqT :: Maybe (k :~: Type) of
Nothing -> "Non-Type kind"
Just Refl ->
case eqT :: Maybe (a :~: Int) of
Nothing -> "Non-Int type"
Just Refl -> "It's an Int!"
```
This exhibits the same problem. Despite the fact that we pattern-matched on a `Refl` of type `k :~: Type`, GHC refuses to consider the possibility that `a :~: Int` is well kinded, even though `(a :: k)`, and we learned from the first `Refl` that `k ~ Type`!
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | ----------------------- |
| Version | 8.0.2 |
| Type | Bug |
| TypeOfFailure | OtherFailure |
| Priority | normal |
| Resolution | Unresolved |
| Component | Compiler (Type checker) |
| Test case | |
| Differential revisions | |
| BlockedBy | |
| Related | |
| Blocking | |
| CC | goldfire |
| Operating system | |
| Architecture | |
</details>
<!-- {"blocked_by":[],"summary":"GHC doesn't think a type is of kind *, despite having evidence for it","status":"New","operating_system":"","component":"Compiler (Type checker)","related":[],"milestone":"","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"8.0.2","keywords":[],"differentials":[],"test_case":"","architecture":"","cc":["goldfire"],"type":"Bug","description":"The easiest way to illustrate this bug is this:\r\n\r\n{{{#!hs\r\n{-# LANGUAGE PolyKinds #-}\r\n{-# LANGUAGE ScopedTypeVariables #-}\r\n{-# LANGUAGE TypeFamilies #-}\r\nmodule Foo where\r\n\r\nimport Data.Kind (Type)\r\n\r\nblah :: forall (a :: k). k ~ Type => a -> a\r\nblah x = x\r\n}}}\r\n\r\n{{{\r\n$ ghci Foo.hs\r\nGHCi, version 8.0.2: http://www.haskell.org/ghc/ :? for help\r\nLoaded GHCi configuration from /home/rgscott/.ghci\r\n[1 of 1] Compiling Foo ( Foo.hs, interpreted )\r\n\r\nFoo.hs:8:43: error:\r\n • Expected a type, but ‘a’ has kind ‘k’\r\n • In the type signature:\r\n blah :: forall (a :: k). k ~ Type => a -> a\r\n}}}\r\n\r\nI find this behavior quite surprising, especially since we have evidence that `k ~ Type` in scope!\r\n\r\nIf the program above looks too contrived, consider a similar program that uses `Typeable`. I want to write something like this:\r\n\r\n{{{#!hs\r\n{-# LANGUAGE RankNTypes #-}\r\n{-# LANGUAGE ScopedTypeVariables #-}\r\n{-# LANGUAGE TypeFamilies #-}\r\n{-# LANGUAGE TypeInType #-}\r\n{-# LANGUAGE TypeOperators #-}\r\nmodule Foo where\r\n\r\nimport Data.Kind (Type)\r\nimport Data.Typeable\r\n\r\nfoo :: forall k (a :: k) proxy. (Typeable k, Typeable a)\r\n => proxy a -> String\r\nfoo _ =\r\n case eqT :: Maybe (k :~: Type) of\r\n Nothing -> \"Non-Type kind\"\r\n Just Refl ->\r\n case eqT :: Maybe (a :~: Int) of\r\n Nothing -> \"Non-Int type\"\r\n Just Refl -> \"It's an Int!\"\r\n}}}\r\n\r\nThis exhibits the same problem. Despite the fact that we pattern-matched on a `Refl` of type `k :~: Type`, GHC refuses to consider the possibility that `a :~: Int` is well kinded, even though `(a :: k)`, and we learned from the first `Refl` that `k ~ Type`!","type_of_failure":"OtherFailure","blocking":[]} -->8.2.1Richard Eisenbergrae@richarde.devRichard Eisenbergrae@richarde.devhttps://gitlab.haskell.org/ghc/ghc/-/issues/13364Remove checkValidTelescope2019-07-07T18:22:16ZRichard Eisenbergrae@richarde.devRemove checkValidTelescopeAll of this new `TypeInType` nonsense has provided a number of ways that we can arrive at ill-scoped kinds. Let's assume we have
```
data SameKind :: k -> k -> Type
```
and then here are three subtly ill-scoped kinds:
```
forall a (b ...All of this new `TypeInType` nonsense has provided a number of ways that we can arrive at ill-scoped kinds. Let's assume we have
```
data SameKind :: k -> k -> Type
```
and then here are three subtly ill-scoped kinds:
```
forall a (b :: a) (c :: Proxy d). SameKind b d
forall a. forall (b :: a). forall (c :: Proxy d). SameKind b d
forall d. forall a (b :: a). SameKind b d
```
Despite the close similarity between these cases, they are all handled separately. See `Note [Bad telescopes]` in !TcValidity for an overview, but these are spread between `tcImplicitTKBndrsX`, `tcExplicitTKBndrsX`, and those functions' calls to `checkValidTelescope`, `checkZonkValidTelescope`, and `checkValidInferredKinds`.
While I am unaware of a concrete bug this all causes, it's a mess.
Better would be to use the existing machinery to prevent skolem-escape: `TcLevel`s and implication constraints. Specifically, it's quite plausible that all this can be avoided by a simple rule: bump the `TcLevel` (and create an implication constraint) for *every* new type variable brought into scope (including implicitly). (Actually, implicit variables have an implicit ordering that GHC is free to decide, so all implicitly bound variables should be brought into scope at once, with just one bump in the `TcLevel`.)
It might all just work! And then we can delete gobs of hairy code. Hooray!
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | ------------ |
| Version | 8.0.1 |
| Type | Task |
| TypeOfFailure | OtherFailure |
| Priority | normal |
| Resolution | Unresolved |
| Component | Compiler |
| Test case | |
| Differential revisions | |
| BlockedBy | |
| Related | |
| Blocking | |
| CC | |
| Operating system | |
| Architecture | |
</details>
<!-- {"blocked_by":[],"summary":"Remove checkValidTelescope","status":"New","operating_system":"","component":"Compiler","related":[],"milestone":"","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"8.0.1","keywords":[],"differentials":[],"test_case":"","architecture":"","cc":[""],"type":"Task","description":"All of this new `TypeInType` nonsense has provided a number of ways that we can arrive at ill-scoped kinds. Let's assume we have\r\n\r\n{{{\r\ndata SameKind :: k -> k -> Type\r\n}}}\r\n\r\nand then here are three subtly ill-scoped kinds:\r\n\r\n{{{\r\nforall a (b :: a) (c :: Proxy d). SameKind b d\r\nforall a. forall (b :: a). forall (c :: Proxy d). SameKind b d\r\nforall d. forall a (b :: a). SameKind b d\r\n}}}\r\n\r\nDespite the close similarity between these cases, they are all handled separately. See `Note [Bad telescopes]` in !TcValidity for an overview, but these are spread between `tcImplicitTKBndrsX`, `tcExplicitTKBndrsX`, and those functions' calls to `checkValidTelescope`, `checkZonkValidTelescope`, and `checkValidInferredKinds`.\r\n\r\nWhile I am unaware of a concrete bug this all causes, it's a mess.\r\n\r\nBetter would be to use the existing machinery to prevent skolem-escape: `TcLevel`s and implication constraints. Specifically, it's quite plausible that all this can be avoided by a simple rule: bump the `TcLevel` (and create an implication constraint) for ''every'' new type variable brought into scope (including implicitly). (Actually, implicit variables have an implicit ordering that GHC is free to decide, so all implicitly bound variables should be brought into scope at once, with just one bump in the `TcLevel`.)\r\n\r\nIt might all just work! And then we can delete gobs of hairy code. Hooray!","type_of_failure":"OtherFailure","blocking":[]} -->8.4.1Richard Eisenbergrae@richarde.devRichard Eisenbergrae@richarde.devhttps://gitlab.haskell.org/ghc/ghc/-/issues/13391PolyKinds is more permissive in GHC 82019-07-07T18:22:06ZEric CrockettPolyKinds is more permissive in GHC 8The docs claim that the definition in section 9.11.10
```
data G (a :: k) where
GInt :: G Int
GMaybe :: G Maybe
```
"requires that `-XTypeInType` be in effect", but this isn't the case.
The following compiles with GHC-8.0.2:
``...The docs claim that the definition in section 9.11.10
```
data G (a :: k) where
GInt :: G Int
GMaybe :: G Maybe
```
"requires that `-XTypeInType` be in effect", but this isn't the case.
The following compiles with GHC-8.0.2:
```
{-# LANGUAGE PolyKinds, GADTs #-}
data G (a :: k) where
GInt :: G Int
GMaybe :: G Maybe
```
The example does \*not\* compile with 7.10.3, so this seems to be a case where `-XPolyKinds` has become more permissive in GHC 8 (as outlined in section 9.11.1).
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | ------------ |
| Version | 8.0.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":"PolyKinds is more permissive in GHC 8","status":"New","operating_system":"","component":"Compiler","related":[],"milestone":"","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"8.0.2","keywords":[],"differentials":[],"test_case":"","architecture":"","cc":[""],"type":"Bug","description":"The docs claim that the definition in section 9.11.10\r\n\r\n{{{\r\ndata G (a :: k) where\r\n GInt :: G Int\r\n GMaybe :: G Maybe\r\n}}}\r\n\r\n\"requires that `-XTypeInType` be in effect\", but this isn't the case.\r\n\r\nThe following compiles with GHC-8.0.2:\r\n\r\n{{{\r\n\r\n{-# LANGUAGE PolyKinds, GADTs #-}\r\n\r\ndata G (a :: k) where\r\n GInt :: G Int\r\n GMaybe :: G Maybe\r\n}}}\r\n\r\nThe example does *not* compile with 7.10.3, so this seems to be a case where `-XPolyKinds` has become more permissive in GHC 8 (as outlined in section 9.11.1). ","type_of_failure":"OtherFailure","blocking":[]} -->https://gitlab.haskell.org/ghc/ghc/-/issues/13399Location of `forall` matters with higher-rank kind polymorphism2020-05-21T22:48:30ZEric CrockettLocation of `forall` matters with higher-rank kind polymorphismThe following code fails to compile, but probably should:
```hs
{-# LANGUAGE RankNTypes, TypeInType #-}
import Data.Kind
data Foo :: forall k . (* -> *) -> k -> * -- Decl 1
class C (a :: forall k . k -> *)
instance C (Foo a) -- erro...The following code fails to compile, but probably should:
```hs
{-# LANGUAGE RankNTypes, TypeInType #-}
import Data.Kind
data Foo :: forall k . (* -> *) -> k -> * -- Decl 1
class C (a :: forall k . k -> *)
instance C (Foo a) -- error on this line
```
with the error
```
• Expected kind ‘forall k. k -> *’, but ‘Foo a’ has kind ‘k0 -> *’
• In the first argument of ‘C’, namely ‘Foo a’
In the instance declaration for ‘C (Foo a)’
```
Similarly, the following declarations of `Foo` also cause a similar error at the instance declaration:
Decl 2: `data Foo :: (* -> *) -> k -> *`
Decl 3: `data Foo (a :: * -> *) (b :: k)`
However, if I move the `forall` to a point *after* the first type parameter (which is where the instance is partially applied) thusly:
Decl 4: `data Foo :: (* -> *) -> forall k . k -> *`
then GHC happily accepts the instance of `C`.
From my (admittedly negligible) knowledge of type theory, the signatures for Decls 1 and 4 (and 2) are identical, since the `forall` can be floated to the front of Decl 4. GHC should accept any of the four versions of `Foo`, since they are all equivalent.8.4.1https://gitlab.haskell.org/ghc/ghc/-/issues/13407Fix printing of higher-rank kinds2019-07-07T18:22:01ZRichard Eisenbergrae@richarde.devFix printing of higher-rank kindsWitness this GHCi session:
```
rae:09:18:37 ~/ghc/ghc> ghci -ignore-dot-ghci
GHCi, version 8.0.1: http://www.haskell.org/ghc/ :? for help
Prelude> :set -XTypeInType -XRankNTypes
Prelude> import Data.Kind
Prelude Data.Kind> data Foo :: ...Witness this GHCi session:
```
rae:09:18:37 ~/ghc/ghc> ghci -ignore-dot-ghci
GHCi, version 8.0.1: http://www.haskell.org/ghc/ :? for help
Prelude> :set -XTypeInType -XRankNTypes
Prelude> import Data.Kind
Prelude Data.Kind> data Foo :: (* -> *) -> (forall k. k -> *)
Prelude Data.Kind> :info Foo
type role Foo phantom nominal phantom
data Foo (a :: * -> *) k (c :: k)
-- Defined at <interactive>:3:1
```
The output from `:info` is terrible, treating `k` as a visible parameter when it isn't.
This is spun off from #13399 but is not tightly coupled to that ticket.
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | ------------ |
| Version | 8.0.1 |
| 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":"Fix printing of higher-rank kinds","status":"New","operating_system":"","component":"Compiler","related":[],"milestone":"","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"8.0.1","keywords":["TypeInType"],"differentials":[],"test_case":"","architecture":"","cc":[""],"type":"Bug","description":"Witness this GHCi session:\r\n\r\n{{{\r\nrae:09:18:37 ~/ghc/ghc> ghci -ignore-dot-ghci\r\nGHCi, version 8.0.1: http://www.haskell.org/ghc/ :? for help\r\nPrelude> :set -XTypeInType -XRankNTypes\r\nPrelude> import Data.Kind\r\nPrelude Data.Kind> data Foo :: (* -> *) -> (forall k. k -> *)\r\nPrelude Data.Kind> :info Foo\r\ntype role Foo phantom nominal phantom\r\ndata Foo (a :: * -> *) k (c :: k)\r\n \t-- Defined at <interactive>:3:1\r\n}}}\r\n\r\nThe output from `:info` is terrible, treating `k` as a visible parameter when it isn't.\r\n\r\nThis is spun off from #13399 but is not tightly coupled to that ticket.","type_of_failure":"OtherFailure","blocking":[]} -->8.4.1https://gitlab.haskell.org/ghc/ghc/-/issues/13408Consider inferring a higher-rank kind for type synonyms2020-09-25T17:22:29ZRichard Eisenbergrae@richarde.devConsider inferring a higher-rank kind for type synonymsIn terms, a definition comprising one non-recursive equation may have a higher-rank type inferred. For example:
```hs
f :: (forall a. a -> a -> a) -> Int
f z = z 0 1
g = f
```
`g` gets an inferred type equal to `f`'s. However, this fa...In terms, a definition comprising one non-recursive equation may have a higher-rank type inferred. For example:
```hs
f :: (forall a. a -> a -> a) -> Int
f z = z 0 1
g = f
```
`g` gets an inferred type equal to `f`'s. However, this fails at the type level:
```hs
type F (z :: forall a. a -> a -> a) = z 0 1
type G = F
```
If anything is strange here, it's that the term-level definition is accepted. GHC should not be in the business of inferring higher-rank types. But there is an exception for definitions comprising one non-recursive equation.
This ticket proposes expanding this behavior to the type level, allowing `G` to be accepted.
This is spun off from #13399, but is not tightly coupled to that ticket.
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | -------------- |
| Version | 8.0.1 |
| 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":"Consider inferring a higher-rank kind for type synonyms","status":"New","operating_system":"","component":"Compiler","related":[],"milestone":"","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"8.0.1","keywords":["TypeInType"],"differentials":[],"test_case":"","architecture":"","cc":[""],"type":"FeatureRequest","description":"In terms, a definition comprising one non-recursive equation may have a higher-rank type inferred. For example:\r\n\r\n{{{#!hs\r\nf :: (forall a. a -> a -> a) -> Int\r\nf z = z 0 1\r\n\r\ng = f\r\n}}}\r\n\r\n`g` gets an inferred type equal to `f`'s. However, this fails at the type level:\r\n\r\n{{{#!hs\r\ntype F (z :: forall a. a -> a -> a) = z 0 1\r\n\r\ntype G = F\r\n}}}\r\n\r\nIf anything is strange here, it's that the term-level definition is accepted. GHC should not be in the business of inferring higher-rank types. But there is an exception for definitions comprising one non-recursive equation.\r\n\r\nThis ticket proposes expanding this behavior to the type level, allowing `G` to be accepted.\r\n\r\nThis is spun off from #13399, but is not tightly coupled to that ticket.","type_of_failure":"OtherFailure","blocking":[]} -->https://gitlab.haskell.org/ghc/ghc/-/issues/13409Data types with higher-rank kinds are pretty-printed strangely2019-07-07T18:22:00ZRyan ScottData types with higher-rank kinds are pretty-printed strangelyFirst observed in #13399\##13409. If you define this:
```hs
data Foo :: (* -> *) -> (forall k. k -> *)
```
and type `:i Foo` into GHCi, you get this back:
```
type role Foo phantom nominal phantom
data Foo (a :: * -> *) k (c :: k)
```...First observed in #13399\##13409. If you define this:
```hs
data Foo :: (* -> *) -> (forall k. k -> *)
```
and type `:i Foo` into GHCi, you get this back:
```
type role Foo phantom nominal phantom
data Foo (a :: * -> *) k (c :: k)
```
This seems to imply that Foo has three visible type parameters, which isn't true at all!
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | ----------------------- |
| Version | 8.0.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 types with higher-rank kinds are pretty-printed strangely","status":"New","operating_system":"","component":"Compiler (Type checker)","related":[],"milestone":"","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"8.0.2","keywords":["TypeInType"],"differentials":[],"test_case":"","architecture":"","cc":[""],"type":"Bug","description":"First observed in https://ghc.haskell.org/trac/ghc/ticket/13399#comment:5. If you define this:\r\n\r\n{{{#!hs\r\ndata Foo :: (* -> *) -> (forall k. k -> *)\r\n}}}\r\n\r\nand type `:i Foo` into GHCi, you get this back:\r\n\r\n{{{\r\ntype role Foo phantom nominal phantom\r\ndata Foo (a :: * -> *) k (c :: k)\r\n}}}\r\n\r\nThis seems to imply that Foo has three visible type parameters, which isn't true at all!","type_of_failure":"OtherFailure","blocking":[]} -->https://gitlab.haskell.org/ghc/ghc/-/issues/13530Horrible error message due to TypeInType2019-07-07T18:21:28ZSimon Peyton JonesHorrible error message due to TypeInTypeConsider this
```
{-# LANGUAGE MagicHash, UnboxedTuples #-}
module Foo where
import GHC.Exts
g :: Int -> (# Int#, a #)
g (I# y) = (# y, undefined #)
f :: Int -> (# Int#, Int# #)
f x = g x
```
With GHC 8 we get
```
Foo.hs:11:7: err...Consider this
```
{-# LANGUAGE MagicHash, UnboxedTuples #-}
module Foo where
import GHC.Exts
g :: Int -> (# Int#, a #)
g (I# y) = (# y, undefined #)
f :: Int -> (# Int#, Int# #)
f x = g x
```
With GHC 8 we get
```
Foo.hs:11:7: error:
• Couldn't match a lifted type with an unlifted type
Expected type: (# Int#, Int# #)
Actual type: (# Int#, Int# #)
```
What a terrible error message!! It was much better in GHC 7.10:
```
Foo.hs:11:7:
Couldn't match kind ‘*’ with ‘#’
When matching types
a0 :: *
Int# :: #
Expected type: (# Int#, Int# #)
Actual type: (# Int#, a0 #)
```
What's going on?
The constraint solver sees
```
[W] alpha::TYPE LiftedRep ~ Int#::TYPE IntRep
```
So it homogenises the kinds, *and unifies alpha* (this did not happen in GHC 7.10), thus
```
alpha := Int# |> TYPE co
[W] co :: LiftedRep ~ IntRep
```
Of course the new constraint fails. But since we have unified alpha, when we print out the types are are unifying they both look like `(# Int#, Int# #)` (there's a suppressed cast in the second component).
I'm not sure what to do here.
(I tripped over this when debugging #13509.)https://gitlab.haskell.org/ghc/ghc/-/issues/13546Kind error with type equality2019-07-07T18:21:24ZVladislav ZavialovKind error with type equalityThis code
```hs
{-# LANGUAGE TypeInType, TypeFamilies, GADTs, ConstraintKinds #-}
import Data.Kind
data Dict c where
Dict :: c => Dict c
data T (t :: k)
type family UnT (a :: Type) :: k where
UnT (T t) = t
untt :: Dict (UnT (T ...This code
```hs
{-# LANGUAGE TypeInType, TypeFamilies, GADTs, ConstraintKinds #-}
import Data.Kind
data Dict c where
Dict :: c => Dict c
data T (t :: k)
type family UnT (a :: Type) :: k where
UnT (T t) = t
untt :: Dict (UnT (T "a") ~ "a")
untt = Dict
tunt :: Dict (T (UnT (T "a")) ~ T "a")
tunt = Dict
```
fails with this error:
```
tunt.hs:17:8: error:
• Couldn't match kind ‘k’ with ‘GHC.Types.Symbol’
‘k’ is a rigid type variable bound by
the type signature for:
tunt :: forall k. Dict T (UnT (T "a")) ~ T "a"
at tunt.hs:16:1-38
When matching types
UnT (T "a") :: k
"a" :: GHC.Types.Symbol
• In the expression: Dict
In an equation for ‘tunt’: tunt = Dict
• Relevant bindings include
tunt :: Dict T (UnT (T "a")) ~ T "a" (bound at tunt.hs:17:1)
|
17 | tunt = Dict
|
```
Instead I would expect these reductions to take place:
```
1. T (UnT (T "a")) ~ T "a"
2. T "a" ~ T "a"
3. constraint satisfied (refl)
```
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | ----------------------- |
| Version | 8.0.1 |
| Type | Bug |
| TypeOfFailure | OtherFailure |
| Priority | normal |
| Resolution | Unresolved |
| Component | Compiler (Type checker) |
| Test case | |
| Differential revisions | |
| BlockedBy | |
| Related | |
| Blocking | |
| CC | goldfire |
| Operating system | |
| Architecture | |
</details>
<!-- {"blocked_by":[],"summary":"Kind error with type equality","status":"New","operating_system":"","component":"Compiler (Type checker)","related":[],"milestone":"","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"8.0.1","keywords":["TypeInType"],"differentials":[],"test_case":"","architecture":"","cc":["goldfire"],"type":"Bug","description":"This code\r\n\r\n{{{#!hs\r\n{-# LANGUAGE TypeInType, TypeFamilies, GADTs, ConstraintKinds #-}\r\n\r\nimport Data.Kind\r\n\r\ndata Dict c where\r\n Dict :: c => Dict c\r\n\r\ndata T (t :: k)\r\n\r\ntype family UnT (a :: Type) :: k where\r\n UnT (T t) = t\r\n\r\nuntt :: Dict (UnT (T \"a\") ~ \"a\")\r\nuntt = Dict\r\n\r\ntunt :: Dict (T (UnT (T \"a\")) ~ T \"a\")\r\ntunt = Dict\r\n}}}\r\n\r\nfails with this error:\r\n\r\n{{{\r\ntunt.hs:17:8: error:\r\n • Couldn't match kind ‘k’ with ‘GHC.Types.Symbol’\r\n ‘k’ is a rigid type variable bound by\r\n the type signature for:\r\n tunt :: forall k. Dict T (UnT (T \"a\")) ~ T \"a\"\r\n at tunt.hs:16:1-38\r\n When matching types\r\n UnT (T \"a\") :: k\r\n \"a\" :: GHC.Types.Symbol\r\n • In the expression: Dict\r\n In an equation for ‘tunt’: tunt = Dict\r\n • Relevant bindings include\r\n tunt :: Dict T (UnT (T \"a\")) ~ T \"a\" (bound at tunt.hs:17:1)\r\n |\r\n17 | tunt = Dict\r\n | \r\n}}}\r\n\r\nInstead I would expect these reductions to take place:\r\n\r\n{{{\r\n 1. T (UnT (T \"a\")) ~ T \"a\"\r\n 2. T \"a\" ~ T \"a\"\r\n 3. constraint satisfied (refl)\r\n}}}","type_of_failure":"OtherFailure","blocking":[]} -->https://gitlab.haskell.org/ghc/ghc/-/issues/13549GHC 8.2.1's typechecker rejects code generated by singletons that 8.0 accepts2019-07-07T18:21:23ZRyan ScottGHC 8.2.1's typechecker rejects code generated by singletons that 8.0 acceptsI recently attempted to upgrade `singletons` to use GHC 8.2.1, but was thwarted when GHC's typechecker rejected code that was generated by Template Haskell. I was able to put all of this code in a single module (which I've attached), but...I recently attempted to upgrade `singletons` to use GHC 8.2.1, but was thwarted when GHC's typechecker rejected code that was generated by Template Haskell. I was able to put all of this code in a single module (which I've attached), but sadly, it's 1367 lines long. What's important is that GHC 8.0.1 and 8.0.2 accept this code, but neither 8.2.1-rc1 nor HEAD do. Here is the error message you get, in its full glory:
```
$ /opt/ghc/8.2.1/bin/ghci Bug.hs -fprint-explicit-kinds
GHCi, version 8.2.0.20170403: http://www.haskell.org/ghc/ :? for help
Loaded GHCi configuration from /home/rgscott/.ghci
[1 of 1] Compiling Bug ( Bug.hs, interpreted )
Bug.hs:1328:59: error:
• Couldn't match type ‘c69895866216793215480’ with ‘[a_a337f]’
‘c69895866216793215480’ is untouchable
inside the constraints: (arg_a33hh ~ xs_a33fp, arg_a33hi ~ r_a33fq)
bound by the type signature for:
lambda_a33iH :: forall (xs_a33fp :: [a_a337f]) (r_a33fq :: [[a_a337f]]).
(arg_a33hh ~ xs_a33fp, arg_a33hi ~ r_a33fq) =>
Sing [a_a337f] xs_a33fp
-> Sing [[a_a337f]] r_a33fq
-> Sing
[[a_a337f]]
(Apply
[[a_a337f]]
[[a_a337f]]
(Apply
[a_a337f]
(TyFun [[a_a337f]] [[a_a337f]] -> *)
(Let6989586621679736980InterleaveSym4
[a_a337f]
[a_a337f]
a_a337f
xs0_a33a0
t_a33aL
ts_a33aM
is_a33aO)
arg_a33hh)
arg_a33hi)
at Bug.hs:(1289,35)-(1294,157)
Expected type: Sing (TyFun [a_a337f] [a_a337f] -> *) t
-> Sing [a_a337f] t1
-> Sing [[a_a337f]] t2
-> Sing
([a_a337f], [[a_a337f]])
((@@)
[[a_a337f]]
([a_a337f], [[a_a337f]])
((@@)
[a_a337f]
([[a_a337f]] ~> ([a_a337f], [[a_a337f]]))
((@@)
(TyFun [a_a337f] [a_a337f] -> *)
([a_a337f] ~> ([[a_a337f]] ~> ([a_a337f], [[a_a337f]])))
(Let6989586621679736980Interleave'Sym4
[a_a337f]
[a_a337f]
a_a337f
[a_a337f]
xs0_a33a0
t_a33aL
ts_a33aM
is_a33aO)
t)
t1)
t2)
Actual type: Sing (TyFun [a_a337f] c69895866216793215480 -> *) t
-> Sing [a_a337f] t1
-> Sing [c69895866216793215480] t2
-> Sing
([a_a337f], [c69895866216793215480])
(Apply
[c69895866216793215480]
([a_a337f], [c69895866216793215480])
(Apply
[a_a337f]
([c69895866216793215480] ~> ([a_a337f], [c69895866216793215480]))
(Apply
(TyFun [a_a337f] c69895866216793215480 -> *)
([a_a337f]
~> ([c69895866216793215480]
~> ([a_a337f], [c69895866216793215480])))
(Let6989586621679736980Interleave'Sym4
[a_a337f]
[a_a337f]
a_a337f
c69895866216793215480
xs0_a33a0
t_a33aL
ts_a33aM
is_a33aO)
t)
t1)
t2)
• In the second argument of ‘singFun3’, namely ‘sInterleave'’
In the first argument of ‘applySing’, namely
‘((singFun3
(Proxy ::
Proxy (Let6989586621679736980Interleave'Sym4 xs0_a33a0 t_a33aL ts_a33aM is_a33aO)))
sInterleave')’
In the first argument of ‘applySing’, namely
‘((applySing
((singFun3
(Proxy ::
Proxy (Let6989586621679736980Interleave'Sym4 xs0_a33a0 t_a33aL ts_a33aM is_a33aO)))
sInterleave'))
((singFun1 (Proxy :: Proxy IdSym0)) sId))’
• Relevant bindings include
sX_6989586621679737266 :: Sing
([a_a337f], [[a_a337f]])
(Let6989586621679737265X_6989586621679737266Sym6
[a_a337f]
[a_a337f]
a_a337f
xs0_a33a0
t_a33aL
ts_a33aM
is_a33aO
xs_a33fp
r_a33fq)
(bound at Bug.hs:1321:41)
r_a33iK :: Sing [[a_a337f]] r_a33fq (bound at Bug.hs:1295:57)
xs_a33iJ :: Sing [a_a337f] xs_a33fp (bound at Bug.hs:1295:48)
lambda_a33iH :: Sing [a_a337f] xs_a33fp
-> Sing [[a_a337f]] r_a33fq
-> Sing
[[a_a337f]]
(Apply
[[a_a337f]]
[[a_a337f]]
(Apply
[a_a337f]
(TyFun [[a_a337f]] [[a_a337f]] -> *)
(Let6989586621679736980InterleaveSym4
[a_a337f]
[a_a337f]
a_a337f
xs0_a33a0
t_a33aL
ts_a33aM
is_a33aO)
arg_a33hh)
arg_a33hi)
(bound at Bug.hs:1295:35)
sR :: Sing [[a_a337f]] arg_a33hi (bound at Bug.hs:1287:45)
sXs :: Sing [a_a337f] arg_a33hh (bound at Bug.hs:1287:41)
sInterleave' :: forall (arg_a33he :: TyFun
[a_a337f] c69895866216793215480
-> *) (arg_a33hf :: [a_a337f]) (arg_a33hg :: [c69895866216793215480]).
Sing (TyFun [a_a337f] c69895866216793215480 -> *) arg_a33he
-> Sing [a_a337f] arg_a33hf
-> Sing [c69895866216793215480] arg_a33hg
-> Sing
([a_a337f], [c69895866216793215480])
(Apply
[c69895866216793215480]
([a_a337f], [c69895866216793215480])
(Apply
[a_a337f]
([c69895866216793215480] ~> ([a_a337f], [c69895866216793215480]))
(Apply
(TyFun [a_a337f] c69895866216793215480 -> *)
([a_a337f]
~> ([c69895866216793215480]
~> ([a_a337f], [c69895866216793215480])))
(Let6989586621679736980Interleave'Sym4
[a_a337f]
[a_a337f]
a_a337f
c69895866216793215480
xs0_a33a0
t_a33aL
ts_a33aM
is_a33aO)
arg_a33he)
arg_a33hf)
arg_a33hg)
(bound at Bug.hs:1166:29)
lambda_a33ha :: Sing a_a337f t_a33aL
-> Sing [a_a337f] ts_a33aM
-> Sing [a_a337f] is_a33aO
-> Sing
[[a_a337f]]
(Apply
[a_a337f]
[[a_a337f]]
(Apply
[a_a337f]
([a_a337f] ~> [[a_a337f]])
(Let6989586621679736931PermsSym1 a_a337f xs0_a33a0)
arg_a33h0)
arg_a33h1)
(bound at Bug.hs:1153:23)
sTs :: Sing [a_a337f] n_a1kQd (bound at Bug.hs:1143:34)
sT :: Sing a_a337f n_a1kQc (bound at Bug.hs:1143:31)
lambda_a33gY :: Sing [a_a337f] xs0_a33a0
-> Sing
[[a_a337f]]
(Apply [a_a337f] [[a_a337f]] (PermutationsSym0 a_a337f) t_a33gX)
(bound at Bug.hs:1127:11)
(Some bindings suppressed; use -fmax-relevant-binds=N or -fno-max-relevant-binds)
|
1328 | sInterleave'))
| ^^^^^^^^^^^^
Bug.hs:1328:59: error:
• Could not deduce: (Let6989586621679736980Interleave'
[a_a337f]
[a_a337f]
a_a337f
c69895866216793215480
xs0_a33a0
t_a33aL
ts_a33aM
is_a33aO
t
t1
t2 :: ([a_a337f], [c69895866216793215480]))
~~
(Let6989586621679736980Interleave'
[a_a337f]
[a_a337f]
a_a337f
[a_a337f]
xs0_a33a0
t_a33aL
ts_a33aM
is_a33aO
t
t1
t2 :: ([a_a337f], [c69895866216793215480]))
from the context: t_a33gX ~ xs0_a33a0
bound by the type signature for:
lambda_a33gY :: forall (xs0_a33a0 :: [a_a337f]).
t_a33gX ~ xs0_a33a0 =>
Sing [a_a337f] xs0_a33a0
-> Sing
[[a_a337f]]
(Apply
[a_a337f] [[a_a337f]] (PermutationsSym0 a_a337f) t_a33gX)
at Bug.hs:(1122,11)-(1126,67)
or from: arg_a33h0 ~ (':) a_a337f n_a1kQc n_a1kQd
bound by a pattern with constructor:
SCons :: forall a_11 (z_a1kQb :: [a_11]) (n_a1kQc :: a_11) (n_a1kQd :: [a_11]).
z_a1kQb ~ (':) a_11 n_a1kQc n_a1kQd =>
Sing a_11 n_a1kQc -> Sing [a_11] n_a1kQd -> Sing [a_11] z_a1kQb,
in an equation for ‘sPerms’
at Bug.hs:1143:25-36
or from: (arg_a33h0
~
Apply
[a_a337f]
[a_a337f]
(Apply
a_a337f (TyFun [a_a337f] [a_a337f] -> *) ((:$) a_a337f) t_a33aL)
ts_a33aM,
arg_a33h1 ~ is_a33aO)
bound by the type signature for:
lambda_a33ha :: forall (t_a33aL :: a_a337f) (ts_a33aM :: [a_a337f]) (is_a33aO :: [a_a337f]).
(arg_a33h0
~
Apply
[a_a337f]
[a_a337f]
(Apply
a_a337f
(TyFun [a_a337f] [a_a337f] -> *)
((:$) a_a337f)
t_a33aL)
ts_a33aM,
arg_a33h1 ~ is_a33aO) =>
Sing a_a337f t_a33aL
-> Sing [a_a337f] ts_a33aM
-> Sing [a_a337f] is_a33aO
-> Sing
[[a_a337f]]
(Apply
[a_a337f]
[[a_a337f]]
(Apply
[a_a337f]
([a_a337f] ~> [[a_a337f]])
(Let6989586621679736931PermsSym1 a_a337f xs0_a33a0)
arg_a33h0)
arg_a33h1)
at Bug.hs:(1145,23)-(1152,117)
or from: (arg_a33hh ~ xs_a33fp, arg_a33hi ~ r_a33fq)
bound by the type signature for:
lambda_a33iH :: forall (xs_a33fp :: [a_a337f]) (r_a33fq :: [[a_a337f]]).
(arg_a33hh ~ xs_a33fp, arg_a33hi ~ r_a33fq) =>
Sing [a_a337f] xs_a33fp
-> Sing [[a_a337f]] r_a33fq
-> Sing
[[a_a337f]]
(Apply
[[a_a337f]]
[[a_a337f]]
(Apply
[a_a337f]
(TyFun [[a_a337f]] [[a_a337f]] -> *)
(Let6989586621679736980InterleaveSym4
[a_a337f]
[a_a337f]
a_a337f
xs0_a33a0
t_a33aL
ts_a33aM
is_a33aO)
arg_a33hh)
arg_a33hi)
at Bug.hs:(1289,35)-(1294,157)
Expected type: Sing (TyFun [a_a337f] [a_a337f] -> *) t
-> Sing [a_a337f] t1
-> Sing [[a_a337f]] t2
-> Sing
([a_a337f], [[a_a337f]])
((@@)
[[a_a337f]]
([a_a337f], [[a_a337f]])
((@@)
[a_a337f]
([[a_a337f]] ~> ([a_a337f], [[a_a337f]]))
((@@)
(TyFun [a_a337f] [a_a337f] -> *)
([a_a337f] ~> ([[a_a337f]] ~> ([a_a337f], [[a_a337f]])))
(Let6989586621679736980Interleave'Sym4
[a_a337f]
[a_a337f]
a_a337f
[a_a337f]
xs0_a33a0
t_a33aL
ts_a33aM
is_a33aO)
t)
t1)
t2)
Actual type: Sing (TyFun [a_a337f] c69895866216793215480 -> *) t
-> Sing [a_a337f] t1
-> Sing [c69895866216793215480] t2
-> Sing
([a_a337f], [c69895866216793215480])
(Apply
[c69895866216793215480]
([a_a337f], [c69895866216793215480])
(Apply
[a_a337f]
([c69895866216793215480] ~> ([a_a337f], [c69895866216793215480]))
(Apply
(TyFun [a_a337f] c69895866216793215480 -> *)
([a_a337f]
~> ([c69895866216793215480]
~> ([a_a337f], [c69895866216793215480])))
(Let6989586621679736980Interleave'Sym4
[a_a337f]
[a_a337f]
a_a337f
c69895866216793215480
xs0_a33a0
t_a33aL
ts_a33aM
is_a33aO)
t)
t1)
t2)
The type variable ‘c69895866216793215480’ is ambiguous
• In the second argument of ‘singFun3’, namely ‘sInterleave'’
In the first argument of ‘applySing’, namely
‘((singFun3
(Proxy ::
Proxy (Let6989586621679736980Interleave'Sym4 xs0_a33a0 t_a33aL ts_a33aM is_a33aO)))
sInterleave')’
In the first argument of ‘applySing’, namely
‘((applySing
((singFun3
(Proxy ::
Proxy (Let6989586621679736980Interleave'Sym4 xs0_a33a0 t_a33aL ts_a33aM is_a33aO)))
sInterleave'))
((singFun1 (Proxy :: Proxy IdSym0)) sId))’
• Relevant bindings include
sX_6989586621679737266 :: Sing
([a_a337f], [[a_a337f]])
(Let6989586621679737265X_6989586621679737266Sym6
[a_a337f]
[a_a337f]
a_a337f
xs0_a33a0
t_a33aL
ts_a33aM
is_a33aO
xs_a33fp
r_a33fq)
(bound at Bug.hs:1321:41)
r_a33iK :: Sing [[a_a337f]] r_a33fq (bound at Bug.hs:1295:57)
xs_a33iJ :: Sing [a_a337f] xs_a33fp (bound at Bug.hs:1295:48)
lambda_a33iH :: Sing [a_a337f] xs_a33fp
-> Sing [[a_a337f]] r_a33fq
-> Sing
[[a_a337f]]
(Apply
[[a_a337f]]
[[a_a337f]]
(Apply
[a_a337f]
(TyFun [[a_a337f]] [[a_a337f]] -> *)
(Let6989586621679736980InterleaveSym4
[a_a337f]
[a_a337f]
a_a337f
xs0_a33a0
t_a33aL
ts_a33aM
is_a33aO)
arg_a33hh)
arg_a33hi)
(bound at Bug.hs:1295:35)
sR :: Sing [[a_a337f]] arg_a33hi (bound at Bug.hs:1287:45)
sXs :: Sing [a_a337f] arg_a33hh (bound at Bug.hs:1287:41)
sInterleave' :: forall (arg_a33he :: TyFun
[a_a337f] c69895866216793215480
-> *) (arg_a33hf :: [a_a337f]) (arg_a33hg :: [c69895866216793215480]).
Sing (TyFun [a_a337f] c69895866216793215480 -> *) arg_a33he
-> Sing [a_a337f] arg_a33hf
-> Sing [c69895866216793215480] arg_a33hg
-> Sing
([a_a337f], [c69895866216793215480])
(Apply
[c69895866216793215480]
([a_a337f], [c69895866216793215480])
(Apply
[a_a337f]
([c69895866216793215480] ~> ([a_a337f], [c69895866216793215480]))
(Apply
(TyFun [a_a337f] c69895866216793215480 -> *)
([a_a337f]
~> ([c69895866216793215480]
~> ([a_a337f], [c69895866216793215480])))
(Let6989586621679736980Interleave'Sym4
[a_a337f]
[a_a337f]
a_a337f
c69895866216793215480
xs0_a33a0
t_a33aL
ts_a33aM
is_a33aO)
arg_a33he)
arg_a33hf)
arg_a33hg)
(bound at Bug.hs:1166:29)
lambda_a33ha :: Sing a_a337f t_a33aL
-> Sing [a_a337f] ts_a33aM
-> Sing [a_a337f] is_a33aO
-> Sing
[[a_a337f]]
(Apply
[a_a337f]
[[a_a337f]]
(Apply
[a_a337f]
([a_a337f] ~> [[a_a337f]])
(Let6989586621679736931PermsSym1 a_a337f xs0_a33a0)
arg_a33h0)
arg_a33h1)
(bound at Bug.hs:1153:23)
sTs :: Sing [a_a337f] n_a1kQd (bound at Bug.hs:1143:34)
sT :: Sing a_a337f n_a1kQc (bound at Bug.hs:1143:31)
lambda_a33gY :: Sing [a_a337f] xs0_a33a0
-> Sing
[[a_a337f]]
(Apply [a_a337f] [[a_a337f]] (PermutationsSym0 a_a337f) t_a33gX)
(bound at Bug.hs:1127:11)
(Some bindings suppressed; use -fmax-relevant-binds=N or -fno-max-relevant-binds)
|
1328 | sInterleave'))
| ^^^^^^^^^^^^
```8.4.1https://gitlab.haskell.org/ghc/ghc/-/issues/13555Typechecker regression when combining PolyKinds and MonoLocalBinds2019-07-07T18:21:21ZRyan ScottTypechecker regression when combining PolyKinds and MonoLocalBinds`lol-0.6.0.0` from Hackage currently fails to build with GHC 8.2.1 because of this regression. Here is a minimized example:
```hs
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE InstanceSigs #-}
{-# LANGUAGE MonoLocalBinds #-}
{-# LANGUA...`lol-0.6.0.0` from Hackage currently fails to build with GHC 8.2.1 because of this regression. Here is a minimized example:
```hs
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE InstanceSigs #-}
{-# LANGUAGE MonoLocalBinds #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE RankNTypes #-}
module Crypto.Lol.Types.FiniteField (GF(..)) where
import Data.Functor.Identity (Identity(..))
data T a
type Polynomial a = T a
newtype GF fp d = GF (Polynomial fp)
type CRTInfo r = (Int -> r, r)
type Tagged s b = TaggedT s Identity b
newtype TaggedT s m b = TagT { untagT :: m b }
class Reflects a i where
value :: Tagged a i
class CRTrans mon r where
crtInfo :: Reflects m Int => TaggedT m mon (CRTInfo r)
instance CRTrans Maybe (GF fp d) where
crtInfo :: forall m . (Reflects m Int) => TaggedT m Maybe (CRTInfo (GF fp d))
crtInfo = undefined
```
This typechecks OK with GHC 8.0.2, but with 8.2.1, it complains:
```
$ /opt/ghc/8.2.1/bin/ghci Bug.hs
GHCi, version 8.2.0.20170403: http://www.haskell.org/ghc/ :? for help
Loaded GHCi configuration from /home/rgscott/.ghci
[1 of 1] Compiling Crypto.Lol.Types.FiniteField ( Bug.hs, interpreted )
Bug.hs:25:14: error:
• Couldn't match type ‘k0’ with ‘k2’
because type variable ‘k2’ would escape its scope
This (rigid, skolem) type variable is bound by
the type signature for:
crtInfo :: forall k2 (m :: k2).
Reflects m Int =>
TaggedT m Maybe (CRTInfo (GF fp d))
at Bug.hs:25:14-79
Expected type: TaggedT m Maybe (CRTInfo (GF fp d))
Actual type: TaggedT m Maybe (CRTInfo (GF fp d))
• When checking that instance signature for ‘crtInfo’
is more general than its signature in the class
Instance sig: forall (m :: k0).
Reflects m Int =>
TaggedT m Maybe (CRTInfo (GF fp d))
Class sig: forall k2 (m :: k2).
Reflects m Int =>
TaggedT m Maybe (CRTInfo (GF fp d))
In the instance declaration for ‘CRTrans Maybe (GF fp d)’
|
25 | crtInfo :: forall m . (Reflects m Int) => TaggedT m Maybe (CRTInfo (GF fp d))
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Bug.hs:25:14: error:
• Could not deduce (Reflects m Int)
from the context: Reflects m Int
bound by the type signature for:
crtInfo :: forall k2 (m :: k2).
Reflects m Int =>
TaggedT m Maybe (CRTInfo (GF fp d))
at Bug.hs:25:14-79
The type variable ‘k0’ is ambiguous
• When checking that instance signature for ‘crtInfo’
is more general than its signature in the class
Instance sig: forall (m :: k0).
Reflects m Int =>
TaggedT m Maybe (CRTInfo (GF fp d))
Class sig: forall k2 (m :: k2).
Reflects m Int =>
TaggedT m Maybe (CRTInfo (GF fp d))
In the instance declaration for ‘CRTrans Maybe (GF fp d)’
|
25 | crtInfo :: forall m . (Reflects m Int) => TaggedT m Maybe (CRTInfo (GF fp d))
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
```
Notably, both `PolyKinds` and `MonoLocalBinds` are required to trigger this bug.
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | ----------------------- |
| Version | 8.1 |
| 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":"Typechecker regression when combining PolyKinds and MonoLocalBinds","status":"New","operating_system":"","component":"Compiler (Type checker)","related":[],"milestone":"8.2.1","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"8.1","keywords":[],"differentials":[],"test_case":"","architecture":"","cc":[""],"type":"Bug","description":"`lol-0.6.0.0` from Hackage currently fails to build with GHC 8.2.1 because of this regression. Here is a minimized example:\r\n\r\n{{{#!hs\r\n{-# LANGUAGE FlexibleContexts #-}\r\n{-# LANGUAGE InstanceSigs #-}\r\n{-# LANGUAGE MonoLocalBinds #-}\r\n{-# LANGUAGE MultiParamTypeClasses #-}\r\n{-# LANGUAGE PolyKinds #-}\r\n{-# LANGUAGE RankNTypes #-}\r\nmodule Crypto.Lol.Types.FiniteField (GF(..)) where\r\n\r\nimport Data.Functor.Identity (Identity(..))\r\n\r\ndata T a\r\ntype Polynomial a = T a\r\nnewtype GF fp d = GF (Polynomial fp)\r\ntype CRTInfo r = (Int -> r, r)\r\ntype Tagged s b = TaggedT s Identity b\r\nnewtype TaggedT s m b = TagT { untagT :: m b }\r\n\r\nclass Reflects a i where\r\n value :: Tagged a i\r\n\r\nclass CRTrans mon r where\r\n crtInfo :: Reflects m Int => TaggedT m mon (CRTInfo r)\r\n\r\ninstance CRTrans Maybe (GF fp d) where\r\n crtInfo :: forall m . (Reflects m Int) => TaggedT m Maybe (CRTInfo (GF fp d))\r\n crtInfo = undefined\r\n}}}\r\n\r\nThis typechecks OK with GHC 8.0.2, but with 8.2.1, it complains:\r\n\r\n{{{\r\n$ /opt/ghc/8.2.1/bin/ghci Bug.hs\r\nGHCi, version 8.2.0.20170403: http://www.haskell.org/ghc/ :? for help\r\nLoaded GHCi configuration from /home/rgscott/.ghci\r\n[1 of 1] Compiling Crypto.Lol.Types.FiniteField ( Bug.hs, interpreted )\r\n\r\nBug.hs:25:14: error:\r\n • Couldn't match type ‘k0’ with ‘k2’\r\n because type variable ‘k2’ would escape its scope\r\n This (rigid, skolem) type variable is bound by\r\n the type signature for:\r\n crtInfo :: forall k2 (m :: k2).\r\n Reflects m Int =>\r\n TaggedT m Maybe (CRTInfo (GF fp d))\r\n at Bug.hs:25:14-79\r\n Expected type: TaggedT m Maybe (CRTInfo (GF fp d))\r\n Actual type: TaggedT m Maybe (CRTInfo (GF fp d))\r\n • When checking that instance signature for ‘crtInfo’\r\n is more general than its signature in the class\r\n Instance sig: forall (m :: k0).\r\n Reflects m Int =>\r\n TaggedT m Maybe (CRTInfo (GF fp d))\r\n Class sig: forall k2 (m :: k2).\r\n Reflects m Int =>\r\n TaggedT m Maybe (CRTInfo (GF fp d))\r\n In the instance declaration for ‘CRTrans Maybe (GF fp d)’\r\n |\r\n25 | crtInfo :: forall m . (Reflects m Int) => TaggedT m Maybe (CRTInfo (GF fp d))\r\n | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\r\n\r\nBug.hs:25:14: error:\r\n • Could not deduce (Reflects m Int)\r\n from the context: Reflects m Int\r\n bound by the type signature for:\r\n crtInfo :: forall k2 (m :: k2).\r\n Reflects m Int =>\r\n TaggedT m Maybe (CRTInfo (GF fp d))\r\n at Bug.hs:25:14-79\r\n The type variable ‘k0’ is ambiguous\r\n • When checking that instance signature for ‘crtInfo’\r\n is more general than its signature in the class\r\n Instance sig: forall (m :: k0).\r\n Reflects m Int =>\r\n TaggedT m Maybe (CRTInfo (GF fp d))\r\n Class sig: forall k2 (m :: k2).\r\n Reflects m Int =>\r\n TaggedT m Maybe (CRTInfo (GF fp d))\r\n In the instance declaration for ‘CRTrans Maybe (GF fp d)’\r\n |\r\n25 | crtInfo :: forall m . (Reflects m Int) => TaggedT m Maybe (CRTInfo (GF fp d))\r\n | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\r\n}}}\r\n\r\nNotably, both `PolyKinds` and `MonoLocalBinds` are required to trigger this bug.","type_of_failure":"OtherFailure","blocking":[]} -->8.2.1https://gitlab.haskell.org/ghc/ghc/-/issues/13585ala from Control.Lens.Wrapped panics2019-07-07T18:21:10ZFumiaki Kinoshitaala from Control.Lens.Wrapped panicsPanic.hs:
```
module Panic where
import Control.Lens.Wrapped
import Data.Monoid
foo :: Maybe String
foo = ala Last foldMap [Just "foo"]
```
main.hs:
```
module Main where
import Panic (foo)
main :: IO ()
main = print foo
```
```
$...Panic.hs:
```
module Panic where
import Control.Lens.Wrapped
import Data.Monoid
foo :: Maybe String
foo = ala Last foldMap [Just "foo"]
```
main.hs:
```
module Main where
import Panic (foo)
main :: IO ()
main = print foo
```
```
$ ghc -c -O2 Panic.hs
$ ghc -c -O2 main.hs
ghc: panic! (the 'impossible' happened)
(GHC version 8.2.0.20170404 for x86_64-unknown-linux):
splitTyConApp
(Exchange (Unwrapped (Last String)) (Unwrapped (Last String)) |> <*
-> * -> *>_N) (Maybe
[Char]) ((Identity |> <*
-> *>_N) (Maybe
[Char]))
Call stack:
CallStack (from HasCallStack):
prettyCurrentCallStack, called at compiler/utils/Outputable.hs:1134:58 in ghc:Outputable
callStackDoc, called at compiler/utils/Outputable.hs:1138:37 in ghc:Outputable
pprPanic, called at compiler/types/Type.hs:1105:34 in ghc:Type
Please report this as a GHC bug: http://www.haskell.org/ghc/reportabug
```
The GHC version is 8134f7d4ba2c14b2f24d2f4c1f5260fcaff3304a.
Control.Lens.Wrapped is from the latest version of lens on GitHub: https://github.com/ekmett/lens/blob/9c4447de7ef57f67dbe293320d45bd8a546be522/src/Control/Lens/Wrapped.hs8.2.1Richard Eisenbergrae@richarde.devRichard Eisenbergrae@richarde.devhttps://gitlab.haskell.org/ghc/ghc/-/issues/13603Can't resolve levity polymorphic superclass2019-07-07T18:21:04ZIcelandjackCan't resolve levity polymorphic superclassThis works
```hs
{-# Language PolyKinds, TypeInType #-}
import GHC.Exts (TYPE, RuntimeRep)
class A (a :: TYPE rep)
class A a => B (a :: TYPE rep)
instance A b => A (a -> (b :: TYPE rep))
instance B b => B (a -> b)
```
but the...This works
```hs
{-# Language PolyKinds, TypeInType #-}
import GHC.Exts (TYPE, RuntimeRep)
class A (a :: TYPE rep)
class A a => B (a :: TYPE rep)
instance A b => A (a -> (b :: TYPE rep))
instance B b => B (a -> b)
```
but the moment you add (`b :: TYPE rep`) to the last line it stops working
```hs
-- t3I7.hs:9:10-40: error: …
-- • Could not deduce (A b)
-- arising from the superclasses of an instance declaration
-- from the context: B b
-- bound by the instance declaration at /tmp/t3I7.hs:9:10-40
-- • In the instance declaration for ‘B (a -> b)’
-- Compilation failed.
{-# Language PolyKinds, TypeInType #-}
import GHC.Exts (TYPE, RuntimeRep)
class A (a :: TYPE rep)
class A a => B (a :: TYPE rep)
instance A b => A (a -> (b :: TYPE rep))
instance B b => B (a -> (b :: TYPE rep))
```
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | ------------ |
| Version | 8.0.1 |
| 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":"Can't resolve levity polymorphic superclass","status":"New","operating_system":"","component":"Compiler","related":[],"milestone":"","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"8.0.1","keywords":["LevityPolymorphism,","TypeInType"],"differentials":[],"test_case":"","architecture":"","cc":[""],"type":"Bug","description":"This works\r\n\r\n{{{#!hs\r\n{-# Language PolyKinds, TypeInType #-}\r\n\r\nimport GHC.Exts (TYPE, RuntimeRep)\r\n\r\nclass A (a :: TYPE rep)\r\nclass A a => B (a :: TYPE rep)\r\n\r\ninstance A b => A (a -> (b :: TYPE rep))\r\ninstance B b => B (a -> b)\r\n}}}\r\n\r\nbut the moment you add (`b :: TYPE rep`) to the last line it stops working\r\n\r\n\r\n{{{#!hs\r\n-- t3I7.hs:9:10-40: error: …\r\n-- • Could not deduce (A b)\r\n-- arising from the superclasses of an instance declaration\r\n-- from the context: B b\r\n-- bound by the instance declaration at /tmp/t3I7.hs:9:10-40\r\n-- • In the instance declaration for ‘B (a -> b)’\r\n-- Compilation failed.\r\n\r\n{-# Language PolyKinds, TypeInType #-}\r\n\r\nimport GHC.Exts (TYPE, RuntimeRep)\r\n\r\nclass A (a :: TYPE rep)\r\nclass A a => B (a :: TYPE rep)\r\n\r\ninstance A b => A (a -> (b :: TYPE rep))\r\ninstance B b => B (a -> (b :: TYPE rep))\r\n}}}\r\n\r\n\r\n","type_of_failure":"OtherFailure","blocking":[]} -->8.2.1https://gitlab.haskell.org/ghc/ghc/-/issues/13625GHC internal error: ‘Y’ is not in scope during type checking, but it passed t...2019-07-07T18:20:53ZMatthew PickeringGHC internal error: ‘Y’ is not in scope during type checking, but it passed the renamer```
{-# LANGUAGE TypeInType #-}
data X :: Y where Y :: X
```
The error message is:
```
Bug.hs:2:11: error: …
• GHC internal error: ‘Y’ is not in scope during type checking, but it passed the renamer
tcl_env of environment: [r...```
{-# LANGUAGE TypeInType #-}
data X :: Y where Y :: X
```
The error message is:
```
Bug.hs:2:11: error: …
• GHC internal error: ‘Y’ is not in scope during type checking, but it passed the renamer
tcl_env of environment: [r1cR :-> APromotionErr TyConPE]
• In the kind ‘Y’
```
Originally reported by \@mietek in #11821
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | ------------ |
| Version | 8.0.1 |
| Type | Bug |
| TypeOfFailure | OtherFailure |
| Priority | normal |
| Resolution | Unresolved |
| Component | Compiler |
| Test case | |
| Differential revisions | |
| BlockedBy | |
| Related | |
| Blocking | |
| CC | mietek |
| Operating system | |
| Architecture | |
</details>
<!-- {"blocked_by":[],"summary":"GHC internal error: ‘Y’ is not in scope during type checking, but it passed the renamer","status":"New","operating_system":"","component":"Compiler","related":[],"milestone":"","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"8.0.1","keywords":[],"differentials":[],"test_case":"","architecture":"","cc":["mietek"],"type":"Bug","description":"{{{\r\n{-# LANGUAGE TypeInType #-}\r\ndata X :: Y where Y :: X\r\n}}}\r\n\r\nThe error message is:\r\n\r\n{{{\r\nBug.hs:2:11: error: …\r\n • GHC internal error: ‘Y’ is not in scope during type checking, but it passed the renamer\r\n tcl_env of environment: [r1cR :-> APromotionErr TyConPE]\r\n • In the kind ‘Y’\r\n}}}\r\n\r\nOriginally reported by @mietek in #11821","type_of_failure":"OtherFailure","blocking":[]} -->8.2.1https://gitlab.haskell.org/ghc/ghc/-/issues/13643Core lint error with TypeInType and TypeFamilyDependencies2019-07-07T18:20:49ZIcelandjackCore lint error with TypeInType and TypeFamilyDependenciesIn the code
```hs
{-# Language TypeFamilyDependencies #-}
{-# Language RankNTypes #-}
{-# Language KindSignatures #-}
{-# Language DataKinds #-}
{-# Language TypeInType #-}
{-# Language GADTs...In the code
```hs
{-# Language TypeFamilyDependencies #-}
{-# Language RankNTypes #-}
{-# Language KindSignatures #-}
{-# Language DataKinds #-}
{-# Language TypeInType #-}
{-# Language GADTs #-}
import Data.Kind (Type)
data Code = I
type family
Interp (a :: Code) = (res :: Type) | res -> a where
Interp I = Bool
data T :: forall a. Interp a -> Type where
MkNat :: T False
instance Show (T a) where show _ = "MkNat"
main = do
print MkNat
```
but add `{-# Options_GHC -dcore-lint #-}` and we get the attached log from running `runghc /tmp/tPb2.hs > /tmp/tPb2.log`.
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | ------------ |
| Version | 8.0.1 |
| Type | Bug |
| TypeOfFailure | OtherFailure |
| Priority | normal |
| Resolution | Unresolved |
| Component | Compiler |
| Test case | |
| Differential revisions | |
| BlockedBy | |
| Related | #12102 |
| Blocking | |
| CC | |
| Operating system | |
| Architecture | |
</details>
<!-- {"blocked_by":[],"summary":"Core lint error with TypeInType and TypeFamilyDependencies","status":"New","operating_system":"","component":"Compiler","related":[12102],"milestone":"","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"8.0.1","keywords":["InjectiveFamilies,","TypeInType"],"differentials":[],"test_case":"","architecture":"","cc":[""],"type":"Bug","description":"In the code\r\n\r\n{{{#!hs\r\n{-# Language TypeFamilyDependencies #-}\r\n{-# Language RankNTypes #-}\r\n{-# Language KindSignatures #-}\r\n{-# Language DataKinds #-}\r\n{-# Language TypeInType #-}\r\n{-# Language GADTs #-}\r\n\r\nimport Data.Kind (Type)\r\n\r\ndata Code = I\r\n\r\ntype family\r\n Interp (a :: Code) = (res :: Type) | res -> a where\r\n Interp I = Bool\r\n\r\ndata T :: forall a. Interp a -> Type where\r\n MkNat :: T False\r\n\r\ninstance Show (T a) where show _ = \"MkNat\"\r\n\r\nmain = do\r\n print MkNat\r\n}}}\r\n\r\nbut add `{-# Options_GHC -dcore-lint #-}` and we get the attached log from running `runghc /tmp/tPb2.hs > /tmp/tPb2.log`.\r\n","type_of_failure":"OtherFailure","blocking":[]} -->https://gitlab.haskell.org/ghc/ghc/-/issues/13650Implement KPush in types2021-10-04T14:41:09ZRichard Eisenbergrae@richarde.devImplement KPush in typesA recent commit contributed a Note (https://gitlab.haskell.org/ghc/ghc/-/commit/ef0ff34d462e3780210567a13d58b868ec3399e0#07ce9a046fb8ea6659690020b0a8551d94cfdf1c_1175_1163) that explains why we need the dreaded KPush rule to be implement...A recent commit contributed a Note (https://gitlab.haskell.org/ghc/ghc/-/commit/ef0ff34d462e3780210567a13d58b868ec3399e0#07ce9a046fb8ea6659690020b0a8551d94cfdf1c_1175_1163) that explains why we need the dreaded KPush rule to be implemented in `splitTyConApp`. Without KPush there, it's possible that we can have two types t1 and t2 such that `t1 `eqType` t2` and yet they respond differently to `splitTyConApp`: t1 = `(T |> co1) (a |> co2)` and t2 = `T a`. Both t1 and t2 are well-kinded and can have the same kind. But one is a `TyConApp` and one is an `AppTy`. (Actually, looking at this, perhaps the magic will be in `mkAppTy`, not `splitTyConApp`.) But I have to look closer.
This ticket serves as a reminder to do so.
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | ------------ |
| Version | |
| Type | Task |
| TypeOfFailure | OtherFailure |
| Priority | high |
| Resolution | Unresolved |
| Component | Compiler |
| Test case | |
| Differential revisions | |
| BlockedBy | |
| Related | |
| Blocking | |
| CC | |
| Operating system | |
| Architecture | |
</details>
<!-- {"blocked_by":[],"summary":"Implement KPush in types","status":"New","operating_system":"","component":"Compiler","related":[],"milestone":"8.4.1","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"","keywords":[],"differentials":[],"test_case":"","architecture":"","cc":[""],"type":"Task","description":"A recent commit contributed a [https://phabricator.haskell.org/diffusion/GHC/browse/master/compiler/types/Type.hs;a483e711da7834bc952367f554ac4e877b4e157a$1191 Note] that explains why we need the dreaded KPush rule to be implemented in `splitTyConApp`. Without KPush there, it's possible that we can have two types t1 and t2 such that {{{t1 `eqType` t2}}} and yet they respond differently to `splitTyConApp`: t1 = `(T |> co1) (a |> co2)` and t2 = `T a`. Both t1 and t2 are well-kinded and can have the same kind. But one is a `TyConApp` and one is an `AppTy`. (Actually, looking at this, perhaps the magic will be in `mkAppTy`, not `splitTyConApp`.) But I have to look closer.\r\n\r\nThis ticket serves as a reminder to do so.","type_of_failure":"OtherFailure","blocking":[]} -->8.6.1Richard Eisenbergrae@richarde.devRichard Eisenbergrae@richarde.devhttps://gitlab.haskell.org/ghc/ghc/-/issues/13674Poor error message which masks occurs-check failure2019-07-07T18:20:39ZRyan ScottPoor error message which masks occurs-check failureHere's some code, reduced from an example in https://github.com/ekmett/constraints/issues/55:
```hs
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE RankNTypes #-...Here's some code, reduced from an example in https://github.com/ekmett/constraints/issues/55:
```hs
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
import Data.Proxy
import GHC.Exts (Constraint)
import GHC.TypeLits
import Unsafe.Coerce (unsafeCoerce)
data Dict :: Constraint -> * where
Dict :: a => Dict a
infixr 9 :-
newtype a :- b = Sub (a => Dict b)
-- | Given that @a :- b@, derive something that needs a context @b@, using the context @a@
(\\) :: a => (b => r) -> (a :- b) -> r
r \\ Sub Dict = r
newtype Magic n = Magic (KnownNat n => Dict (KnownNat n))
magic :: forall n m o. (Integer -> Integer -> Integer) -> (KnownNat n, KnownNat m) :- KnownNat o
magic f = Sub $ unsafeCoerce (Magic Dict) (natVal (Proxy :: Proxy n) `f` natVal (Proxy :: Proxy m))
type family Lcm :: Nat -> Nat -> Nat where
axiom :: forall a b. Dict (a ~ b)
axiom = unsafeCoerce (Dict :: Dict (a ~ a))
lcmNat :: forall n m. (KnownNat n, KnownNat m) :- KnownNat (Lcm n m)
lcmNat = magic lcm
lcmIsIdempotent :: forall n. Dict (n ~ Lcm n n)
lcmIsIdempotent = axiom
newtype GF (n :: Nat) = GF Integer
instance KnownNat n => Num (GF n) where
xf@(GF x) + GF y = GF $ (x+y) `mod` (natVal xf)
xf@(GF x) - GF y = GF $ (x-y) `mod` (natVal xf)
xf@(GF x) * GF y = GF $ (x*y) `mod` (natVal xf)
abs = id
signum xf@(GF x) | x==0 = xf
| otherwise = GF 1
fromInteger = GF
x :: GF 5
x = GF 3
y :: GF 5
y = GF 4
foo :: (KnownNat m, KnownNat n) => GF m -> GF n -> GF (Lcm m n)
foo m@(GF x) n@(GF y) = GF $ (x*y) `mod` (lcm (natVal m) (natVal n))
bar :: (KnownNat m) => GF m -> GF m -> GF m
bar (x :: GF m) y = foo x y - foo y x \\ lcmNat @m @m \\ Sub @() (lcmIsIdempotent @m)
```
Compiling this (with either GHC 8.0.1, 8.0.2, 8.2.1, or HEAD) gives you a downright puzzling type error:
```
$ /opt/ghc/head/bin/ghci Bug.hs
GHCi, version 8.3.20170509: http://www.haskell.org/ghc/ :? for help
Loaded GHCi configuration from /home/rgscott/.ghci
[1 of 1] Compiling Main ( Bug.hs, interpreted )
Bug.hs:63:21: error:
• Couldn't match type ‘m’ with ‘Lcm m m’
‘m’ is a rigid type variable bound by
the type signature for:
bar :: forall (m :: Nat). KnownNat m => GF m -> GF m -> GF m
at Bug.hs:62:1-44
Expected type: GF m
Actual type: GF (Lcm m m)
• In the first argument of ‘(-)’, namely ‘foo x y’
In the expression:
foo x y - foo y x \\ lcmNat @m @m \\ Sub @() (lcmIsIdempotent @m)
In an equation for ‘bar’:
bar (x :: GF m) y
= foo x y - foo y x \\ lcmNat @m @m \\ Sub @() (lcmIsIdempotent @m)
• Relevant bindings include
y :: GF m (bound at Bug.hs:63:17)
x :: GF m (bound at Bug.hs:63:6)
bar :: GF m -> GF m -> GF m (bound at Bug.hs:63:1)
|
63 | bar (x :: GF m) y = foo x y - foo y x \\ lcmNat @m @m \\ Sub @() (lcmIsIdempotent @m)
| ^^^^^^^
Bug.hs:63:31: error:
• Could not deduce: m ~ Lcm m m
from the context: m ~ Lcm m m
bound by a type expected by the context:
m ~ Lcm m m => GF m
at Bug.hs:63:31-85
‘m’ is a rigid type variable bound by
the type signature for:
bar :: forall (m :: Nat). KnownNat m => GF m -> GF m -> GF m
at Bug.hs:62:1-44
Expected type: GF m
Actual type: GF (Lcm m m)
• In the first argument of ‘(\\)’, namely ‘foo y x’
In the first argument of ‘(\\)’, namely ‘foo y x \\ lcmNat @m @m’
In the second argument of ‘(-)’, namely
‘foo y x \\ lcmNat @m @m \\ Sub @() (lcmIsIdempotent @m)’
• Relevant bindings include
y :: GF m (bound at Bug.hs:63:17)
x :: GF m (bound at Bug.hs:63:6)
bar :: GF m -> GF m -> GF m (bound at Bug.hs:63:1)
|
63 | bar (x :: GF m) y = foo x y - foo y x \\ lcmNat @m @m \\ Sub @() (lcmIsIdempotent @m)
| ^^^^^^^
```
In particular, I'd like to emphasize this part:
```
• Could not deduce: m ~ Lcm m m
from the context: m ~ Lcm m m
```
Wat!? Surely, GHC can deduce `m ~ Lcm m m` from `m ~ Lcm m m`? I decided to flip on `-fprint-explicit-kinds` and see if there was some other issue lurking beneath the surface:
```
$ /opt/ghc/head/bin/ghci Bug.hs -fprint-explicit-kinds
GHCi, version 8.3.20170509: http://www.haskell.org/ghc/ :? for help
Loaded GHCi configuration from /home/rgscott/.ghci
[1 of 1] Compiling Main ( Bug.hs, interpreted )
Bug.hs:63:21: error:
• Couldn't match type ‘m’ with ‘Lcm m m’
‘m’ is a rigid type variable bound by
the type signature for:
bar :: forall (m :: Nat). KnownNat m => GF m -> GF m -> GF m
at Bug.hs:62:1-44
Expected type: GF m
Actual type: GF (Lcm m m)
• In the first argument of ‘(-)’, namely ‘foo x y’
In the expression:
foo x y - foo y x \\ lcmNat @m @m \\ Sub @() (lcmIsIdempotent @m)
In an equation for ‘bar’:
bar (x :: GF m) y
= foo x y - foo y x \\ lcmNat @m @m \\ Sub @() (lcmIsIdempotent @m)
• Relevant bindings include
y :: GF m (bound at Bug.hs:63:17)
x :: GF m (bound at Bug.hs:63:6)
bar :: GF m -> GF m -> GF m (bound at Bug.hs:63:1)
|
63 | bar (x :: GF m) y = foo x y - foo y x \\ lcmNat @m @m \\ Sub @() (lcmIsIdempotent @m)
| ^^^^^^^
Bug.hs:63:31: error:
• Could not deduce: (m :: Nat) ~~ (Lcm m m :: Nat)
from the context: m ~ Lcm m m
bound by a type expected by the context:
m ~ Lcm m m => GF m
at Bug.hs:63:31-85
‘m’ is a rigid type variable bound by
the type signature for:
bar :: forall (m :: Nat). KnownNat m => GF m -> GF m -> GF m
at Bug.hs:62:1-44
Expected type: GF m
Actual type: GF (Lcm m m)
• In the first argument of ‘(\\)’, namely ‘foo y x’
In the first argument of ‘(\\)’, namely ‘foo y x \\ lcmNat @m @m’
In the second argument of ‘(-)’, namely
‘foo y x \\ lcmNat @m @m \\ Sub @() (lcmIsIdempotent @m)’
• Relevant bindings include
y :: GF m (bound at Bug.hs:63:17)
x :: GF m (bound at Bug.hs:63:6)
bar :: GF m -> GF m -> GF m (bound at Bug.hs:63:1)
|
63 | bar (x :: GF m) y = foo x y - foo y x \\ lcmNat @m @m \\ Sub @() (lcmIsIdempotent @m)
|
```
Well, not a whole lot changed. We now have this, slightly more specific error instead:
```
• Could not deduce: (m :: Nat) ~~ (Lcm m m :: Nat)
from the context: m ~ Lcm m m
```
Huh, this is flummoxing. Surely `(m :: Nat) ~~ (Lcm m m :: Nat)` ought to be the same thing as `m ~ Lcm m m`, right?https://gitlab.haskell.org/ghc/ghc/-/issues/13761Can't create poly-kinded GADT with TypeInType enabled, but can without2019-07-07T18:20:12ZRyan ScottCan't create poly-kinded GADT with TypeInType enabled, but can withoutSurprisingly, this compiles without `TypeInType`:
```hs
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE PolyKinds #-}
module Works where
import Data.Kind
data T :: k -> Type where
MkT :...Surprisingly, this compiles without `TypeInType`:
```hs
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE PolyKinds #-}
module Works where
import Data.Kind
data T :: k -> Type where
MkT :: T Int
```
But once you add `TypeInType`:
```hs
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE TypeInType #-}
module Bug where
import Data.Kind
data T :: k -> Type where
MkT :: T Int
```
then it stops working!
```
GHCi, version 8.3.20170516: http://www.haskell.org/ghc/ :? for help
Loaded GHCi configuration from /home/rgscott/.ghci
[1 of 1] Compiling Bug ( Bug.hs, interpreted )
Bug.hs:11:12: error:
• Expected kind ‘k’, but ‘Int’ has kind ‘*’
• In the first argument of ‘T’, namely ‘Int’
In the type ‘T Int’
In the definition of data constructor ‘MkT’
|
11 | MkT :: T Int
| ^^^
```
This bug is present in GHC 8.0.1, 8.0.2, 8.2.1, and HEAD.
What's strange about this bug is that is requires that you write `T` with an explicit kind signature. If you write `T` like this:
```hs
data T (a :: k) where
MkT :: T Int
```
Then it will work with `TypeInType` enabled.
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | ----------------------- |
| Version | 8.0.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":"Can't create poly-kinded GADT with TypeInType enabled, but can without","status":"New","operating_system":"","component":"Compiler (Type checker)","related":[],"milestone":"","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"8.0.1","keywords":["TypeInType"],"differentials":[],"test_case":"","architecture":"","cc":[""],"type":"Bug","description":"Surprisingly, this compiles without `TypeInType`:\r\n\r\n{{{#!hs\r\n{-# LANGUAGE DataKinds #-}\r\n{-# LANGUAGE GADTs #-}\r\n{-# LANGUAGE KindSignatures #-}\r\n{-# LANGUAGE PolyKinds #-}\r\nmodule Works where\r\n\r\nimport Data.Kind\r\n\r\ndata T :: k -> Type where\r\n MkT :: T Int\r\n}}}\r\n\r\nBut once you add `TypeInType`:\r\n\r\n{{{#!hs\r\n{-# LANGUAGE DataKinds #-}\r\n{-# LANGUAGE GADTs #-}\r\n{-# LANGUAGE KindSignatures #-}\r\n{-# LANGUAGE PolyKinds #-}\r\n{-# LANGUAGE TypeInType #-}\r\nmodule Bug where\r\n\r\nimport Data.Kind\r\n\r\ndata T :: k -> Type where\r\n MkT :: T Int\r\n}}}\r\n\r\nthen it stops working!\r\n\r\n{{{\r\nGHCi, version 8.3.20170516: 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:11:12: error:\r\n • Expected kind ‘k’, but ‘Int’ has kind ‘*’\r\n • In the first argument of ‘T’, namely ‘Int’\r\n In the type ‘T Int’\r\n In the definition of data constructor ‘MkT’\r\n |\r\n11 | MkT :: T Int\r\n | ^^^\r\n}}}\r\n\r\nThis bug is present in GHC 8.0.1, 8.0.2, 8.2.1, and HEAD.\r\n\r\nWhat's strange about this bug is that is requires that you write `T` with an explicit kind signature. If you write `T` like this:\r\n\r\n{{{#!hs\r\ndata T (a :: k) where\r\n MkT :: T Int\r\n}}}\r\n\r\nThen it will work with `TypeInType` enabled.","type_of_failure":"OtherFailure","blocking":[]} -->https://gitlab.haskell.org/ghc/ghc/-/issues/13762TypeInType is not documented in the users' guide flag reference2019-07-07T18:20:12ZRyan ScottTypeInType is not documented in the users' guide flag referenceAt least, not as of http://git.haskell.org/ghc.git/blob/09d5c993aae208e3d34a9e715297922b6ea42b3f:/utils/mkUserGuidePart/Options/Language.hs. We should fix this.
<details><summary>Trac metadata</summary>
| Trac field | Value...At least, not as of http://git.haskell.org/ghc.git/blob/09d5c993aae208e3d34a9e715297922b6ea42b3f:/utils/mkUserGuidePart/Options/Language.hs. We should fix this.
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | ------------- |
| Version | 8.0.1 |
| Type | Bug |
| TypeOfFailure | OtherFailure |
| Priority | normal |
| Resolution | Unresolved |
| Component | Documentation |
| Test case | |
| Differential revisions | |
| BlockedBy | |
| Related | |
| Blocking | |
| CC | |
| Operating system | |
| Architecture | |
</details>
<!-- {"blocked_by":[],"summary":"TypeInType is not documented in the users' guide flag reference","status":"New","operating_system":"","component":"Documentation","related":[],"milestone":"","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"8.0.1","keywords":["TypeInType"],"differentials":[],"test_case":"","architecture":"","cc":[""],"type":"Bug","description":"At least, not as of http://git.haskell.org/ghc.git/blob/09d5c993aae208e3d34a9e715297922b6ea42b3f:/utils/mkUserGuidePart/Options/Language.hs. We should fix this.","type_of_failure":"OtherFailure","blocking":[]} -->8.2.1https://gitlab.haskell.org/ghc/ghc/-/issues/13777Poor error message around CUSKs2019-07-07T18:20:07ZRichard Eisenbergrae@richarde.devPoor error message around CUSKsWhile typing up [ticket:13761\#comment:137502](https://gitlab.haskell.org//ghc/ghc/issues/13761#note_137502), I came across a poor error message around CUSKs.
```
data Proxy (a :: k) = P
data S :: forall k. Proxy k -> Type where
MkS :...While typing up [ticket:13761\#comment:137502](https://gitlab.haskell.org//ghc/ghc/issues/13761#note_137502), I came across a poor error message around CUSKs.
```
data Proxy (a :: k) = P
data S :: forall k. Proxy k -> Type where
MkS :: S (P :: Proxy Maybe)
```
produces
```
You have written a *complete user-suppled kind signature*,
but the following variable is undetermined: k0 :: *
Perhaps add a kind signature.
Inferred kinds of user-written variables:
```
That promised list of the kinds of user-written variables is empty. Either GHC should find something to print (like `k :: k0`, perhaps) or omit the header.
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | ------------ |
| Version | 8.2.1-rc2 |
| 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":"Poor error message around CUSKs","status":"New","operating_system":"","component":"Compiler","related":[],"milestone":"","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"8.2.1-rc2","keywords":["CUSKs","TypeInType,"],"differentials":[],"test_case":"","architecture":"","cc":[""],"type":"Bug","description":"While typing up comment:7:ticket:13761, I came across a poor error message around CUSKs.\r\n\r\n{{{\r\ndata Proxy (a :: k) = P\r\ndata S :: forall k. Proxy k -> Type where\r\n MkS :: S (P :: Proxy Maybe)\r\n}}}\r\n\r\nproduces\r\n\r\n{{{\r\n You have written a *complete user-suppled kind signature*,\r\n but the following variable is undetermined: k0 :: *\r\n Perhaps add a kind signature.\r\n Inferred kinds of user-written variables:\r\n}}}\r\n\r\nThat promised list of the kinds of user-written variables is empty. Either GHC should find something to print (like `k :: k0`, perhaps) or omit the header.","type_of_failure":"OtherFailure","blocking":[]} -->8.6.1https://gitlab.haskell.org/ghc/ghc/-/issues/13780Nightmarish pretty-printing of equality type in GHC 8.2 error message2019-07-07T18:20:06ZRyan ScottNightmarish pretty-printing of equality type in GHC 8.2 error messageI originally spotted this in #12102\##13780, but I happened to stumble upon it again recently in a separate context, so I though it deserved its own ticket. Here's some code which does not typecheck:
```hs
{-# LANGUAGE ExistentialQuanti...I originally spotted this in #12102\##13780, but I happened to stumble upon it again recently in a separate context, so I though it deserved its own ticket. Here's some code which does not typecheck:
```hs
{-# LANGUAGE ExistentialQuantification #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeInType #-}
module Foo where
data family Sing (a :: k)
data Foo a = a ~ Bool => MkFoo
data instance Sing (z :: Foo a) = (z ~ MkFoo) => SMkFoo
```
In GHC 8.0.1 and 8.0.2, the error message you'd get from this program was reasonable enough:
```
GHCi, version 8.0.2: http://www.haskell.org/ghc/ :? for help
Loaded GHCi configuration from /home/rgscott/.ghci
[1 of 1] Compiling Foo ( Bug.hs, interpreted )
Bug.hs:9:40: error:
• Expected kind ‘Foo a’, but ‘'MkFoo’ has kind ‘Foo Bool’
• In the second argument of ‘~’, namely ‘MkFoo’
In the definition of data constructor ‘SMkFoo’
In the data instance declaration for ‘Sing’
```
But in GHC 8.2.1 and HEAD, it's hair-raisingly bad:
```
GHCi, version 8.2.0.20170522: http://www.haskell.org/ghc/ :? for help
Loaded GHCi configuration from /home/rgscott/.ghci
[1 of 1] Compiling Foo ( Bug.hs, interpreted )
Bug.hs:9:40: error:
• Expected kind ‘Foo a’,
but ‘'MkFoo
('Data.Type.Equality.C:~ ('GHC.Types.Eq# <>))’ has kind ‘Foo Bool’
• In the second argument of ‘~’, namely ‘MkFoo’
In the definition of data constructor ‘SMkFoo’
In the data instance declaration for ‘Sing’
|
9 | data instance Sing (z :: Foo a) = (z ~ MkFoo) => SMkFoo
| ^^^^^
```
- \*WAT.\*\*
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | ----------------------- |
| Version | 8.2.1-rc2 |
| 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":"Nightmarish pretty-printing of equality type in GHC 8.2 error message","status":"New","operating_system":"","component":"Compiler (Type checker)","related":[],"milestone":"","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"8.2.1-rc2","keywords":["TypeInType"],"differentials":[],"test_case":"","architecture":"","cc":[""],"type":"Bug","description":"I originally spotted this in https://ghc.haskell.org/trac/ghc/ticket/12102#comment:1, but I happened to stumble upon it again recently in a separate context, so I though it deserved its own ticket. Here's some code which does not typecheck:\r\n\r\n{{{#!hs\r\n{-# LANGUAGE ExistentialQuantification #-}\r\n{-# LANGUAGE TypeFamilies #-}\r\n{-# LANGUAGE TypeInType #-}\r\nmodule Foo where\r\n\r\ndata family Sing (a :: k)\r\n\r\ndata Foo a = a ~ Bool => MkFoo\r\ndata instance Sing (z :: Foo a) = (z ~ MkFoo) => SMkFoo\r\n}}}\r\n\r\nIn GHC 8.0.1 and 8.0.2, the error message you'd get from this program was reasonable enough:\r\n\r\n{{{\r\nGHCi, version 8.0.2: http://www.haskell.org/ghc/ :? for help\r\nLoaded GHCi configuration from /home/rgscott/.ghci\r\n[1 of 1] Compiling Foo ( Bug.hs, interpreted )\r\n\r\nBug.hs:9:40: error:\r\n • Expected kind ‘Foo a’, but ‘'MkFoo’ has kind ‘Foo Bool’\r\n • In the second argument of ‘~’, namely ‘MkFoo’\r\n In the definition of data constructor ‘SMkFoo’\r\n In the data instance declaration for ‘Sing’\r\n}}}\r\n\r\nBut in GHC 8.2.1 and HEAD, it's hair-raisingly bad:\r\n\r\n{{{\r\nGHCi, version 8.2.0.20170522: http://www.haskell.org/ghc/ :? for help\r\nLoaded GHCi configuration from /home/rgscott/.ghci\r\n[1 of 1] Compiling Foo ( Bug.hs, interpreted )\r\n\r\nBug.hs:9:40: error:\r\n • Expected kind ‘Foo a’,\r\n but ‘'MkFoo\r\n ('Data.Type.Equality.C:~ ('GHC.Types.Eq# <>))’ has kind ‘Foo Bool’\r\n • In the second argument of ‘~’, namely ‘MkFoo’\r\n In the definition of data constructor ‘SMkFoo’\r\n In the data instance declaration for ‘Sing’\r\n |\r\n9 | data instance Sing (z :: Foo a) = (z ~ MkFoo) => SMkFoo\r\n | ^^^^^\r\n}}}\r\n\r\n**WAT.**","type_of_failure":"OtherFailure","blocking":[]} -->8.4.1Richard Eisenbergrae@richarde.devRichard Eisenbergrae@richarde.devhttps://gitlab.haskell.org/ghc/ghc/-/issues/13781(a :: (k :: Type)) is too exotic for Template Haskell2019-07-07T18:20:06ZRyan Scott(a :: (k :: Type)) is too exotic for Template HaskellOn GHC 8.0.1 or later, GHC will choke on this code:
```hs
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeInType #-}
module Bug where
import Data.Kind
import Data.Proxy
$([d| f :: Proxy (a :: (k :: Type))
f = Proxy
|])
```...On GHC 8.0.1 or later, GHC will choke on this code:
```hs
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeInType #-}
module Bug where
import Data.Kind
import Data.Proxy
$([d| f :: Proxy (a :: (k :: Type))
f = Proxy
|])
```
```
GHCi, version 8.2.0.20170522: http://www.haskell.org/ghc/ :? for help
Loaded GHCi configuration from /home/rgscott/.ghci
[1 of 1] Compiling Bug ( Bug.hs, interpreted )
Bug.hs:8:3: error:
Exotic form of kind not (yet) handled by Template Haskell
(k :: Type)
|
8 | $([d| f :: Proxy (a :: (k :: Type))
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^...
```
I don't think this would be too hard to support, though. I'll take a shot at fixing this.
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | ---------------- |
| Version | 8.0.1 |
| Type | Bug |
| TypeOfFailure | OtherFailure |
| Priority | normal |
| Resolution | Unresolved |
| Component | Template Haskell |
| Test case | |
| Differential revisions | |
| BlockedBy | |
| Related | |
| Blocking | |
| CC | |
| Operating system | |
| Architecture | |
</details>
<!-- {"blocked_by":[],"summary":"(a :: (k :: Type)) is too exotic for Template Haskell","status":"New","operating_system":"","component":"Template Haskell","related":[],"milestone":"","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"8.0.1","keywords":["TypeInType"],"differentials":[],"test_case":"","architecture":"","cc":[""],"type":"Bug","description":"On GHC 8.0.1 or later, GHC will choke on this code:\r\n\r\n{{{#!hs\r\n{-# LANGUAGE TemplateHaskell #-}\r\n{-# LANGUAGE TypeInType #-}\r\nmodule Bug where\r\n\r\nimport Data.Kind\r\nimport Data.Proxy\r\n\r\n$([d| f :: Proxy (a :: (k :: Type))\r\n f = Proxy\r\n |])\r\n}}}\r\n\r\n{{{\r\nGHCi, version 8.2.0.20170522: 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:8:3: error:\r\n Exotic form of kind not (yet) handled by Template Haskell\r\n (k :: Type)\r\n |\r\n8 | $([d| f :: Proxy (a :: (k :: Type))\r\n | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^...\r\n}}}\r\n\r\nI don't think this would be too hard to support, though. I'll take a shot at fixing this.","type_of_failure":"OtherFailure","blocking":[]} -->8.4.1Ryan ScottRyan Scotthttps://gitlab.haskell.org/ghc/ghc/-/issues/13790GHC doesn't reduce type family in kind signature unless its arm is twisted2019-07-07T18:20:04ZRyan ScottGHC doesn't reduce type family in kind signature unless its arm is twistedHere's some code (inspired by Richard's musings [here](https://github.com/goldfirere/singletons/issues/150#issuecomment-306088297)) which typechecks with GHC 8.2.1 or HEAD:
```hs
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GADTs #-}...Here's some code (inspired by Richard's musings [here](https://github.com/goldfirere/singletons/issues/150#issuecomment-306088297)) which typechecks with GHC 8.2.1 or HEAD:
```hs
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeInType #-}
module Bug where
import Data.Kind
data family Sing (a :: k)
data SomeSing (k :: Type) where
SomeSing :: Sing (a :: k) -> SomeSing k
type family Promote k :: Type
class (Promote (Demote k) ~ k) => SingKind (k :: Type) where
type Demote k :: Type
fromSing :: Sing (a :: k) -> Demote k
toSing :: Demote k -> SomeSing k
type family DemoteX (a :: k) :: Demote k
type instance DemoteX (a :: Type) = Demote a
type instance Promote Type = Type
instance SingKind Type where
type Demote Type = Type
fromSing = error "fromSing Type"
toSing = error "toSing Type"
-----
data N = Z | S N
data instance Sing (z :: N) where
SZ :: Sing Z
SS :: Sing n -> Sing (S n)
type instance Promote N = N
instance SingKind N where
type Demote N = N
fromSing SZ = Z
fromSing (SS n) = S (fromSing n)
toSing Z = SomeSing SZ
toSing (S n) = case toSing n of
SomeSing sn -> SomeSing (SS sn)
```
Things get more interesting if you try to add this type instance at the end of this file:
```hs
type instance DemoteX (n :: N) = n
```
Now GHC will complain:
```
GHCi, version 8.2.0.20170522: http://www.haskell.org/ghc/ :? for help
Loaded GHCi configuration from /home/rgscott/.ghci
[1 of 1] Compiling Bug ( Bug.hs, interpreted )
Bug.hs:49:34: error:
• Expected kind ‘Demote N’, but ‘n’ has kind ‘N’
• In the type ‘n’
In the type instance declaration for ‘DemoteX’
|
49 | type instance DemoteX (n :: N) = n
| ^
```
That error message smells funny, since we do have a type family instance that says `Demote N = N`! In fact, if you use Template Haskell to split up the declarations manually:
```hs
...
instance SingKind N where
type Demote N = N
fromSing SZ = Z
fromSing (SS n) = S (fromSing n)
toSing Z = SomeSing SZ
toSing (S n) = case toSing n of
SomeSing sn -> SomeSing (SS sn)
$(return [])
type instance DemoteX (n :: N) = n
```
Then the file typechecks without issue.
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | ----------------------- |
| Version | 8.2.1-rc2 |
| 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 doesn't reduce type family in kind signature unless its arm is twisted","status":"New","operating_system":"","component":"Compiler (Type checker)","related":[],"milestone":"","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"8.2.1-rc2","keywords":["TypeFamilies","TypeInType,"],"differentials":[],"test_case":"","architecture":"","cc":[""],"type":"Bug","description":"Here's some code (inspired by Richard's musings [https://github.com/goldfirere/singletons/issues/150#issuecomment-306088297 here]) which typechecks with GHC 8.2.1 or HEAD:\r\n\r\n{{{#!hs\r\n{-# LANGUAGE FlexibleInstances #-}\r\n{-# LANGUAGE GADTs #-}\r\n{-# LANGUAGE TemplateHaskell #-}\r\n{-# LANGUAGE TypeFamilies #-}\r\n{-# LANGUAGE TypeInType #-}\r\nmodule Bug where\r\n\r\nimport Data.Kind\r\n\r\ndata family Sing (a :: k)\r\n\r\ndata SomeSing (k :: Type) where\r\n SomeSing :: Sing (a :: k) -> SomeSing k\r\n\r\ntype family Promote k :: Type\r\n\r\nclass (Promote (Demote k) ~ k) => SingKind (k :: Type) where\r\n type Demote k :: Type\r\n fromSing :: Sing (a :: k) -> Demote k\r\n toSing :: Demote k -> SomeSing k\r\n\r\ntype family DemoteX (a :: k) :: Demote k\r\ntype instance DemoteX (a :: Type) = Demote a\r\n\r\ntype instance Promote Type = Type\r\n\r\ninstance SingKind Type where\r\n type Demote Type = Type\r\n fromSing = error \"fromSing Type\"\r\n toSing = error \"toSing Type\"\r\n\r\n-----\r\n\r\ndata N = Z | S N\r\n\r\ndata instance Sing (z :: N) where\r\n SZ :: Sing Z\r\n SS :: Sing n -> Sing (S n)\r\ntype instance Promote N = N\r\n\r\ninstance SingKind N where\r\n type Demote N = N\r\n fromSing SZ = Z\r\n fromSing (SS n) = S (fromSing n)\r\n toSing Z = SomeSing SZ\r\n toSing (S n) = case toSing n of\r\n SomeSing sn -> SomeSing (SS sn)\r\n}}}\r\n\r\nThings get more interesting if you try to add this type instance at the end of this file:\r\n\r\n{{{#!hs\r\ntype instance DemoteX (n :: N) = n\r\n}}}\r\n\r\nNow GHC will complain:\r\n\r\n{{{\r\nGHCi, version 8.2.0.20170522: 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:49:34: error:\r\n • Expected kind ‘Demote N’, but ‘n’ has kind ‘N’\r\n • In the type ‘n’\r\n In the type instance declaration for ‘DemoteX’\r\n |\r\n49 | type instance DemoteX (n :: N) = n\r\n | ^\r\n}}}\r\n\r\nThat error message smells funny, since we do have a type family instance that says `Demote N = N`! In fact, if you use Template Haskell to split up the declarations manually:\r\n\r\n{{{#!hs\r\n...\r\n\r\ninstance SingKind N where\r\n type Demote N = N\r\n fromSing SZ = Z\r\n fromSing (SS n) = S (fromSing n)\r\n toSing Z = SomeSing SZ\r\n toSing (S n) = case toSing n of\r\n SomeSing sn -> SomeSing (SS sn)\r\n$(return [])\r\ntype instance DemoteX (n :: N) = n\r\n}}}\r\n\r\nThen the file typechecks without issue.","type_of_failure":"OtherFailure","blocking":[]} -->https://gitlab.haskell.org/ghc/ghc/-/issues/13822GHC not using injectivity?2019-07-07T18:19:56ZIcelandjackGHC not using injectivity?This may be normal behavior but.. (Example from [System FC with Explicit Kind Equality](http://repository.brynmawr.edu/cgi/viewcontent.cgi?article=1014&context=compsci_pubs))
```hs
{-# LANGUAGE GADTs, TypeOperators, PolyKinds, DataKinds...This may be normal behavior but.. (Example from [System FC with Explicit Kind Equality](http://repository.brynmawr.edu/cgi/viewcontent.cgi?article=1014&context=compsci_pubs))
```hs
{-# LANGUAGE GADTs, TypeOperators, PolyKinds, DataKinds, TypeFamilyDependencies, TypeInType, RankNTypes, LambdaCase, EmptyCase #-}
import Data.Kind
data KIND = STAR | KIND :> KIND
data Ty :: KIND -> Type where
TInt :: Ty STAR
TBool :: Ty STAR
TMaybe :: Ty (STAR :> STAR)
TApp :: Ty (a :> b) -> (Ty a -> Ty b)
type family
IK (k :: KIND) = (res :: Type) | res -> k where
IK STAR = Type
IK (a:>b) = IK a -> IK b
type family
I (t :: Ty k) = (res :: IK k) | res -> t where
I TInt = Int
I TBool = Bool
I TMaybe = Maybe
I (TApp f a) = (I f) (I a)
data TyRep (k :: KIND) (t :: Ty k) where
TyInt :: TyRep STAR TInt
TyBool :: TyRep STAR TBool
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 = \case
TyInt -> 0
TyBool -> False
TyApp TyMaybe _ -> Nothing
```
When I ask it to infer the representation for `Int` and `Bool` it does so with no surprises
```hs
-- Inferred type:
--
-- int :: TyRep STAR TInt -> Int
int rep = zero rep :: Int
-- bool:: TyRep STAR TBool -> Bool
bool rep = zero rep :: Bool
```
but inferring the representation for `Maybe Int` fails
```hs
-- v.hs:43:16: error:
-- • Couldn't match kind ‘k’ with ‘'STAR’
-- ‘k’ is a rigid type variable bound by
-- the inferred type of
-- maybeInt :: (I 'TInt ~ Int, I 'TMaybe ~ Maybe) =>
-- TyRep 'STAR ('TApp 'TMaybe 'TInt) -> Maybe Int
-- at v.hs:25:3
-- When matching the kind of ‘'TMaybe’
-- Expected type: Maybe Int
-- Actual type: I ('TApp 'TMaybe 'TInt)
-- • In the expression: zero rep :: Maybe Int
-- In an equation for ‘maybeInt’: maybeInt rep = zero rep :: Maybe Int
-- • Relevant bindings include
-- rep :: TyRep 'STAR ('TApp 'TMaybe 'TInt) (bound at v.hs:43:10)
-- maybeInt :: TyRep 'STAR ('TApp 'TMaybe 'TInt) -> Maybe Int
-- (bound at v.hs:43:1)
-- Failed, modules loaded: none.
maybeInt rep = zero rep :: Maybe Int
```
even though `I` is injective and GHC knows that `I (TMaybe `TApp` TMaybe) = Maybe Int`
```
>>> :kind! I (TMaybe `TApp` TInt)
I (TMaybe `TApp` TInt) :: IK 'STAR
= Maybe Int
```
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | ------------ |
| Version | 8.0.1 |
| 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":"GHC not using injectivity?","status":"New","operating_system":"","component":"Compiler","related":[],"milestone":"","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"8.0.1","keywords":["InjectiveFamilies,","TypeInType"],"differentials":[],"test_case":"","architecture":"","cc":[""],"type":"Bug","description":"This may be normal behavior but.. (Example from [http://repository.brynmawr.edu/cgi/viewcontent.cgi?article=1014&context=compsci_pubs System FC with Explicit Kind Equality])\r\n\r\n{{{#!hs\r\n{-# LANGUAGE GADTs, TypeOperators, PolyKinds, DataKinds, TypeFamilyDependencies, TypeInType, RankNTypes, LambdaCase, EmptyCase #-}\r\n\r\nimport Data.Kind\r\n\r\ndata KIND = STAR | KIND :> KIND\r\n\r\ndata Ty :: KIND -> Type where\r\n TInt :: Ty STAR\r\n TBool :: Ty STAR\r\n TMaybe :: Ty (STAR :> STAR)\r\n TApp :: Ty (a :> b) -> (Ty a -> Ty b)\r\n\r\ntype family\r\n IK (k :: KIND) = (res :: Type) | res -> k where\r\n IK STAR = Type\r\n IK (a:>b) = IK a -> IK b\r\n\r\ntype family\r\n I (t :: Ty k) = (res :: IK k) | res -> t where\r\n I TInt = Int\r\n I TBool = Bool\r\n I TMaybe = Maybe\r\n I (TApp f a) = (I f) (I a)\r\n\r\ndata TyRep (k :: KIND) (t :: Ty k) where\r\n TyInt :: TyRep STAR TInt\r\n TyBool :: TyRep STAR TBool\r\n TyMaybe :: TyRep (STAR:>STAR) TMaybe\r\n TyApp :: TyRep (a:>b) f -> TyRep a x -> TyRep b (TApp f x)\r\n\r\nzero :: TyRep STAR a -> I a\r\nzero = \\case\r\n TyInt -> 0\r\n TyBool -> False\r\n TyApp TyMaybe _ -> Nothing\r\n}}}\r\n\r\nWhen I ask it to infer the representation for `Int` and `Bool` it does so with no surprises\r\n\r\n{{{#!hs\r\n-- Inferred type: \r\n-- \r\n-- int :: TyRep STAR TInt -> Int\r\nint rep = zero rep :: Int\r\n\r\n\r\n-- bool:: TyRep STAR TBool -> Bool\r\nbool rep = zero rep :: Bool\r\n}}}\r\n\r\nbut inferring the representation for `Maybe Int` fails\r\n\r\n{{{#!hs\r\n-- v.hs:43:16: error:\r\n-- • Couldn't match kind ‘k’ with ‘'STAR’\r\n-- ‘k’ is a rigid type variable bound by\r\n-- the inferred type of\r\n-- maybeInt :: (I 'TInt ~ Int, I 'TMaybe ~ Maybe) =>\r\n-- TyRep 'STAR ('TApp 'TMaybe 'TInt) -> Maybe Int\r\n-- at v.hs:25:3\r\n-- When matching the kind of ‘'TMaybe’\r\n-- Expected type: Maybe Int\r\n-- Actual type: I ('TApp 'TMaybe 'TInt)\r\n-- • In the expression: zero rep :: Maybe Int\r\n-- In an equation for ‘maybeInt’: maybeInt rep = zero rep :: Maybe Int\r\n-- • Relevant bindings include\r\n-- rep :: TyRep 'STAR ('TApp 'TMaybe 'TInt) (bound at v.hs:43:10)\r\n-- maybeInt :: TyRep 'STAR ('TApp 'TMaybe 'TInt) -> Maybe Int\r\n-- (bound at v.hs:43:1)\r\n-- Failed, modules loaded: none.\r\nmaybeInt rep = zero rep :: Maybe Int\r\n}}}\r\n\r\neven though `I` is injective and GHC knows that `I (TMaybe `TApp` TMaybe) = Maybe Int`\r\n\r\n{{{\r\n>>> :kind! I (TMaybe `TApp` TInt)\r\nI (TMaybe `TApp` TInt) :: IK 'STAR\r\n= Maybe Int\r\n}}}","type_of_failure":"OtherFailure","blocking":[]} -->8.2.1https://gitlab.haskell.org/ghc/ghc/-/issues/13871GHC panic in 8.2 only: typeIsTypeable(Coercion)2019-07-07T18:19:45ZRyan ScottGHC panic in 8.2 only: typeIsTypeable(Coercion)This code works fine in GHC 8.0.1 and 8.0.2:
```hs
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeInType #-}
{-# LANGUAGE TypeOperators #-}
module Foo where
import Data.Kind
data...This code works fine in GHC 8.0.1 and 8.0.2:
```hs
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeInType #-}
{-# LANGUAGE TypeOperators #-}
module Foo where
import Data.Kind
data Foo (a :: Type) (b :: Type) where
MkFoo :: (a ~ Int, b ~ Char) => Foo a b
data family Sing (a :: k)
data SFoo (z :: Foo a b) where
SMkFoo :: SFoo MkFoo
```
But in GHC 8.2 and HEAD, it panics:
```
$ /opt/ghc/8.2.1/bin/ghci Bug.hs
GHCi, version 8.2.0.20170622: http://www.haskell.org/ghc/ :? for help
Loaded GHCi configuration from /home/rgscott/.ghci
[1 of 1] Compiling Foo ( Bug.hs, interpreted )
ghc: panic! (the 'impossible' happened)
(GHC version 8.2.0.20170622 for x86_64-unknown-linux):
typeIsTypeable(Coercion)
```
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | ----------------------- |
| Version | 8.2.1-rc2 |
| 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 panic in 8.2 only: typeIsTypeable(Coercion)","status":"New","operating_system":"","component":"Compiler (Type checker)","related":[],"milestone":"8.2.1","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"8.2.1-rc2","keywords":["TypeInType,","Typeable"],"differentials":[],"test_case":"","architecture":"","cc":[""],"type":"Bug","description":"This code works fine in GHC 8.0.1 and 8.0.2:\r\n\r\n{{{#!hs\r\n{-# LANGUAGE ConstraintKinds #-}\r\n{-# LANGUAGE GADTs #-}\r\n{-# LANGUAGE TypeFamilies #-}\r\n{-# LANGUAGE TypeInType #-}\r\n{-# LANGUAGE TypeOperators #-}\r\nmodule Foo where\r\n\r\nimport Data.Kind\r\n\r\ndata Foo (a :: Type) (b :: Type) where\r\n MkFoo :: (a ~ Int, b ~ Char) => Foo a b\r\n\r\ndata family Sing (a :: k)\r\ndata SFoo (z :: Foo a b) where\r\n SMkFoo :: SFoo MkFoo\r\n}}}\r\n\r\nBut in GHC 8.2 and HEAD, it panics:\r\n\r\n{{{\r\n$ /opt/ghc/8.2.1/bin/ghci Bug.hs\r\nGHCi, version 8.2.0.20170622: http://www.haskell.org/ghc/ :? for help\r\nLoaded GHCi configuration from /home/rgscott/.ghci\r\n[1 of 1] Compiling Foo ( Bug.hs, interpreted )\r\nghc: panic! (the 'impossible' happened)\r\n (GHC version 8.2.0.20170622 for x86_64-unknown-linux):\r\n\ttypeIsTypeable(Coercion)\r\n}}}","type_of_failure":"OtherFailure","blocking":[]} -->8.2.1Ben GamariBen Gamarihttps://gitlab.haskell.org/ghc/ghc/-/issues/13872Strange Typeable error message involving TypeInType2019-07-07T18:19:44ZRyan ScottStrange Typeable error message involving TypeInTypeI originally discovered this when tinkering with #13871. This program:
```hs
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeInType #-}
{-# LANGUAGE TypeOperators #-}
module Foo whe...I originally discovered this when tinkering with #13871. This program:
```hs
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeInType #-}
{-# LANGUAGE TypeOperators #-}
module Foo where
import Data.Kind
import Data.Typeable
data Foo (a :: Type) (b :: Type) where
MkFoo :: (a ~ Int, b ~ Char) => Foo a b
data family Sing (a :: k)
data SFoo (z :: Foo a b) where
SMkFoo :: SFoo MkFoo
f :: String
f = show $ typeOf SMkFoo
```
Fails in GHC 8.0.1, 8.0.2, and 8.2 (after applying [D3671](https://phabricator.haskell.org/D3671)) with a rather unsightly error message:
```
GHCi, version 8.3.20170624: http://www.haskell.org/ghc/ :? for help
Loaded GHCi configuration from /home/rgscott/.ghci
[1 of 1] Compiling Foo ( Foo.hs, interpreted )
Foo.hs:19:12: error:
• No instance for (Typeable <>) arising from a use of ‘typeOf’
• In the second argument of ‘($)’, namely ‘typeOf SMkFoo’
In the expression: show $ typeOf SMkFoo
In an equation for ‘f’: f = show $ typeOf SMkFoo
|
19 | f = show $ typeOf SMkFoo
| ^^^^^^^^^^^^^
```
I'm not sure what this mysterious `<>` is, but I'm pretty sure it shouldn't be making an appearance here. (See also #13780, where `<>` also makes a surprise guest appearance.)
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | ----------------------- |
| Version | 8.0.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":"Strange Typeable error message involving TypeInType","status":"New","operating_system":"","component":"Compiler (Type checker)","related":[],"milestone":"","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"8.0.1","keywords":["TypeInType,","Typeable"],"differentials":[],"test_case":"","architecture":"","cc":[""],"type":"Bug","description":"I originally discovered this when tinkering with #13871. This program:\r\n\r\n{{{#!hs\r\n{-# LANGUAGE ConstraintKinds #-}\r\n{-# LANGUAGE GADTs #-}\r\n{-# LANGUAGE TypeFamilies #-}\r\n{-# LANGUAGE TypeInType #-}\r\n{-# LANGUAGE TypeOperators #-}\r\nmodule Foo where\r\n\r\nimport Data.Kind\r\nimport Data.Typeable\r\n\r\ndata Foo (a :: Type) (b :: Type) where\r\n MkFoo :: (a ~ Int, b ~ Char) => Foo a b\r\n\r\ndata family Sing (a :: k)\r\ndata SFoo (z :: Foo a b) where\r\n SMkFoo :: SFoo MkFoo\r\n\r\nf :: String\r\nf = show $ typeOf SMkFoo\r\n}}}\r\n\r\nFails in GHC 8.0.1, 8.0.2, and 8.2 (after applying Phab:D3671) with a rather unsightly error message:\r\n\r\n{{{\r\nGHCi, version 8.3.20170624: http://www.haskell.org/ghc/ :? for help\r\nLoaded GHCi configuration from /home/rgscott/.ghci\r\n[1 of 1] Compiling Foo ( Foo.hs, interpreted )\r\n\r\nFoo.hs:19:12: error:\r\n • No instance for (Typeable <>) arising from a use of ‘typeOf’\r\n • In the second argument of ‘($)’, namely ‘typeOf SMkFoo’\r\n In the expression: show $ typeOf SMkFoo\r\n In an equation for ‘f’: f = show $ typeOf SMkFoo\r\n |\r\n19 | f = show $ typeOf SMkFoo\r\n | ^^^^^^^^^^^^^\r\n}}}\r\n\r\nI'm not sure what this mysterious `<>` is, but I'm pretty sure it shouldn't be making an appearance here. (See also #13780, where `<>` also makes a surprise guest appearance.)","type_of_failure":"OtherFailure","blocking":[]} -->