GHC issueshttps://gitlab.haskell.org/ghc/ghc//issues20190707T18:01:03Zhttps://gitlab.haskell.org/ghc/ghc//issues/16184GHC said to report a bug20190707T18:01:03ZTheKing01GHC said to report a bugI tried to run
```hs
{# LANGUAGE Rank2Types, PartialTypeSignatures #}
import Control.Monad
newtype Search b = Search {optimum :: forall a. Ord a => (b > a) > b}
instance Monad Search where
return a = Search $ const a
Search ma >>= f = Search $ \p >
optimum (f (ma (\a > p (optimum (f a) p)))) p
instance Functor Search where
fmap = liftM
instance Applicative Search where
pure = return
(<*>) = ap
pair a b = Search $ \p > if p a >= p b then a else b
toList s = igo [] where
igo ls = let x = optimum s (\x' > x' `notElem` ls) in if x `elem` ls then ls else igo (x:ls)
cantor :: Search (Integer > Bool)
cantor = let
igo :: _
igo p n = q n (optimum cantor $ q n) where
q n a = p undefined
in Search igo
main = return ()
```
When run, it said
```
source_file.hs:24:5:
No instance for (Ord a)
When checking that ‘igo’ has the specified type
igo :: forall t a t1. (t > a) > t1 > a
Probable cause: the inferred type is ambiguous
In the expression:
let
igo :: _
igo p n
= q n (optimum cantor $ q n)
where
q n a = ...
in Search igo
In an equation for ‘cantor’:
cantor
= let
igo :: _
igo p n
= q n (optimum cantor $ q n)
where
...
in Search igo
source_file.hs:26:15:
Couldn't match type ‘t’ with ‘Integer > Bool’
‘t’ is untouchable
inside the constraints (Ord a1)
bound by a type expected by the context:
Ord a1 => ((Integer > Bool) > a1) > Integer > Bool
at source_file.hs:26:817ghc: panic! (the 'impossible' happened)
(GHC version 7.10.3 for x86_64unknownlinux):
No skolem info: t_aU3[sk]
Please report this as a GHC bug: http://www.haskell.org/ghc/reportabug
```
Since it said to report a bug, I am.
<details><summary>Trac metadata</summary>
 Trac field  Value 
    
 Version  7.10.3 
 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 said to report a bug","status":"New","operating_system":"","component":"Compiler (Type checker)","related":[],"milestone":"","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"7.10.3","keywords":["panic,","skolem"],"differentials":[],"test_case":"","architecture":"","cc":[""],"type":"Bug","description":"I tried to run\r\n{{{#!hs\r\n{# LANGUAGE Rank2Types, PartialTypeSignatures #}\r\nimport Control.Monad\r\nnewtype Search b = Search {optimum :: forall a. Ord a => (b > a) > b}\r\n\r\ninstance Monad Search where\r\n return a = Search $ const a\r\n Search ma >>= f = Search $ \\p >\r\n optimum (f (ma (\\a > p (optimum (f a) p)))) p\r\n\r\ninstance Functor Search where\r\n fmap = liftM\r\n\r\ninstance Applicative Search where\r\n pure = return\r\n (<*>) = ap\r\n\r\npair a b = Search $ \\p > if p a >= p b then a else b\r\ntoList s = igo [] where\r\n igo ls = let x = optimum s (\\x' > x' `notElem` ls) in if x `elem` ls then ls else igo (x:ls)\r\n\r\ncantor :: Search (Integer > Bool)\r\ncantor = let\r\n igo :: _\r\n igo p n = q n (optimum cantor $ q n) where\r\n q n a = p undefined\r\n in Search igo\r\n\r\nmain = return ()\r\n}}}\r\n\r\nWhen run, it said\r\n\r\n{{{\r\nsource_file.hs:24:5:\r\n No instance for (Ord a)\r\n When checking that ‘igo’ has the specified type\r\n igo :: forall t a t1. (t > a) > t1 > a\r\n Probable cause: the inferred type is ambiguous\r\n In the expression:\r\n let\r\n igo :: _\r\n igo p n\r\n = q n (optimum cantor $ q n)\r\n where\r\n q n a = ...\r\n in Search igo\r\n In an equation for ‘cantor’:\r\n cantor\r\n = let\r\n igo :: _\r\n igo p n\r\n = q n (optimum cantor $ q n)\r\n where\r\n ...\r\n in Search igo\r\n\r\nsource_file.hs:26:15:\r\n Couldn't match type ‘t’ with ‘Integer > Bool’\r\n ‘t’ is untouchable\r\n inside the constraints (Ord a1)\r\n bound by a type expected by the context:\r\n Ord a1 => ((Integer > Bool) > a1) > Integer > Bool\r\n at source_file.hs:26:817ghc: panic! (the 'impossible' happened)\r\n (GHC version 7.10.3 for x86_64unknownlinux):\r\n\tNo skolem info: t_aU3[sk]\r\n\r\nPlease report this as a GHC bug: http://www.haskell.org/ghc/reportabug\r\n}}}\r\n\r\nSince it said to report a bug, I am.","type_of_failure":"OtherFailure","blocking":[]} >I tried to run
```hs
{# LANGUAGE Rank2Types, PartialTypeSignatures #}
import Control.Monad
newtype Search b = Search {optimum :: forall a. Ord a => (b > a) > b}
instance Monad Search where
return a = Search $ const a
Search ma >>= f = Search $ \p >
optimum (f (ma (\a > p (optimum (f a) p)))) p
instance Functor Search where
fmap = liftM
instance Applicative Search where
pure = return
(<*>) = ap
pair a b = Search $ \p > if p a >= p b then a else b
toList s = igo [] where
igo ls = let x = optimum s (\x' > x' `notElem` ls) in if x `elem` ls then ls else igo (x:ls)
cantor :: Search (Integer > Bool)
cantor = let
igo :: _
igo p n = q n (optimum cantor $ q n) where
q n a = p undefined
in Search igo
main = return ()
```
When run, it said
```
source_file.hs:24:5:
No instance for (Ord a)
When checking that ‘igo’ has the specified type
igo :: forall t a t1. (t > a) > t1 > a
Probable cause: the inferred type is ambiguous
In the expression:
let
igo :: _
igo p n
= q n (optimum cantor $ q n)
where
q n a = ...
in Search igo
In an equation for ‘cantor’:
cantor
= let
igo :: _
igo p n
= q n (optimum cantor $ q n)
where
...
in Search igo
source_file.hs:26:15:
Couldn't match type ‘t’ with ‘Integer > Bool’
‘t’ is untouchable
inside the constraints (Ord a1)
bound by a type expected by the context:
Ord a1 => ((Integer > Bool) > a1) > Integer > Bool
at source_file.hs:26:817ghc: panic! (the 'impossible' happened)
(GHC version 7.10.3 for x86_64unknownlinux):
No skolem info: t_aU3[sk]
Please report this as a GHC bug: http://www.haskell.org/ghc/reportabug
```
Since it said to report a bug, I am.
<details><summary>Trac metadata</summary>
 Trac field  Value 
    
 Version  7.10.3 
 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 said to report a bug","status":"New","operating_system":"","component":"Compiler (Type checker)","related":[],"milestone":"","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"7.10.3","keywords":["panic,","skolem"],"differentials":[],"test_case":"","architecture":"","cc":[""],"type":"Bug","description":"I tried to run\r\n{{{#!hs\r\n{# LANGUAGE Rank2Types, PartialTypeSignatures #}\r\nimport Control.Monad\r\nnewtype Search b = Search {optimum :: forall a. Ord a => (b > a) > b}\r\n\r\ninstance Monad Search where\r\n return a = Search $ const a\r\n Search ma >>= f = Search $ \\p >\r\n optimum (f (ma (\\a > p (optimum (f a) p)))) p\r\n\r\ninstance Functor Search where\r\n fmap = liftM\r\n\r\ninstance Applicative Search where\r\n pure = return\r\n (<*>) = ap\r\n\r\npair a b = Search $ \\p > if p a >= p b then a else b\r\ntoList s = igo [] where\r\n igo ls = let x = optimum s (\\x' > x' `notElem` ls) in if x `elem` ls then ls else igo (x:ls)\r\n\r\ncantor :: Search (Integer > Bool)\r\ncantor = let\r\n igo :: _\r\n igo p n = q n (optimum cantor $ q n) where\r\n q n a = p undefined\r\n in Search igo\r\n\r\nmain = return ()\r\n}}}\r\n\r\nWhen run, it said\r\n\r\n{{{\r\nsource_file.hs:24:5:\r\n No instance for (Ord a)\r\n When checking that ‘igo’ has the specified type\r\n igo :: forall t a t1. (t > a) > t1 > a\r\n Probable cause: the inferred type is ambiguous\r\n In the expression:\r\n let\r\n igo :: _\r\n igo p n\r\n = q n (optimum cantor $ q n)\r\n where\r\n q n a = ...\r\n in Search igo\r\n In an equation for ‘cantor’:\r\n cantor\r\n = let\r\n igo :: _\r\n igo p n\r\n = q n (optimum cantor $ q n)\r\n where\r\n ...\r\n in Search igo\r\n\r\nsource_file.hs:26:15:\r\n Couldn't match type ‘t’ with ‘Integer > Bool’\r\n ‘t’ is untouchable\r\n inside the constraints (Ord a1)\r\n bound by a type expected by the context:\r\n Ord a1 => ((Integer > Bool) > a1) > Integer > Bool\r\n at source_file.hs:26:817ghc: panic! (the 'impossible' happened)\r\n (GHC version 7.10.3 for x86_64unknownlinux):\r\n\tNo skolem info: t_aU3[sk]\r\n\r\nPlease report this as a GHC bug: http://www.haskell.org/ghc/reportabug\r\n}}}\r\n\r\nSince it said to report a bug, I am.","type_of_failure":"OtherFailure","blocking":[]} >https://gitlab.haskell.org/ghc/ghc//issues/16188GHC HEADonly panic (buildKindCoercion)20190707T18:01:01ZRyan ScottGHC HEADonly panic (buildKindCoercion)The following program compiles without issue on GHC 8.6.3:
```hs
{# LANGUAGE DataKinds #}
{# LANGUAGE GADTs #}
{# LANGUAGE PolyKinds #}
{# LANGUAGE ScopedTypeVariables #}
{# LANGUAGE TypeFamilies #}
{# LANGUAGE TypeOperators #}
{# LANGUAGE UndecidableInstances #}
module Bug where
import Data.Kind (Type)
import Data.Type.Bool (type (&&))
data TyFun :: Type > Type > Type
type a ~> b = TyFun a b > Type
infixr 0 ~>
type family Apply (f :: a ~> b) (x :: a) :: b
data family Sing :: forall k. k > Type
data instance Sing :: Bool > Type where
SFalse :: Sing False
STrue :: Sing True
(%&&) :: forall (x :: Bool) (y :: Bool).
Sing x > Sing y > Sing (x && y)
SFalse %&& _ = SFalse
STrue %&& a = a
data RegExp :: Type > Type where
App :: RegExp t > RegExp t > RegExp t
data instance Sing :: forall t. RegExp t > Type where
SApp :: Sing re1 > Sing re2 > Sing (App re1 re2)
data ReNotEmptySym0 :: forall t. RegExp t ~> Bool
type instance Apply ReNotEmptySym0 r = ReNotEmpty r
type family ReNotEmpty (r :: RegExp t) :: Bool where
ReNotEmpty (App re1 re2) = ReNotEmpty re1 && ReNotEmpty re2
sReNotEmpty :: forall t (r :: RegExp t).
Sing r > Sing (Apply ReNotEmptySym0 r :: Bool)
sReNotEmpty (SApp sre1 sre2) = sReNotEmpty sre1 %&& sReNotEmpty sre2
blah :: forall (t :: Type) (re :: RegExp t).
Sing re > ()
blah (SApp sre1 sre2)
= case (sReNotEmpty sre1, sReNotEmpty sre2) of
(STrue, STrue) > ()
```
However, it panics on GHC HEAD:
```
$ ~/Software/ghc4/inplace/bin/ghcstage2 Bug.hs
[1 of 1] Compiling Bug ( Bug.hs, Bug.o )
ghcstage2: panic! (the 'impossible' happened)
(GHC version 8.7.20190114 for x86_64unknownlinux):
buildKindCoercion
Any
ReNotEmpty re2_a1hm
Bool
t_a1hg
Call stack:
CallStack (from HasCallStack):
callStackDoc, called at compiler/utils/Outputable.hs:1159:37 in ghc:Outputable
pprPanic, called at compiler/types/Coercion.hs:2427:9 in ghc:Coercion
```
<details><summary>Trac metadata</summary>
 Trac field  Value 
    
 Version  8.7 
 Type  Bug 
 TypeOfFailure  OtherFailure 
 Priority  highest 
 Resolution  Unresolved 
 Component  Compiler (Type checker) 
 Test case  
 Differential revisions  
 BlockedBy  
 Related  
 Blocking  
 CC  
 Operating system  
 Architecture  
</details>
<! {"blocked_by":[],"summary":"GHC HEADonly panic (buildKindCoercion)","status":"New","operating_system":"","component":"Compiler (Type checker)","related":[],"milestone":"8.8.1","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"8.7","keywords":["TypeInType"],"differentials":[],"test_case":"","architecture":"","cc":[""],"type":"Bug","description":"The following program compiles without issue on GHC 8.6.3:\r\n\r\n{{{#!hs\r\n{# LANGUAGE DataKinds #}\r\n{# LANGUAGE GADTs #}\r\n{# LANGUAGE PolyKinds #}\r\n{# LANGUAGE ScopedTypeVariables #}\r\n{# LANGUAGE TypeFamilies #}\r\n{# LANGUAGE TypeOperators #}\r\n{# LANGUAGE UndecidableInstances #}\r\nmodule Bug where\r\n\r\nimport Data.Kind (Type)\r\nimport Data.Type.Bool (type (&&))\r\n\r\ndata TyFun :: Type > Type > Type\r\ntype a ~> b = TyFun a b > Type\r\ninfixr 0 ~>\r\ntype family Apply (f :: a ~> b) (x :: a) :: b\r\ndata family Sing :: forall k. k > Type\r\n\r\ndata instance Sing :: Bool > Type where\r\n SFalse :: Sing False\r\n STrue :: Sing True\r\n\r\n(%&&) :: forall (x :: Bool) (y :: Bool).\r\n Sing x > Sing y > Sing (x && y)\r\nSFalse %&& _ = SFalse\r\nSTrue %&& a = a\r\n\r\ndata RegExp :: Type > Type where\r\n App :: RegExp t > RegExp t > RegExp t\r\n\r\ndata instance Sing :: forall t. RegExp t > Type where\r\n SApp :: Sing re1 > Sing re2 > Sing (App re1 re2)\r\n\r\ndata ReNotEmptySym0 :: forall t. RegExp t ~> Bool\r\ntype instance Apply ReNotEmptySym0 r = ReNotEmpty r\r\n\r\ntype family ReNotEmpty (r :: RegExp t) :: Bool where\r\n ReNotEmpty (App re1 re2) = ReNotEmpty re1 && ReNotEmpty re2\r\n\r\nsReNotEmpty :: forall t (r :: RegExp t).\r\n Sing r > Sing (Apply ReNotEmptySym0 r :: Bool)\r\nsReNotEmpty (SApp sre1 sre2) = sReNotEmpty sre1 %&& sReNotEmpty sre2\r\n\r\nblah :: forall (t :: Type) (re :: RegExp t).\r\n Sing re > ()\r\nblah (SApp sre1 sre2)\r\n = case (sReNotEmpty sre1, sReNotEmpty sre2) of\r\n (STrue, STrue) > ()\r\n}}}\r\n\r\nHowever, it panics on GHC HEAD:\r\n\r\n{{{\r\n$ ~/Software/ghc4/inplace/bin/ghcstage2 Bug.hs \r\n[1 of 1] Compiling Bug ( Bug.hs, Bug.o )\r\nghcstage2: panic! (the 'impossible' happened)\r\n (GHC version 8.7.20190114 for x86_64unknownlinux):\r\n buildKindCoercion\r\n Any\r\n ReNotEmpty re2_a1hm\r\n Bool\r\n t_a1hg\r\n Call stack:\r\n CallStack (from HasCallStack):\r\n callStackDoc, called at compiler/utils/Outputable.hs:1159:37 in ghc:Outputable\r\n pprPanic, called at compiler/types/Coercion.hs:2427:9 in ghc:Coercion\r\n}}}","type_of_failure":"OtherFailure","blocking":[]} >The following program compiles without issue on GHC 8.6.3:
```hs
{# LANGUAGE DataKinds #}
{# LANGUAGE GADTs #}
{# LANGUAGE PolyKinds #}
{# LANGUAGE ScopedTypeVariables #}
{# LANGUAGE TypeFamilies #}
{# LANGUAGE TypeOperators #}
{# LANGUAGE UndecidableInstances #}
module Bug where
import Data.Kind (Type)
import Data.Type.Bool (type (&&))
data TyFun :: Type > Type > Type
type a ~> b = TyFun a b > Type
infixr 0 ~>
type family Apply (f :: a ~> b) (x :: a) :: b
data family Sing :: forall k. k > Type
data instance Sing :: Bool > Type where
SFalse :: Sing False
STrue :: Sing True
(%&&) :: forall (x :: Bool) (y :: Bool).
Sing x > Sing y > Sing (x && y)
SFalse %&& _ = SFalse
STrue %&& a = a
data RegExp :: Type > Type where
App :: RegExp t > RegExp t > RegExp t
data instance Sing :: forall t. RegExp t > Type where
SApp :: Sing re1 > Sing re2 > Sing (App re1 re2)
data ReNotEmptySym0 :: forall t. RegExp t ~> Bool
type instance Apply ReNotEmptySym0 r = ReNotEmpty r
type family ReNotEmpty (r :: RegExp t) :: Bool where
ReNotEmpty (App re1 re2) = ReNotEmpty re1 && ReNotEmpty re2
sReNotEmpty :: forall t (r :: RegExp t).
Sing r > Sing (Apply ReNotEmptySym0 r :: Bool)
sReNotEmpty (SApp sre1 sre2) = sReNotEmpty sre1 %&& sReNotEmpty sre2
blah :: forall (t :: Type) (re :: RegExp t).
Sing re > ()
blah (SApp sre1 sre2)
= case (sReNotEmpty sre1, sReNotEmpty sre2) of
(STrue, STrue) > ()
```
However, it panics on GHC HEAD:
```
$ ~/Software/ghc4/inplace/bin/ghcstage2 Bug.hs
[1 of 1] Compiling Bug ( Bug.hs, Bug.o )
ghcstage2: panic! (the 'impossible' happened)
(GHC version 8.7.20190114 for x86_64unknownlinux):
buildKindCoercion
Any
ReNotEmpty re2_a1hm
Bool
t_a1hg
Call stack:
CallStack (from HasCallStack):
callStackDoc, called at compiler/utils/Outputable.hs:1159:37 in ghc:Outputable
pprPanic, called at compiler/types/Coercion.hs:2427:9 in ghc:Coercion
```
<details><summary>Trac metadata</summary>
 Trac field  Value 
    
 Version  8.7 
 Type  Bug 
 TypeOfFailure  OtherFailure 
 Priority  highest 
 Resolution  Unresolved 
 Component  Compiler (Type checker) 
 Test case  
 Differential revisions  
 BlockedBy  
 Related  
 Blocking  
 CC  
 Operating system  
 Architecture  
</details>
<! {"blocked_by":[],"summary":"GHC HEADonly panic (buildKindCoercion)","status":"New","operating_system":"","component":"Compiler (Type checker)","related":[],"milestone":"8.8.1","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"8.7","keywords":["TypeInType"],"differentials":[],"test_case":"","architecture":"","cc":[""],"type":"Bug","description":"The following program compiles without issue on GHC 8.6.3:\r\n\r\n{{{#!hs\r\n{# LANGUAGE DataKinds #}\r\n{# LANGUAGE GADTs #}\r\n{# LANGUAGE PolyKinds #}\r\n{# LANGUAGE ScopedTypeVariables #}\r\n{# LANGUAGE TypeFamilies #}\r\n{# LANGUAGE TypeOperators #}\r\n{# LANGUAGE UndecidableInstances #}\r\nmodule Bug where\r\n\r\nimport Data.Kind (Type)\r\nimport Data.Type.Bool (type (&&))\r\n\r\ndata TyFun :: Type > Type > Type\r\ntype a ~> b = TyFun a b > Type\r\ninfixr 0 ~>\r\ntype family Apply (f :: a ~> b) (x :: a) :: b\r\ndata family Sing :: forall k. k > Type\r\n\r\ndata instance Sing :: Bool > Type where\r\n SFalse :: Sing False\r\n STrue :: Sing True\r\n\r\n(%&&) :: forall (x :: Bool) (y :: Bool).\r\n Sing x > Sing y > Sing (x && y)\r\nSFalse %&& _ = SFalse\r\nSTrue %&& a = a\r\n\r\ndata RegExp :: Type > Type where\r\n App :: RegExp t > RegExp t > RegExp t\r\n\r\ndata instance Sing :: forall t. RegExp t > Type where\r\n SApp :: Sing re1 > Sing re2 > Sing (App re1 re2)\r\n\r\ndata ReNotEmptySym0 :: forall t. RegExp t ~> Bool\r\ntype instance Apply ReNotEmptySym0 r = ReNotEmpty r\r\n\r\ntype family ReNotEmpty (r :: RegExp t) :: Bool where\r\n ReNotEmpty (App re1 re2) = ReNotEmpty re1 && ReNotEmpty re2\r\n\r\nsReNotEmpty :: forall t (r :: RegExp t).\r\n Sing r > Sing (Apply ReNotEmptySym0 r :: Bool)\r\nsReNotEmpty (SApp sre1 sre2) = sReNotEmpty sre1 %&& sReNotEmpty sre2\r\n\r\nblah :: forall (t :: Type) (re :: RegExp t).\r\n Sing re > ()\r\nblah (SApp sre1 sre2)\r\n = case (sReNotEmpty sre1, sReNotEmpty sre2) of\r\n (STrue, STrue) > ()\r\n}}}\r\n\r\nHowever, it panics on GHC HEAD:\r\n\r\n{{{\r\n$ ~/Software/ghc4/inplace/bin/ghcstage2 Bug.hs \r\n[1 of 1] Compiling Bug ( Bug.hs, Bug.o )\r\nghcstage2: panic! (the 'impossible' happened)\r\n (GHC version 8.7.20190114 for x86_64unknownlinux):\r\n buildKindCoercion\r\n Any\r\n ReNotEmpty re2_a1hm\r\n Bool\r\n t_a1hg\r\n Call stack:\r\n CallStack (from HasCallStack):\r\n callStackDoc, called at compiler/utils/Outputable.hs:1159:37 in ghc:Outputable\r\n pprPanic, called at compiler/types/Coercion.hs:2427:9 in ghc:Coercion\r\n}}}","type_of_failure":"OtherFailure","blocking":[]} >8.8.1Richard Eisenbergrae@richarde.devRichard Eisenbergrae@richarde.devhttps://gitlab.haskell.org/ghc/ghc//issues/16204GHC HEADonly Core Lint error (Argument value doesn't match argument type)20190707T18:00:58ZRyan ScottGHC HEADonly Core Lint error (Argument value doesn't match argument type)The following program passes Core Lint on GHC 8.6.3:
```hs
{# LANGUAGE DataKinds #}
{# LANGUAGE FlexibleContexts #}
{# LANGUAGE GADTs #}
{# LANGUAGE PolyKinds #}
{# LANGUAGE RankNTypes #}
{# LANGUAGE ScopedTypeVariables #}
{# LANGUAGE TypeApplications #}
{# LANGUAGE TypeFamilies #}
module Bug where
import Data.Kind

 singletons machinery

data family Sing :: forall k. k > Type
data SomeSing :: Type > Type where
SomeSing :: Sing (a :: k) > SomeSing k

 (Simplified) GHC.Generics

class Generic (a :: Type) where
type Rep a :: Type
from :: a > Rep a
to :: Rep a > a
class PGeneric (a :: Type) where
 type PFrom ...
type PTo (x :: Rep a) :: a
class SGeneric k where
 sFrom :: ...
sTo :: forall (a :: Rep k). Sing a > Sing (PTo a :: k)

class SingKind k where
type Demote k :: Type
 fromSing :: ...
toSing :: Demote k > SomeSing k
genericToSing :: forall k.
( SingKind k, SGeneric k, SingKind (Rep k)
, Generic (Demote k), Rep (Demote k) ~ Demote (Rep k) )
=> Demote k > SomeSing k
genericToSing d = withSomeSing @(Rep k) (from d) $ SomeSing . sTo
withSomeSing :: forall k r
. SingKind k
=> Demote k
> (forall (a :: k). Sing a > r)
> r
withSomeSing x f =
case toSing x of
SomeSing x' > f x'
```
But not on GHC HEAD:
```
$ ~/Software/ghc4/inplace/bin/ghcstage2 Bug.hs dcorelint
[1 of 1] Compiling Bug ( Bug.hs, Bug.o )
*** Core Lint errors : in result of Desugar (before optimization) ***
<no location info>: warning:
In the expression: $ @ 'LiftedRep
@ (forall (a :: Rep k_a1cV). Sing a > SomeSing k_a1cV)
@ (SomeSing k_a1cV)
(withSomeSing
@ (Rep k_a1cV)
@ (SomeSing k_a1cV)
$dSingKind_a1d5
((from
@ (Demote k_a1cV)
$dGeneric_a1d7
(d_aX7
`cast` (Sub co_a1dK
:: Demote k_a1cV[sk:1] ~R# Demote k_a1cV[sk:1])))
`cast` (Sub (Sym (Sym co_a1dR ; Sym co_a1dM) ; (Sym co_a1dQ ; (Demote
(Sym co_a1dO))_N))
:: Rep (Demote k_a1cV[sk:1]) ~R# Demote (Rep k_a1cV[sk:1]))))
(\ (@ (a_a1dc :: Rep k_a1cV)) >
let {
$dSGeneric_a1dm :: SGeneric k_a1cV
[LclId]
$dSGeneric_a1dm = $dSGeneric_a1cY } in
. @ (Sing (PTo Any))
@ (SomeSing k_a1cV)
@ (Sing Any)
(SomeSing @ k_a1cV @ (PTo Any))
((sTo @ k_a1cV $dSGeneric_a1dm @ Any)
`cast` (Sym (Sing
(Sym co_a1dO) (Sym (GRefl nominal Any co_a1dO)))_R
>_R <Sing (PTo Any)>_R
:: (Sing Any > Sing (PTo Any))
~R# (Sing Any > Sing (PTo Any)))))
Argument value doesn't match argument type:
Fun type:
(forall (a :: Rep k_a1cV). Sing a > SomeSing k_a1cV)
> SomeSing k_a1cV
Arg type: forall (a :: Rep k_a1cV). Sing Any > SomeSing k_a1cV
Arg:
\ (@ (a_a1dc :: Rep k_a1cV)) >
let {
$dSGeneric_a1dm :: SGeneric k_a1cV
[LclId]
$dSGeneric_a1dm = $dSGeneric_a1cY } in
. @ (Sing (PTo Any))
@ (SomeSing k_a1cV)
@ (Sing Any)
(SomeSing @ k_a1cV @ (PTo Any))
((sTo @ k_a1cV $dSGeneric_a1dm @ Any)
`cast` (Sym (Sing
(Sym co_a1dO) (Sym (GRefl nominal Any co_a1dO)))_R
>_R <Sing (PTo Any)>_R
:: (Sing Any > Sing (PTo Any)) ~R# (Sing Any > Sing (PTo Any))))
*** Offending Program ***
<elided>
genericToSing
:: forall k.
(SingKind k, SGeneric k, SingKind (Rep k), Generic (Demote k),
Rep (Demote k) ~ Demote (Rep k)) =>
Demote k > SomeSing k
[LclIdX]
genericToSing
= \ (@ k_a1cV)
($dSingKind_a1cX :: SingKind k_a1cV)
($dSGeneric_a1cY :: SGeneric k_a1cV)
($dSingKind_a1cZ :: SingKind (Rep k_a1cV))
($dGeneric_a1d0 :: Generic (Demote k_a1cV))
($d~_a1d1 :: Rep (Demote k_a1cV) ~ Demote (Rep k_a1cV)) >
let {
co_a1dQ :: Demote (Rep k_a1cV) ~# Demote (Rep k_a1cV)
[LclId[CoVarId]]
co_a1dQ = CO: <Demote (Rep k_a1cV)>_N } in
let {
co_a1dO :: Rep k_a1cV ~# Rep k_a1cV
[LclId[CoVarId]]
co_a1dO = CO: <Rep k_a1cV>_N } in
let {
$dSingKind_a1dT :: SingKind (Rep k_a1cV)
[LclId]
$dSingKind_a1dT
= $dSingKind_a1cZ
`cast` (Sub (Sym (SingKind (Sym co_a1dO))_N)
:: SingKind (Rep k_a1cV[sk:1])
~R# SingKind (Rep k_a1cV[sk:1])) } in
let {
$dSingKind_a1d5 :: SingKind (Rep k_a1cV)
[LclId]
$dSingKind_a1d5
= $dSingKind_a1dT
`cast` ((SingKind (Sym co_a1dO))_R
:: SingKind (Rep k_a1cV[sk:1])
~R# SingKind (Rep k_a1cV[sk:1])) } in
let {
co_a1dM :: Rep (Demote k_a1cV) ~# Rep (Demote k_a1cV)
[LclId[CoVarId]]
co_a1dM = CO: <Rep (Demote k_a1cV)>_N } in
let {
co_a1dK :: Demote k_a1cV ~# Demote k_a1cV
[LclId[CoVarId]]
co_a1dK = CO: <Demote k_a1cV>_N } in
let {
$dGeneric_a1dU :: Generic (Demote k_a1cV)
[LclId]
$dGeneric_a1dU
= $dGeneric_a1d0
`cast` (Sub (Sym (Generic (Sym co_a1dK))_N)
:: Generic (Demote k_a1cV[sk:1])
~R# Generic (Demote k_a1cV[sk:1])) } in
let {
$dGeneric_a1d7 :: Generic (Demote k_a1cV)
[LclId]
$dGeneric_a1d7 = $dGeneric_a1dU } in
case eq_sel
@ * @ (Rep (Demote k_a1cV)) @ (Demote (Rep k_a1cV)) $d~_a1d1
of co_a1dI
{ __DEFAULT >
let {
co_a1dR :: Rep (Demote k_a1cV) ~# Demote (Rep k_a1cV)
[LclId[CoVarId]]
co_a1dR
= CO: ((Sym co_a1dM ; (Rep
(Sym co_a1dK))_N) ; co_a1dI) ; Sym (Sym co_a1dQ ; (Demote
(Sym co_a1dO))_N) } in
\ (d_aX7 :: Demote k_a1cV) >
$ @ 'LiftedRep
@ (forall (a :: Rep k_a1cV). Sing a > SomeSing k_a1cV)
@ (SomeSing k_a1cV)
(withSomeSing
@ (Rep k_a1cV)
@ (SomeSing k_a1cV)
$dSingKind_a1d5
((from
@ (Demote k_a1cV)
$dGeneric_a1d7
(d_aX7
`cast` (Sub co_a1dK
:: Demote k_a1cV[sk:1] ~R# Demote k_a1cV[sk:1])))
`cast` (Sub (Sym (Sym co_a1dR ; Sym co_a1dM) ; (Sym co_a1dQ ; (Demote
(Sym co_a1dO))_N))
:: Rep (Demote k_a1cV[sk:1]) ~R# Demote (Rep k_a1cV[sk:1]))))
(\ (@ (a_a1dc :: Rep k_a1cV)) >
let {
$dSGeneric_a1dm :: SGeneric k_a1cV
[LclId]
$dSGeneric_a1dm = $dSGeneric_a1cY } in
. @ (Sing (PTo Any))
@ (SomeSing k_a1cV)
@ (Sing Any)
(SomeSing @ k_a1cV @ (PTo Any))
((sTo @ k_a1cV $dSGeneric_a1dm @ Any)
`cast` (Sym (Sing
(Sym co_a1dO) (Sym (GRefl nominal Any co_a1dO)))_R
>_R <Sing (PTo Any)>_R
:: (Sing Any > Sing (PTo Any)) ~R# (Sing Any > Sing (PTo Any)))))
}
```
I'm not sure if this is related to #16188 (see #16188\##16204), but this Core Lint error is technically different from the one in that ticket, so I decided to open a new issue for this.
<details><summary>Trac metadata</summary>
 Trac field  Value 
    
 Version  8.7 
 Type  Bug 
 TypeOfFailure  OtherFailure 
 Priority  highest 
 Resolution  Unresolved 
 Component  Compiler (Type checker) 
 Test case  
 Differential revisions  
 BlockedBy  
 Related  #16188 
 Blocking  
 CC  
 Operating system  
 Architecture  
</details>
<! {"blocked_by":[],"summary":"GHC HEADonly Core Lint error (Argument value doesn't match argument type)","status":"New","operating_system":"","component":"Compiler (Type checker)","related":[16188],"milestone":"8.8.1","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"8.7","keywords":["TypeInType"],"differentials":[],"test_case":"","architecture":"","cc":[""],"type":"Bug","description":"The following program passes Core Lint on GHC 8.6.3:\r\n\r\n{{{#!hs\r\n{# LANGUAGE DataKinds #}\r\n{# LANGUAGE FlexibleContexts #}\r\n{# LANGUAGE GADTs #}\r\n{# LANGUAGE PolyKinds #}\r\n{# LANGUAGE RankNTypes #}\r\n{# LANGUAGE ScopedTypeVariables #}\r\n{# LANGUAGE TypeApplications #}\r\n{# LANGUAGE TypeFamilies #}\r\nmodule Bug where\r\n\r\nimport Data.Kind\r\n\r\n\r\n singletons machinery\r\n\r\n\r\ndata family Sing :: forall k. k > Type\r\ndata SomeSing :: Type > Type where\r\n SomeSing :: Sing (a :: k) > SomeSing k\r\n\r\n\r\n (Simplified) GHC.Generics\r\n\r\n\r\nclass Generic (a :: Type) where\r\n type Rep a :: Type\r\n from :: a > Rep a\r\n to :: Rep a > a\r\n\r\nclass PGeneric (a :: Type) where\r\n  type PFrom ...\r\n type PTo (x :: Rep a) :: a\r\n\r\nclass SGeneric k where\r\n  sFrom :: ...\r\n sTo :: forall (a :: Rep k). Sing a > Sing (PTo a :: k)\r\n\r\n\r\n\r\nclass SingKind k where\r\n type Demote k :: Type\r\n  fromSing :: ...\r\n toSing :: Demote k > SomeSing k\r\n\r\ngenericToSing :: forall k.\r\n ( SingKind k, SGeneric k, SingKind (Rep k)\r\n , Generic (Demote k), Rep (Demote k) ~ Demote (Rep k) )\r\n => Demote k > SomeSing k\r\ngenericToSing d = withSomeSing @(Rep k) (from d) $ SomeSing . sTo\r\n\r\nwithSomeSing :: forall k r\r\n . SingKind k\r\n => Demote k\r\n > (forall (a :: k). Sing a > r)\r\n > r\r\nwithSomeSing x f =\r\n case toSing x of\r\n SomeSing x' > f x'\r\n}}}\r\n\r\nBut not on GHC HEAD:\r\n\r\n{{{\r\n$ ~/Software/ghc4/inplace/bin/ghcstage2 Bug.hs dcorelint \r\n[1 of 1] Compiling Bug ( Bug.hs, Bug.o )\r\n*** Core Lint errors : in result of Desugar (before optimization) ***\r\n<no location info>: warning:\r\n In the expression: $ @ 'LiftedRep\r\n @ (forall (a :: Rep k_a1cV). Sing a > SomeSing k_a1cV)\r\n @ (SomeSing k_a1cV)\r\n (withSomeSing\r\n @ (Rep k_a1cV)\r\n @ (SomeSing k_a1cV)\r\n $dSingKind_a1d5\r\n ((from\r\n @ (Demote k_a1cV)\r\n $dGeneric_a1d7\r\n (d_aX7\r\n `cast` (Sub co_a1dK\r\n :: Demote k_a1cV[sk:1] ~R# Demote k_a1cV[sk:1])))\r\n `cast` (Sub (Sym (Sym co_a1dR ; Sym co_a1dM) ; (Sym co_a1dQ ; (Demote\r\n (Sym co_a1dO))_N))\r\n :: Rep (Demote k_a1cV[sk:1]) ~R# Demote (Rep k_a1cV[sk:1]))))\r\n (\\ (@ (a_a1dc :: Rep k_a1cV)) >\r\n let {\r\n $dSGeneric_a1dm :: SGeneric k_a1cV\r\n [LclId]\r\n $dSGeneric_a1dm = $dSGeneric_a1cY } in\r\n . @ (Sing (PTo Any))\r\n @ (SomeSing k_a1cV)\r\n @ (Sing Any)\r\n (SomeSing @ k_a1cV @ (PTo Any))\r\n ((sTo @ k_a1cV $dSGeneric_a1dm @ Any)\r\n `cast` (Sym (Sing\r\n (Sym co_a1dO) (Sym (GRefl nominal Any co_a1dO)))_R\r\n >_R <Sing (PTo Any)>_R\r\n :: (Sing Any > Sing (PTo Any))\r\n ~R# (Sing Any > Sing (PTo Any)))))\r\n Argument value doesn't match argument type:\r\n Fun type:\r\n (forall (a :: Rep k_a1cV). Sing a > SomeSing k_a1cV)\r\n > SomeSing k_a1cV\r\n Arg type: forall (a :: Rep k_a1cV). Sing Any > SomeSing k_a1cV\r\n Arg:\r\n \\ (@ (a_a1dc :: Rep k_a1cV)) >\r\n let {\r\n $dSGeneric_a1dm :: SGeneric k_a1cV\r\n [LclId]\r\n $dSGeneric_a1dm = $dSGeneric_a1cY } in\r\n . @ (Sing (PTo Any))\r\n @ (SomeSing k_a1cV)\r\n @ (Sing Any)\r\n (SomeSing @ k_a1cV @ (PTo Any))\r\n ((sTo @ k_a1cV $dSGeneric_a1dm @ Any)\r\n `cast` (Sym (Sing\r\n (Sym co_a1dO) (Sym (GRefl nominal Any co_a1dO)))_R\r\n >_R <Sing (PTo Any)>_R\r\n :: (Sing Any > Sing (PTo Any)) ~R# (Sing Any > Sing (PTo Any))))\r\n*** Offending Program ***\r\n<elided>\r\ngenericToSing\r\n :: forall k.\r\n (SingKind k, SGeneric k, SingKind (Rep k), Generic (Demote k),\r\n Rep (Demote k) ~ Demote (Rep k)) =>\r\n Demote k > SomeSing k\r\n[LclIdX]\r\ngenericToSing\r\n = \\ (@ k_a1cV)\r\n ($dSingKind_a1cX :: SingKind k_a1cV)\r\n ($dSGeneric_a1cY :: SGeneric k_a1cV)\r\n ($dSingKind_a1cZ :: SingKind (Rep k_a1cV))\r\n ($dGeneric_a1d0 :: Generic (Demote k_a1cV))\r\n ($d~_a1d1 :: Rep (Demote k_a1cV) ~ Demote (Rep k_a1cV)) >\r\n let {\r\n co_a1dQ :: Demote (Rep k_a1cV) ~# Demote (Rep k_a1cV)\r\n [LclId[CoVarId]]\r\n co_a1dQ = CO: <Demote (Rep k_a1cV)>_N } in\r\n let {\r\n co_a1dO :: Rep k_a1cV ~# Rep k_a1cV\r\n [LclId[CoVarId]]\r\n co_a1dO = CO: <Rep k_a1cV>_N } in\r\n let {\r\n $dSingKind_a1dT :: SingKind (Rep k_a1cV)\r\n [LclId]\r\n $dSingKind_a1dT\r\n = $dSingKind_a1cZ\r\n `cast` (Sub (Sym (SingKind (Sym co_a1dO))_N)\r\n :: SingKind (Rep k_a1cV[sk:1])\r\n ~R# SingKind (Rep k_a1cV[sk:1])) } in\r\n let {\r\n $dSingKind_a1d5 :: SingKind (Rep k_a1cV)\r\n [LclId]\r\n $dSingKind_a1d5\r\n = $dSingKind_a1dT\r\n `cast` ((SingKind (Sym co_a1dO))_R\r\n :: SingKind (Rep k_a1cV[sk:1])\r\n ~R# SingKind (Rep k_a1cV[sk:1])) } in\r\n let {\r\n co_a1dM :: Rep (Demote k_a1cV) ~# Rep (Demote k_a1cV)\r\n [LclId[CoVarId]]\r\n co_a1dM = CO: <Rep (Demote k_a1cV)>_N } in\r\n let {\r\n co_a1dK :: Demote k_a1cV ~# Demote k_a1cV\r\n [LclId[CoVarId]]\r\n co_a1dK = CO: <Demote k_a1cV>_N } in\r\n let {\r\n $dGeneric_a1dU :: Generic (Demote k_a1cV)\r\n [LclId]\r\n $dGeneric_a1dU\r\n = $dGeneric_a1d0\r\n `cast` (Sub (Sym (Generic (Sym co_a1dK))_N)\r\n :: Generic (Demote k_a1cV[sk:1])\r\n ~R# Generic (Demote k_a1cV[sk:1])) } in\r\n let {\r\n $dGeneric_a1d7 :: Generic (Demote k_a1cV)\r\n [LclId]\r\n $dGeneric_a1d7 = $dGeneric_a1dU } in\r\n case eq_sel\r\n @ * @ (Rep (Demote k_a1cV)) @ (Demote (Rep k_a1cV)) $d~_a1d1\r\n of co_a1dI\r\n { __DEFAULT >\r\n let {\r\n co_a1dR :: Rep (Demote k_a1cV) ~# Demote (Rep k_a1cV)\r\n [LclId[CoVarId]]\r\n co_a1dR\r\n = CO: ((Sym co_a1dM ; (Rep\r\n (Sym co_a1dK))_N) ; co_a1dI) ; Sym (Sym co_a1dQ ; (Demote\r\n (Sym co_a1dO))_N) } in\r\n \\ (d_aX7 :: Demote k_a1cV) >\r\n $ @ 'LiftedRep\r\n @ (forall (a :: Rep k_a1cV). Sing a > SomeSing k_a1cV)\r\n @ (SomeSing k_a1cV)\r\n (withSomeSing\r\n @ (Rep k_a1cV)\r\n @ (SomeSing k_a1cV)\r\n $dSingKind_a1d5\r\n ((from\r\n @ (Demote k_a1cV)\r\n $dGeneric_a1d7\r\n (d_aX7\r\n `cast` (Sub co_a1dK\r\n :: Demote k_a1cV[sk:1] ~R# Demote k_a1cV[sk:1])))\r\n `cast` (Sub (Sym (Sym co_a1dR ; Sym co_a1dM) ; (Sym co_a1dQ ; (Demote\r\n (Sym co_a1dO))_N))\r\n :: Rep (Demote k_a1cV[sk:1]) ~R# Demote (Rep k_a1cV[sk:1]))))\r\n (\\ (@ (a_a1dc :: Rep k_a1cV)) >\r\n let {\r\n $dSGeneric_a1dm :: SGeneric k_a1cV\r\n [LclId]\r\n $dSGeneric_a1dm = $dSGeneric_a1cY } in\r\n . @ (Sing (PTo Any))\r\n @ (SomeSing k_a1cV)\r\n @ (Sing Any)\r\n (SomeSing @ k_a1cV @ (PTo Any))\r\n ((sTo @ k_a1cV $dSGeneric_a1dm @ Any)\r\n `cast` (Sym (Sing\r\n (Sym co_a1dO) (Sym (GRefl nominal Any co_a1dO)))_R\r\n >_R <Sing (PTo Any)>_R\r\n :: (Sing Any > Sing (PTo Any)) ~R# (Sing Any > Sing (PTo Any)))))\r\n }\r\n}}}\r\n\r\nI'm not sure if this is related to #16188 (see https://ghc.haskell.org/trac/ghc/ticket/16188#comment:1), but this Core Lint error is technically different from the one in that ticket, so I decided to open a new issue for this.","type_of_failure":"OtherFailure","blocking":[]} >The following program passes Core Lint on GHC 8.6.3:
```hs
{# LANGUAGE DataKinds #}
{# LANGUAGE FlexibleContexts #}
{# LANGUAGE GADTs #}
{# LANGUAGE PolyKinds #}
{# LANGUAGE RankNTypes #}
{# LANGUAGE ScopedTypeVariables #}
{# LANGUAGE TypeApplications #}
{# LANGUAGE TypeFamilies #}
module Bug where
import Data.Kind

 singletons machinery

data family Sing :: forall k. k > Type
data SomeSing :: Type > Type where
SomeSing :: Sing (a :: k) > SomeSing k

 (Simplified) GHC.Generics

class Generic (a :: Type) where
type Rep a :: Type
from :: a > Rep a
to :: Rep a > a
class PGeneric (a :: Type) where
 type PFrom ...
type PTo (x :: Rep a) :: a
class SGeneric k where
 sFrom :: ...
sTo :: forall (a :: Rep k). Sing a > Sing (PTo a :: k)

class SingKind k where
type Demote k :: Type
 fromSing :: ...
toSing :: Demote k > SomeSing k
genericToSing :: forall k.
( SingKind k, SGeneric k, SingKind (Rep k)
, Generic (Demote k), Rep (Demote k) ~ Demote (Rep k) )
=> Demote k > SomeSing k
genericToSing d = withSomeSing @(Rep k) (from d) $ SomeSing . sTo
withSomeSing :: forall k r
. SingKind k
=> Demote k
> (forall (a :: k). Sing a > r)
> r
withSomeSing x f =
case toSing x of
SomeSing x' > f x'
```
But not on GHC HEAD:
```
$ ~/Software/ghc4/inplace/bin/ghcstage2 Bug.hs dcorelint
[1 of 1] Compiling Bug ( Bug.hs, Bug.o )
*** Core Lint errors : in result of Desugar (before optimization) ***
<no location info>: warning:
In the expression: $ @ 'LiftedRep
@ (forall (a :: Rep k_a1cV). Sing a > SomeSing k_a1cV)
@ (SomeSing k_a1cV)
(withSomeSing
@ (Rep k_a1cV)
@ (SomeSing k_a1cV)
$dSingKind_a1d5
((from
@ (Demote k_a1cV)
$dGeneric_a1d7
(d_aX7
`cast` (Sub co_a1dK
:: Demote k_a1cV[sk:1] ~R# Demote k_a1cV[sk:1])))
`cast` (Sub (Sym (Sym co_a1dR ; Sym co_a1dM) ; (Sym co_a1dQ ; (Demote
(Sym co_a1dO))_N))
:: Rep (Demote k_a1cV[sk:1]) ~R# Demote (Rep k_a1cV[sk:1]))))
(\ (@ (a_a1dc :: Rep k_a1cV)) >
let {
$dSGeneric_a1dm :: SGeneric k_a1cV
[LclId]
$dSGeneric_a1dm = $dSGeneric_a1cY } in
. @ (Sing (PTo Any))
@ (SomeSing k_a1cV)
@ (Sing Any)
(SomeSing @ k_a1cV @ (PTo Any))
((sTo @ k_a1cV $dSGeneric_a1dm @ Any)
`cast` (Sym (Sing
(Sym co_a1dO) (Sym (GRefl nominal Any co_a1dO)))_R
>_R <Sing (PTo Any)>_R
:: (Sing Any > Sing (PTo Any))
~R# (Sing Any > Sing (PTo Any)))))
Argument value doesn't match argument type:
Fun type:
(forall (a :: Rep k_a1cV). Sing a > SomeSing k_a1cV)
> SomeSing k_a1cV
Arg type: forall (a :: Rep k_a1cV). Sing Any > SomeSing k_a1cV
Arg:
\ (@ (a_a1dc :: Rep k_a1cV)) >
let {
$dSGeneric_a1dm :: SGeneric k_a1cV
[LclId]
$dSGeneric_a1dm = $dSGeneric_a1cY } in
. @ (Sing (PTo Any))
@ (SomeSing k_a1cV)
@ (Sing Any)
(SomeSing @ k_a1cV @ (PTo Any))
((sTo @ k_a1cV $dSGeneric_a1dm @ Any)
`cast` (Sym (Sing
(Sym co_a1dO) (Sym (GRefl nominal Any co_a1dO)))_R
>_R <Sing (PTo Any)>_R
:: (Sing Any > Sing (PTo Any)) ~R# (Sing Any > Sing (PTo Any))))
*** Offending Program ***
<elided>
genericToSing
:: forall k.
(SingKind k, SGeneric k, SingKind (Rep k), Generic (Demote k),
Rep (Demote k) ~ Demote (Rep k)) =>
Demote k > SomeSing k
[LclIdX]
genericToSing
= \ (@ k_a1cV)
($dSingKind_a1cX :: SingKind k_a1cV)
($dSGeneric_a1cY :: SGeneric k_a1cV)
($dSingKind_a1cZ :: SingKind (Rep k_a1cV))
($dGeneric_a1d0 :: Generic (Demote k_a1cV))
($d~_a1d1 :: Rep (Demote k_a1cV) ~ Demote (Rep k_a1cV)) >
let {
co_a1dQ :: Demote (Rep k_a1cV) ~# Demote (Rep k_a1cV)
[LclId[CoVarId]]
co_a1dQ = CO: <Demote (Rep k_a1cV)>_N } in
let {
co_a1dO :: Rep k_a1cV ~# Rep k_a1cV
[LclId[CoVarId]]
co_a1dO = CO: <Rep k_a1cV>_N } in
let {
$dSingKind_a1dT :: SingKind (Rep k_a1cV)
[LclId]
$dSingKind_a1dT
= $dSingKind_a1cZ
`cast` (Sub (Sym (SingKind (Sym co_a1dO))_N)
:: SingKind (Rep k_a1cV[sk:1])
~R# SingKind (Rep k_a1cV[sk:1])) } in
let {
$dSingKind_a1d5 :: SingKind (Rep k_a1cV)
[LclId]
$dSingKind_a1d5
= $dSingKind_a1dT
`cast` ((SingKind (Sym co_a1dO))_R
:: SingKind (Rep k_a1cV[sk:1])
~R# SingKind (Rep k_a1cV[sk:1])) } in
let {
co_a1dM :: Rep (Demote k_a1cV) ~# Rep (Demote k_a1cV)
[LclId[CoVarId]]
co_a1dM = CO: <Rep (Demote k_a1cV)>_N } in
let {
co_a1dK :: Demote k_a1cV ~# Demote k_a1cV
[LclId[CoVarId]]
co_a1dK = CO: <Demote k_a1cV>_N } in
let {
$dGeneric_a1dU :: Generic (Demote k_a1cV)
[LclId]
$dGeneric_a1dU
= $dGeneric_a1d0
`cast` (Sub (Sym (Generic (Sym co_a1dK))_N)
:: Generic (Demote k_a1cV[sk:1])
~R# Generic (Demote k_a1cV[sk:1])) } in
let {
$dGeneric_a1d7 :: Generic (Demote k_a1cV)
[LclId]
$dGeneric_a1d7 = $dGeneric_a1dU } in
case eq_sel
@ * @ (Rep (Demote k_a1cV)) @ (Demote (Rep k_a1cV)) $d~_a1d1
of co_a1dI
{ __DEFAULT >
let {
co_a1dR :: Rep (Demote k_a1cV) ~# Demote (Rep k_a1cV)
[LclId[CoVarId]]
co_a1dR
= CO: ((Sym co_a1dM ; (Rep
(Sym co_a1dK))_N) ; co_a1dI) ; Sym (Sym co_a1dQ ; (Demote
(Sym co_a1dO))_N) } in
\ (d_aX7 :: Demote k_a1cV) >
$ @ 'LiftedRep
@ (forall (a :: Rep k_a1cV). Sing a > SomeSing k_a1cV)
@ (SomeSing k_a1cV)
(withSomeSing
@ (Rep k_a1cV)
@ (SomeSing k_a1cV)
$dSingKind_a1d5
((from
@ (Demote k_a1cV)
$dGeneric_a1d7
(d_aX7
`cast` (Sub co_a1dK
:: Demote k_a1cV[sk:1] ~R# Demote k_a1cV[sk:1])))
`cast` (Sub (Sym (Sym co_a1dR ; Sym co_a1dM) ; (Sym co_a1dQ ; (Demote
(Sym co_a1dO))_N))
:: Rep (Demote k_a1cV[sk:1]) ~R# Demote (Rep k_a1cV[sk:1]))))
(\ (@ (a_a1dc :: Rep k_a1cV)) >
let {
$dSGeneric_a1dm :: SGeneric k_a1cV
[LclId]
$dSGeneric_a1dm = $dSGeneric_a1cY } in
. @ (Sing (PTo Any))
@ (SomeSing k_a1cV)
@ (Sing Any)
(SomeSing @ k_a1cV @ (PTo Any))
((sTo @ k_a1cV $dSGeneric_a1dm @ Any)
`cast` (Sym (Sing
(Sym co_a1dO) (Sym (GRefl nominal Any co_a1dO)))_R
>_R <Sing (PTo Any)>_R
:: (Sing Any > Sing (PTo Any)) ~R# (Sing Any > Sing (PTo Any)))))
}
```
I'm not sure if this is related to #16188 (see #16188\##16204), but this Core Lint error is technically different from the one in that ticket, so I decided to open a new issue for this.
<details><summary>Trac metadata</summary>
 Trac field  Value 
    
 Version  8.7 
 Type  Bug 
 TypeOfFailure  OtherFailure 
 Priority  highest 
 Resolution  Unresolved 
 Component  Compiler (Type checker) 
 Test case  
 Differential revisions  
 BlockedBy  
 Related  #16188 
 Blocking  
 CC  
 Operating system  
 Architecture  
</details>
<! {"blocked_by":[],"summary":"GHC HEADonly Core Lint error (Argument value doesn't match argument type)","status":"New","operating_system":"","component":"Compiler (Type checker)","related":[16188],"milestone":"8.8.1","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"8.7","keywords":["TypeInType"],"differentials":[],"test_case":"","architecture":"","cc":[""],"type":"Bug","description":"The following program passes Core Lint on GHC 8.6.3:\r\n\r\n{{{#!hs\r\n{# LANGUAGE DataKinds #}\r\n{# LANGUAGE FlexibleContexts #}\r\n{# LANGUAGE GADTs #}\r\n{# LANGUAGE PolyKinds #}\r\n{# LANGUAGE RankNTypes #}\r\n{# LANGUAGE ScopedTypeVariables #}\r\n{# LANGUAGE TypeApplications #}\r\n{# LANGUAGE TypeFamilies #}\r\nmodule Bug where\r\n\r\nimport Data.Kind\r\n\r\n\r\n singletons machinery\r\n\r\n\r\ndata family Sing :: forall k. k > Type\r\ndata SomeSing :: Type > Type where\r\n SomeSing :: Sing (a :: k) > SomeSing k\r\n\r\n\r\n (Simplified) GHC.Generics\r\n\r\n\r\nclass Generic (a :: Type) where\r\n type Rep a :: Type\r\n from :: a > Rep a\r\n to :: Rep a > a\r\n\r\nclass PGeneric (a :: Type) where\r\n  type PFrom ...\r\n type PTo (x :: Rep a) :: a\r\n\r\nclass SGeneric k where\r\n  sFrom :: ...\r\n sTo :: forall (a :: Rep k). Sing a > Sing (PTo a :: k)\r\n\r\n\r\n\r\nclass SingKind k where\r\n type Demote k :: Type\r\n  fromSing :: ...\r\n toSing :: Demote k > SomeSing k\r\n\r\ngenericToSing :: forall k.\r\n ( SingKind k, SGeneric k, SingKind (Rep k)\r\n , Generic (Demote k), Rep (Demote k) ~ Demote (Rep k) )\r\n => Demote k > SomeSing k\r\ngenericToSing d = withSomeSing @(Rep k) (from d) $ SomeSing . sTo\r\n\r\nwithSomeSing :: forall k r\r\n . SingKind k\r\n => Demote k\r\n > (forall (a :: k). Sing a > r)\r\n > r\r\nwithSomeSing x f =\r\n case toSing x of\r\n SomeSing x' > f x'\r\n}}}\r\n\r\nBut not on GHC HEAD:\r\n\r\n{{{\r\n$ ~/Software/ghc4/inplace/bin/ghcstage2 Bug.hs dcorelint \r\n[1 of 1] Compiling Bug ( Bug.hs, Bug.o )\r\n*** Core Lint errors : in result of Desugar (before optimization) ***\r\n<no location info>: warning:\r\n In the expression: $ @ 'LiftedRep\r\n @ (forall (a :: Rep k_a1cV). Sing a > SomeSing k_a1cV)\r\n @ (SomeSing k_a1cV)\r\n (withSomeSing\r\n @ (Rep k_a1cV)\r\n @ (SomeSing k_a1cV)\r\n $dSingKind_a1d5\r\n ((from\r\n @ (Demote k_a1cV)\r\n $dGeneric_a1d7\r\n (d_aX7\r\n `cast` (Sub co_a1dK\r\n :: Demote k_a1cV[sk:1] ~R# Demote k_a1cV[sk:1])))\r\n `cast` (Sub (Sym (Sym co_a1dR ; Sym co_a1dM) ; (Sym co_a1dQ ; (Demote\r\n (Sym co_a1dO))_N))\r\n :: Rep (Demote k_a1cV[sk:1]) ~R# Demote (Rep k_a1cV[sk:1]))))\r\n (\\ (@ (a_a1dc :: Rep k_a1cV)) >\r\n let {\r\n $dSGeneric_a1dm :: SGeneric k_a1cV\r\n [LclId]\r\n $dSGeneric_a1dm = $dSGeneric_a1cY } in\r\n . @ (Sing (PTo Any))\r\n @ (SomeSing k_a1cV)\r\n @ (Sing Any)\r\n (SomeSing @ k_a1cV @ (PTo Any))\r\n ((sTo @ k_a1cV $dSGeneric_a1dm @ Any)\r\n `cast` (Sym (Sing\r\n (Sym co_a1dO) (Sym (GRefl nominal Any co_a1dO)))_R\r\n >_R <Sing (PTo Any)>_R\r\n :: (Sing Any > Sing (PTo Any))\r\n ~R# (Sing Any > Sing (PTo Any)))))\r\n Argument value doesn't match argument type:\r\n Fun type:\r\n (forall (a :: Rep k_a1cV). Sing a > SomeSing k_a1cV)\r\n > SomeSing k_a1cV\r\n Arg type: forall (a :: Rep k_a1cV). Sing Any > SomeSing k_a1cV\r\n Arg:\r\n \\ (@ (a_a1dc :: Rep k_a1cV)) >\r\n let {\r\n $dSGeneric_a1dm :: SGeneric k_a1cV\r\n [LclId]\r\n $dSGeneric_a1dm = $dSGeneric_a1cY } in\r\n . @ (Sing (PTo Any))\r\n @ (SomeSing k_a1cV)\r\n @ (Sing Any)\r\n (SomeSing @ k_a1cV @ (PTo Any))\r\n ((sTo @ k_a1cV $dSGeneric_a1dm @ Any)\r\n `cast` (Sym (Sing\r\n (Sym co_a1dO) (Sym (GRefl nominal Any co_a1dO)))_R\r\n >_R <Sing (PTo Any)>_R\r\n :: (Sing Any > Sing (PTo Any)) ~R# (Sing Any > Sing (PTo Any))))\r\n*** Offending Program ***\r\n<elided>\r\ngenericToSing\r\n :: forall k.\r\n (SingKind k, SGeneric k, SingKind (Rep k), Generic (Demote k),\r\n Rep (Demote k) ~ Demote (Rep k)) =>\r\n Demote k > SomeSing k\r\n[LclIdX]\r\ngenericToSing\r\n = \\ (@ k_a1cV)\r\n ($dSingKind_a1cX :: SingKind k_a1cV)\r\n ($dSGeneric_a1cY :: SGeneric k_a1cV)\r\n ($dSingKind_a1cZ :: SingKind (Rep k_a1cV))\r\n ($dGeneric_a1d0 :: Generic (Demote k_a1cV))\r\n ($d~_a1d1 :: Rep (Demote k_a1cV) ~ Demote (Rep k_a1cV)) >\r\n let {\r\n co_a1dQ :: Demote (Rep k_a1cV) ~# Demote (Rep k_a1cV)\r\n [LclId[CoVarId]]\r\n co_a1dQ = CO: <Demote (Rep k_a1cV)>_N } in\r\n let {\r\n co_a1dO :: Rep k_a1cV ~# Rep k_a1cV\r\n [LclId[CoVarId]]\r\n co_a1dO = CO: <Rep k_a1cV>_N } in\r\n let {\r\n $dSingKind_a1dT :: SingKind (Rep k_a1cV)\r\n [LclId]\r\n $dSingKind_a1dT\r\n = $dSingKind_a1cZ\r\n `cast` (Sub (Sym (SingKind (Sym co_a1dO))_N)\r\n :: SingKind (Rep k_a1cV[sk:1])\r\n ~R# SingKind (Rep k_a1cV[sk:1])) } in\r\n let {\r\n $dSingKind_a1d5 :: SingKind (Rep k_a1cV)\r\n [LclId]\r\n $dSingKind_a1d5\r\n = $dSingKind_a1dT\r\n `cast` ((SingKind (Sym co_a1dO))_R\r\n :: SingKind (Rep k_a1cV[sk:1])\r\n ~R# SingKind (Rep k_a1cV[sk:1])) } in\r\n let {\r\n co_a1dM :: Rep (Demote k_a1cV) ~# Rep (Demote k_a1cV)\r\n [LclId[CoVarId]]\r\n co_a1dM = CO: <Rep (Demote k_a1cV)>_N } in\r\n let {\r\n co_a1dK :: Demote k_a1cV ~# Demote k_a1cV\r\n [LclId[CoVarId]]\r\n co_a1dK = CO: <Demote k_a1cV>_N } in\r\n let {\r\n $dGeneric_a1dU :: Generic (Demote k_a1cV)\r\n [LclId]\r\n $dGeneric_a1dU\r\n = $dGeneric_a1d0\r\n `cast` (Sub (Sym (Generic (Sym co_a1dK))_N)\r\n :: Generic (Demote k_a1cV[sk:1])\r\n ~R# Generic (Demote k_a1cV[sk:1])) } in\r\n let {\r\n $dGeneric_a1d7 :: Generic (Demote k_a1cV)\r\n [LclId]\r\n $dGeneric_a1d7 = $dGeneric_a1dU } in\r\n case eq_sel\r\n @ * @ (Rep (Demote k_a1cV)) @ (Demote (Rep k_a1cV)) $d~_a1d1\r\n of co_a1dI\r\n { __DEFAULT >\r\n let {\r\n co_a1dR :: Rep (Demote k_a1cV) ~# Demote (Rep k_a1cV)\r\n [LclId[CoVarId]]\r\n co_a1dR\r\n = CO: ((Sym co_a1dM ; (Rep\r\n (Sym co_a1dK))_N) ; co_a1dI) ; Sym (Sym co_a1dQ ; (Demote\r\n (Sym co_a1dO))_N) } in\r\n \\ (d_aX7 :: Demote k_a1cV) >\r\n $ @ 'LiftedRep\r\n @ (forall (a :: Rep k_a1cV). Sing a > SomeSing k_a1cV)\r\n @ (SomeSing k_a1cV)\r\n (withSomeSing\r\n @ (Rep k_a1cV)\r\n @ (SomeSing k_a1cV)\r\n $dSingKind_a1d5\r\n ((from\r\n @ (Demote k_a1cV)\r\n $dGeneric_a1d7\r\n (d_aX7\r\n `cast` (Sub co_a1dK\r\n :: Demote k_a1cV[sk:1] ~R# Demote k_a1cV[sk:1])))\r\n `cast` (Sub (Sym (Sym co_a1dR ; Sym co_a1dM) ; (Sym co_a1dQ ; (Demote\r\n (Sym co_a1dO))_N))\r\n :: Rep (Demote k_a1cV[sk:1]) ~R# Demote (Rep k_a1cV[sk:1]))))\r\n (\\ (@ (a_a1dc :: Rep k_a1cV)) >\r\n let {\r\n $dSGeneric_a1dm :: SGeneric k_a1cV\r\n [LclId]\r\n $dSGeneric_a1dm = $dSGeneric_a1cY } in\r\n . @ (Sing (PTo Any))\r\n @ (SomeSing k_a1cV)\r\n @ (Sing Any)\r\n (SomeSing @ k_a1cV @ (PTo Any))\r\n ((sTo @ k_a1cV $dSGeneric_a1dm @ Any)\r\n `cast` (Sym (Sing\r\n (Sym co_a1dO) (Sym (GRefl nominal Any co_a1dO)))_R\r\n >_R <Sing (PTo Any)>_R\r\n :: (Sing Any > Sing (PTo Any)) ~R# (Sing Any > Sing (PTo Any)))))\r\n }\r\n}}}\r\n\r\nI'm not sure if this is related to #16188 (see https://ghc.haskell.org/trac/ghc/ticket/16188#comment:1), but this Core Lint error is technically different from the one in that ticket, so I decided to open a new issue for this.","type_of_failure":"OtherFailure","blocking":[]} >8.8.1https://gitlab.haskell.org/ghc/ghc//issues/16221Core Lint error with a data type20190707T18:00:55ZKrzysztof GogolewskiCore Lint error with a data typeThe following data declaration fails `dcorelint`
```haskell
{# LANGUAGE PolyKinds, ExplicitForAll, ExistentialQuantification #}
module T16221 where
data T0 a = forall k (b :: k). MkT0 (T0 b) !Int
```
The test case was extracted from T14066a, the bang is to force the data type to have a wrapper. This has been present at least since GHC 8.0.
```
<no location info>: warning:
In the type ‘T0 a_a1wY’
Kind application error in type ‘T0 a_a1wY’
Function kind = forall k. k > *
Arg kinds = [(k_X1x2, *), (a_a1wY, k_a1wZ)]
Fun: k_X1x2
(a_a1wY, k_a1wZ)
<no location info>: warning:
In the expression: MkT0
@ k_X1x2 @ a_a1wY @ k_X1x2 @ b_a1x0 dt_a1xC dt_X1xK
Kinds don't match in type application:
Type variable: a_X1xw :: k_X1x2
Arg type: a_a1wY :: k_a1wZ
Linted Arg kind: k_a1wZ
<no location info>: warning:
In the type ‘T0 a_a1wY’
Kind application error in type ‘T0 a_a1wY’
Function kind = forall k. k > *
Arg kinds = [(k_X1x2, *), (a_a1wY, k_a1wZ)]
Fun: k_X1x2
(a_a1wY, k_a1wZ)
<no location info>: warning:
In the expression: MkT0
@ k_X1x2 @ a_a1wY @ k_X1x2 @ b_a1x0 dt_a1xC dt_X1xK
Kinds don't match in type application:
Type variable: a_X1xw :: k_X1x2
Arg type: a_a1wY :: k_a1wZ
Linted Arg kind: k_a1wZ
```
<details><summary>Trac metadata</summary>
 Trac field  Value 
    
 Version  8.7 
 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":"Core Lint error with a data type","status":"New","operating_system":"","component":"Compiler (Type checker)","related":[],"milestone":"","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"8.7","keywords":[],"differentials":[],"test_case":"","architecture":"","cc":[""],"type":"Bug","description":"The following data declaration fails `dcorelint`\r\n\r\n{{{\r\n#!haskell\r\n{# LANGUAGE PolyKinds, ExplicitForAll, ExistentialQuantification #}\r\n\r\nmodule T16221 where\r\ndata T0 a = forall k (b :: k). MkT0 (T0 b) !Int\r\n}}}\r\n\r\nThe test case was extracted from T14066a, the bang is to force the data type to have a wrapper. This has been present at least since GHC 8.0.\r\n\r\n{{{\r\n<no location info>: warning:\r\n In the type ‘T0 a_a1wY’\r\n Kind application error in type ‘T0 a_a1wY’\r\n Function kind = forall k. k > *\r\n Arg kinds = [(k_X1x2, *), (a_a1wY, k_a1wZ)]\r\n Fun: k_X1x2\r\n (a_a1wY, k_a1wZ)\r\n<no location info>: warning:\r\n In the expression: MkT0\r\n @ k_X1x2 @ a_a1wY @ k_X1x2 @ b_a1x0 dt_a1xC dt_X1xK\r\n Kinds don't match in type application:\r\n Type variable: a_X1xw :: k_X1x2\r\n Arg type: a_a1wY :: k_a1wZ\r\n Linted Arg kind: k_a1wZ\r\n<no location info>: warning:\r\n In the type ‘T0 a_a1wY’\r\n Kind application error in type ‘T0 a_a1wY’\r\n Function kind = forall k. k > *\r\n Arg kinds = [(k_X1x2, *), (a_a1wY, k_a1wZ)]\r\n Fun: k_X1x2\r\n (a_a1wY, k_a1wZ)\r\n<no location info>: warning:\r\n In the expression: MkT0\r\n @ k_X1x2 @ a_a1wY @ k_X1x2 @ b_a1x0 dt_a1xC dt_X1xK\r\n Kinds don't match in type application:\r\n Type variable: a_X1xw :: k_X1x2\r\n Arg type: a_a1wY :: k_a1wZ\r\n Linted Arg kind: k_a1wZ\r\n}}}","type_of_failure":"OtherFailure","blocking":[]} >The following data declaration fails `dcorelint`
```haskell
{# LANGUAGE PolyKinds, ExplicitForAll, ExistentialQuantification #}
module T16221 where
data T0 a = forall k (b :: k). MkT0 (T0 b) !Int
```
The test case was extracted from T14066a, the bang is to force the data type to have a wrapper. This has been present at least since GHC 8.0.
```
<no location info>: warning:
In the type ‘T0 a_a1wY’
Kind application error in type ‘T0 a_a1wY’
Function kind = forall k. k > *
Arg kinds = [(k_X1x2, *), (a_a1wY, k_a1wZ)]
Fun: k_X1x2
(a_a1wY, k_a1wZ)
<no location info>: warning:
In the expression: MkT0
@ k_X1x2 @ a_a1wY @ k_X1x2 @ b_a1x0 dt_a1xC dt_X1xK
Kinds don't match in type application:
Type variable: a_X1xw :: k_X1x2
Arg type: a_a1wY :: k_a1wZ
Linted Arg kind: k_a1wZ
<no location info>: warning:
In the type ‘T0 a_a1wY’
Kind application error in type ‘T0 a_a1wY’
Function kind = forall k. k > *
Arg kinds = [(k_X1x2, *), (a_a1wY, k_a1wZ)]
Fun: k_X1x2
(a_a1wY, k_a1wZ)
<no location info>: warning:
In the expression: MkT0
@ k_X1x2 @ a_a1wY @ k_X1x2 @ b_a1x0 dt_a1xC dt_X1xK
Kinds don't match in type application:
Type variable: a_X1xw :: k_X1x2
Arg type: a_a1wY :: k_a1wZ
Linted Arg kind: k_a1wZ
```
<details><summary>Trac metadata</summary>
 Trac field  Value 
    
 Version  8.7 
 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":"Core Lint error with a data type","status":"New","operating_system":"","component":"Compiler (Type checker)","related":[],"milestone":"","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"8.7","keywords":[],"differentials":[],"test_case":"","architecture":"","cc":[""],"type":"Bug","description":"The following data declaration fails `dcorelint`\r\n\r\n{{{\r\n#!haskell\r\n{# LANGUAGE PolyKinds, ExplicitForAll, ExistentialQuantification #}\r\n\r\nmodule T16221 where\r\ndata T0 a = forall k (b :: k). MkT0 (T0 b) !Int\r\n}}}\r\n\r\nThe test case was extracted from T14066a, the bang is to force the data type to have a wrapper. This has been present at least since GHC 8.0.\r\n\r\n{{{\r\n<no location info>: warning:\r\n In the type ‘T0 a_a1wY’\r\n Kind application error in type ‘T0 a_a1wY’\r\n Function kind = forall k. k > *\r\n Arg kinds = [(k_X1x2, *), (a_a1wY, k_a1wZ)]\r\n Fun: k_X1x2\r\n (a_a1wY, k_a1wZ)\r\n<no location info>: warning:\r\n In the expression: MkT0\r\n @ k_X1x2 @ a_a1wY @ k_X1x2 @ b_a1x0 dt_a1xC dt_X1xK\r\n Kinds don't match in type application:\r\n Type variable: a_X1xw :: k_X1x2\r\n Arg type: a_a1wY :: k_a1wZ\r\n Linted Arg kind: k_a1wZ\r\n<no location info>: warning:\r\n In the type ‘T0 a_a1wY’\r\n Kind application error in type ‘T0 a_a1wY’\r\n Function kind = forall k. k > *\r\n Arg kinds = [(k_X1x2, *), (a_a1wY, k_a1wZ)]\r\n Fun: k_X1x2\r\n (a_a1wY, k_a1wZ)\r\n<no location info>: warning:\r\n In the expression: MkT0\r\n @ k_X1x2 @ a_a1wY @ k_X1x2 @ b_a1x0 dt_a1xC dt_X1xK\r\n Kinds don't match in type application:\r\n Type variable: a_X1xw :: k_X1x2\r\n Arg type: a_a1wY :: k_a1wZ\r\n Linted Arg kind: k_a1wZ\r\n}}}","type_of_failure":"OtherFailure","blocking":[]} >8.10.1https://gitlab.haskell.org/ghc/ghc//issues/16225GHC HEADonly Core Lint error (Trans coercion mismatch)20190707T18:00:54ZRyan ScottGHC HEADonly Core Lint error (Trans coercion mismatch)The following code compiles on GHC 8.0.2 through GHC 8.6.3 with `dcorelint`:
```hs
{# LANGUAGE AllowAmbiguousTypes #}
{# LANGUAGE GADTs #}
{# LANGUAGE TypeFamilies #}
{# LANGUAGE TypeInType #}
{# LANGUAGE TypeOperators #}
module Bug where
import Data.Kind
data family Sing :: k > Type
data TyFun :: Type > Type > Type
type a ~> b = TyFun a b > Type
infixr 0 ~>
type family Apply (f :: a ~> b) (x :: a) :: b
data TyCon1 :: (k1 > k2) > (k1 ~> k2)
type instance Apply (TyCon1 f) x = f x
data SomeApply :: (k ~> Type) > Type where
SomeApply :: Apply f a > SomeApply f
f :: SomeApply (TyCon1 Sing :: k ~> Type)
> SomeApply (TyCon1 Sing :: k ~> Type)
f (SomeApply s)
= SomeApply s
```
However, it chokes on GHC HEAD:
```
$ ~/Software/ghc4/inplace/bin/ghcstage2 interactive Bug.hs dcorelint
GHCi, version 8.7.20190120: https://www.haskell.org/ghc/ :? for help
Loaded GHCi configuration from /home/rgscott/.ghci
[1 of 1] Compiling Bug ( Bug.hs, interpreted )
*** Core Lint errors : in result of Desugar (before optimization) ***
<no location info>: warning:
In the expression: SomeApply
@ k_a1Dz
@ (TyCon1 Sing)
@ Any
(s_a1Bq
`cast` (Sub (D:R:ApplyabTyCon1x[0]
<k_a1Dz>_N
<*>_N
<Sing>_N
<a_a1DB>_N ; Sym (D:R:ApplyabTyCon1x[0]
<k_a1Dz>_N <*>_N <Sing>_N <Any>_N))
:: Apply (TyCon1 Sing) a_a1DB ~R# Apply (TyCon1 Sing) Any))
Trans coercion mismatch: D:R:ApplyabTyCon1x[0]
<k_a1Dz>_N <*>_N <Sing>_N <a_a1DB>_N ; Sym (D:R:ApplyabTyCon1x[0]
<k_a1Dz>_N
<*>_N
<Sing>_N
<Any>_N)
Apply (TyCon1 Sing) a_a1DB
Sing a_a1DB
Sing Any
Apply (TyCon1 Sing) Any
*** Offending Program ***
<elided>
f :: forall k. SomeApply (TyCon1 Sing) > SomeApply (TyCon1 Sing)
[LclIdX]
f = \ (@ k_a1Dz) (ds_d1EV :: SomeApply (TyCon1 Sing)) >
case ds_d1EV of wild_00 { SomeApply @ a_a1DB s_a1Bq >
break<0>(s_a1Bq)
SomeApply
@ k_a1Dz
@ (TyCon1 Sing)
@ Any
(s_a1Bq
`cast` (Sub (D:R:ApplyabTyCon1x[0]
<k_a1Dz>_N <*>_N <Sing>_N <a_a1DB>_N ; Sym (D:R:ApplyabTyCon1x[0]
<k_a1Dz>_N
<*>_N
<Sing>_N
<Any>_N))
:: Apply (TyCon1 Sing) a_a1DB ~R# Apply (TyCon1 Sing) Any))
}
```
Note that if I change the definition of `Sing` to this:
```hs
data family Sing (a :: k)
```
Then the error goes away.
Also, if I extend `SomeProxy` with an additional `proxy` field:
```hs
data SomeApply :: (k ~> Type) > Type where
SomeApply :: proxy a > Apply f a > SomeApply f
f :: SomeApply (TyCon1 Sing :: k ~> Type)
> SomeApply (TyCon1 Sing :: k ~> Type)
f (SomeApply p s)
= SomeApply p s
```
Then the error also goes away. Perhaps `a` being ambiguous plays an important role here?
Possibly related to #16188 or #16204.
<details><summary>Trac metadata</summary>
 Trac field  Value 
    
 Version  8.7 
 Type  Bug 
 TypeOfFailure  OtherFailure 
 Priority  highest 
 Resolution  Unresolved 
 Component  Compiler (Type checker) 
 Test case  
 Differential revisions  
 BlockedBy  
 Related  
 Blocking  
 CC  
 Operating system  
 Architecture  
</details>
<! {"blocked_by":[],"summary":"GHC HEADonly Core Lint error (Trans coercion mismatch)","status":"New","operating_system":"","component":"Compiler (Type checker)","related":[],"milestone":"8.8.1","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"8.7","keywords":["TypeInType"],"differentials":[],"test_case":"","architecture":"","cc":[""],"type":"Bug","description":"The following code compiles on GHC 8.0.2 through GHC 8.6.3 with `dcorelint`:\r\n\r\n{{{#!hs\r\n{# LANGUAGE AllowAmbiguousTypes #}\r\n{# LANGUAGE GADTs #}\r\n{# LANGUAGE TypeFamilies #}\r\n{# LANGUAGE TypeInType #}\r\n{# LANGUAGE TypeOperators #}\r\nmodule Bug where\r\n\r\nimport Data.Kind\r\n\r\ndata family Sing :: k > Type\r\ndata TyFun :: Type > Type > Type\r\ntype a ~> b = TyFun a b > Type\r\ninfixr 0 ~>\r\ntype family Apply (f :: a ~> b) (x :: a) :: b\r\n\r\ndata TyCon1 :: (k1 > k2) > (k1 ~> k2)\r\ntype instance Apply (TyCon1 f) x = f x\r\n\r\ndata SomeApply :: (k ~> Type) > Type where\r\n SomeApply :: Apply f a > SomeApply f\r\n\r\nf :: SomeApply (TyCon1 Sing :: k ~> Type)\r\n > SomeApply (TyCon1 Sing :: k ~> Type)\r\nf (SomeApply s)\r\n = SomeApply s\r\n}}}\r\n\r\nHowever, it chokes on GHC HEAD:\r\n\r\n{{{\r\n$ ~/Software/ghc4/inplace/bin/ghcstage2 interactive Bug.hs dcorelint\r\nGHCi, version 8.7.20190120: https://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*** Core Lint errors : in result of Desugar (before optimization) ***\r\n<no location info>: warning:\r\n In the expression: SomeApply\r\n @ k_a1Dz\r\n @ (TyCon1 Sing)\r\n @ Any\r\n (s_a1Bq\r\n `cast` (Sub (D:R:ApplyabTyCon1x[0]\r\n <k_a1Dz>_N\r\n <*>_N\r\n <Sing>_N\r\n <a_a1DB>_N ; Sym (D:R:ApplyabTyCon1x[0]\r\n <k_a1Dz>_N <*>_N <Sing>_N <Any>_N))\r\n :: Apply (TyCon1 Sing) a_a1DB ~R# Apply (TyCon1 Sing) Any))\r\n Trans coercion mismatch: D:R:ApplyabTyCon1x[0]\r\n <k_a1Dz>_N <*>_N <Sing>_N <a_a1DB>_N ; Sym (D:R:ApplyabTyCon1x[0]\r\n <k_a1Dz>_N\r\n <*>_N\r\n <Sing>_N\r\n <Any>_N)\r\n Apply (TyCon1 Sing) a_a1DB\r\n Sing a_a1DB\r\n Sing Any\r\n Apply (TyCon1 Sing) Any\r\n*** Offending Program ***\r\n\r\n<elided>\r\n\r\nf :: forall k. SomeApply (TyCon1 Sing) > SomeApply (TyCon1 Sing)\r\n[LclIdX]\r\nf = \\ (@ k_a1Dz) (ds_d1EV :: SomeApply (TyCon1 Sing)) >\r\n case ds_d1EV of wild_00 { SomeApply @ a_a1DB s_a1Bq >\r\n break<0>(s_a1Bq)\r\n SomeApply\r\n @ k_a1Dz\r\n @ (TyCon1 Sing)\r\n @ Any\r\n (s_a1Bq\r\n `cast` (Sub (D:R:ApplyabTyCon1x[0]\r\n <k_a1Dz>_N <*>_N <Sing>_N <a_a1DB>_N ; Sym (D:R:ApplyabTyCon1x[0]\r\n <k_a1Dz>_N\r\n <*>_N\r\n <Sing>_N\r\n <Any>_N))\r\n :: Apply (TyCon1 Sing) a_a1DB ~R# Apply (TyCon1 Sing) Any))\r\n }\r\n}}}\r\n\r\nNote that if I change the definition of `Sing` to this:\r\n\r\n{{{#!hs\r\ndata family Sing (a :: k)\r\n}}}\r\n\r\nThen the error goes away.\r\n\r\nAlso, if I extend `SomeProxy` with an additional `proxy` field:\r\n\r\n{{{#!hs\r\ndata SomeApply :: (k ~> Type) > Type where\r\n SomeApply :: proxy a > Apply f a > SomeApply f\r\n\r\nf :: SomeApply (TyCon1 Sing :: k ~> Type)\r\n > SomeApply (TyCon1 Sing :: k ~> Type)\r\nf (SomeApply p s)\r\n = SomeApply p s\r\n}}}\r\n\r\nThen the error also goes away. Perhaps `a` being ambiguous plays an important role here?\r\n\r\nPossibly related to #16188 or #16204.","type_of_failure":"OtherFailure","blocking":[]} >The following code compiles on GHC 8.0.2 through GHC 8.6.3 with `dcorelint`:
```hs
{# LANGUAGE AllowAmbiguousTypes #}
{# LANGUAGE GADTs #}
{# LANGUAGE TypeFamilies #}
{# LANGUAGE TypeInType #}
{# LANGUAGE TypeOperators #}
module Bug where
import Data.Kind
data family Sing :: k > Type
data TyFun :: Type > Type > Type
type a ~> b = TyFun a b > Type
infixr 0 ~>
type family Apply (f :: a ~> b) (x :: a) :: b
data TyCon1 :: (k1 > k2) > (k1 ~> k2)
type instance Apply (TyCon1 f) x = f x
data SomeApply :: (k ~> Type) > Type where
SomeApply :: Apply f a > SomeApply f
f :: SomeApply (TyCon1 Sing :: k ~> Type)
> SomeApply (TyCon1 Sing :: k ~> Type)
f (SomeApply s)
= SomeApply s
```
However, it chokes on GHC HEAD:
```
$ ~/Software/ghc4/inplace/bin/ghcstage2 interactive Bug.hs dcorelint
GHCi, version 8.7.20190120: https://www.haskell.org/ghc/ :? for help
Loaded GHCi configuration from /home/rgscott/.ghci
[1 of 1] Compiling Bug ( Bug.hs, interpreted )
*** Core Lint errors : in result of Desugar (before optimization) ***
<no location info>: warning:
In the expression: SomeApply
@ k_a1Dz
@ (TyCon1 Sing)
@ Any
(s_a1Bq
`cast` (Sub (D:R:ApplyabTyCon1x[0]
<k_a1Dz>_N
<*>_N
<Sing>_N
<a_a1DB>_N ; Sym (D:R:ApplyabTyCon1x[0]
<k_a1Dz>_N <*>_N <Sing>_N <Any>_N))
:: Apply (TyCon1 Sing) a_a1DB ~R# Apply (TyCon1 Sing) Any))
Trans coercion mismatch: D:R:ApplyabTyCon1x[0]
<k_a1Dz>_N <*>_N <Sing>_N <a_a1DB>_N ; Sym (D:R:ApplyabTyCon1x[0]
<k_a1Dz>_N
<*>_N
<Sing>_N
<Any>_N)
Apply (TyCon1 Sing) a_a1DB
Sing a_a1DB
Sing Any
Apply (TyCon1 Sing) Any
*** Offending Program ***
<elided>
f :: forall k. SomeApply (TyCon1 Sing) > SomeApply (TyCon1 Sing)
[LclIdX]
f = \ (@ k_a1Dz) (ds_d1EV :: SomeApply (TyCon1 Sing)) >
case ds_d1EV of wild_00 { SomeApply @ a_a1DB s_a1Bq >
break<0>(s_a1Bq)
SomeApply
@ k_a1Dz
@ (TyCon1 Sing)
@ Any
(s_a1Bq
`cast` (Sub (D:R:ApplyabTyCon1x[0]
<k_a1Dz>_N <*>_N <Sing>_N <a_a1DB>_N ; Sym (D:R:ApplyabTyCon1x[0]
<k_a1Dz>_N
<*>_N
<Sing>_N
<Any>_N))
:: Apply (TyCon1 Sing) a_a1DB ~R# Apply (TyCon1 Sing) Any))
}
```
Note that if I change the definition of `Sing` to this:
```hs
data family Sing (a :: k)
```
Then the error goes away.
Also, if I extend `SomeProxy` with an additional `proxy` field:
```hs
data SomeApply :: (k ~> Type) > Type where
SomeApply :: proxy a > Apply f a > SomeApply f
f :: SomeApply (TyCon1 Sing :: k ~> Type)
> SomeApply (TyCon1 Sing :: k ~> Type)
f (SomeApply p s)
= SomeApply p s
```
Then the error also goes away. Perhaps `a` being ambiguous plays an important role here?
Possibly related to #16188 or #16204.
<details><summary>Trac metadata</summary>
 Trac field  Value 
    
 Version  8.7 
 Type  Bug 
 TypeOfFailure  OtherFailure 
 Priority  highest 
 Resolution  Unresolved 
 Component  Compiler (Type checker) 
 Test case  
 Differential revisions  
 BlockedBy  
 Related  
 Blocking  
 CC  
 Operating system  
 Architecture  
</details>
<! {"blocked_by":[],"summary":"GHC HEADonly Core Lint error (Trans coercion mismatch)","status":"New","operating_system":"","component":"Compiler (Type checker)","related":[],"milestone":"8.8.1","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"8.7","keywords":["TypeInType"],"differentials":[],"test_case":"","architecture":"","cc":[""],"type":"Bug","description":"The following code compiles on GHC 8.0.2 through GHC 8.6.3 with `dcorelint`:\r\n\r\n{{{#!hs\r\n{# LANGUAGE AllowAmbiguousTypes #}\r\n{# LANGUAGE GADTs #}\r\n{# LANGUAGE TypeFamilies #}\r\n{# LANGUAGE TypeInType #}\r\n{# LANGUAGE TypeOperators #}\r\nmodule Bug where\r\n\r\nimport Data.Kind\r\n\r\ndata family Sing :: k > Type\r\ndata TyFun :: Type > Type > Type\r\ntype a ~> b = TyFun a b > Type\r\ninfixr 0 ~>\r\ntype family Apply (f :: a ~> b) (x :: a) :: b\r\n\r\ndata TyCon1 :: (k1 > k2) > (k1 ~> k2)\r\ntype instance Apply (TyCon1 f) x = f x\r\n\r\ndata SomeApply :: (k ~> Type) > Type where\r\n SomeApply :: Apply f a > SomeApply f\r\n\r\nf :: SomeApply (TyCon1 Sing :: k ~> Type)\r\n > SomeApply (TyCon1 Sing :: k ~> Type)\r\nf (SomeApply s)\r\n = SomeApply s\r\n}}}\r\n\r\nHowever, it chokes on GHC HEAD:\r\n\r\n{{{\r\n$ ~/Software/ghc4/inplace/bin/ghcstage2 interactive Bug.hs dcorelint\r\nGHCi, version 8.7.20190120: https://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*** Core Lint errors : in result of Desugar (before optimization) ***\r\n<no location info>: warning:\r\n In the expression: SomeApply\r\n @ k_a1Dz\r\n @ (TyCon1 Sing)\r\n @ Any\r\n (s_a1Bq\r\n `cast` (Sub (D:R:ApplyabTyCon1x[0]\r\n <k_a1Dz>_N\r\n <*>_N\r\n <Sing>_N\r\n <a_a1DB>_N ; Sym (D:R:ApplyabTyCon1x[0]\r\n <k_a1Dz>_N <*>_N <Sing>_N <Any>_N))\r\n :: Apply (TyCon1 Sing) a_a1DB ~R# Apply (TyCon1 Sing) Any))\r\n Trans coercion mismatch: D:R:ApplyabTyCon1x[0]\r\n <k_a1Dz>_N <*>_N <Sing>_N <a_a1DB>_N ; Sym (D:R:ApplyabTyCon1x[0]\r\n <k_a1Dz>_N\r\n <*>_N\r\n <Sing>_N\r\n <Any>_N)\r\n Apply (TyCon1 Sing) a_a1DB\r\n Sing a_a1DB\r\n Sing Any\r\n Apply (TyCon1 Sing) Any\r\n*** Offending Program ***\r\n\r\n<elided>\r\n\r\nf :: forall k. SomeApply (TyCon1 Sing) > SomeApply (TyCon1 Sing)\r\n[LclIdX]\r\nf = \\ (@ k_a1Dz) (ds_d1EV :: SomeApply (TyCon1 Sing)) >\r\n case ds_d1EV of wild_00 { SomeApply @ a_a1DB s_a1Bq >\r\n break<0>(s_a1Bq)\r\n SomeApply\r\n @ k_a1Dz\r\n @ (TyCon1 Sing)\r\n @ Any\r\n (s_a1Bq\r\n `cast` (Sub (D:R:ApplyabTyCon1x[0]\r\n <k_a1Dz>_N <*>_N <Sing>_N <a_a1DB>_N ; Sym (D:R:ApplyabTyCon1x[0]\r\n <k_a1Dz>_N\r\n <*>_N\r\n <Sing>_N\r\n <Any>_N))\r\n :: Apply (TyCon1 Sing) a_a1DB ~R# Apply (TyCon1 Sing) Any))\r\n }\r\n}}}\r\n\r\nNote that if I change the definition of `Sing` to this:\r\n\r\n{{{#!hs\r\ndata family Sing (a :: k)\r\n}}}\r\n\r\nThen the error goes away.\r\n\r\nAlso, if I extend `SomeProxy` with an additional `proxy` field:\r\n\r\n{{{#!hs\r\ndata SomeApply :: (k ~> Type) > Type where\r\n SomeApply :: proxy a > Apply f a > SomeApply f\r\n\r\nf :: SomeApply (TyCon1 Sing :: k ~> Type)\r\n > SomeApply (TyCon1 Sing :: k ~> Type)\r\nf (SomeApply p s)\r\n = SomeApply p s\r\n}}}\r\n\r\nThen the error also goes away. Perhaps `a` being ambiguous plays an important role here?\r\n\r\nPossibly related to #16188 or #16204.","type_of_failure":"OtherFailure","blocking":[]} >8.8.1https://gitlab.haskell.org/ghc/ghc//issues/16244Couldn't match kind ‘k1’ with ‘k1’20200505T09:44:28ZRyan ScottCouldn't match kind ‘k1’ with ‘k1’The following program gives a hopelessly confusing error message on GHC 8.6.3 and HEAD:
```hs
{# LANGUAGE ConstraintKinds #}
{# LANGUAGE DataKinds #}
{# LANGUAGE MultiParamTypeClasses #}
{# LANGUAGE PolyKinds #}
module Bug where
import Data.Kind
type Const a b = a
type SameKind (a :: k) (b :: k) = (() :: Constraint)
class SameKind a b => C (k :: Const Type a) (b :: k)
```
```
$ /opt/ghc/8.6.3/bin/ghc Bug.hs
[1 of 1] Compiling Bug ( Bug.hs, Bug.o )
Bug.hs:11:18: error:
• Couldn't match kind ‘k1’ with ‘k1’
• In the second argument of ‘SameKind’, namely ‘b’
In the class declaration for ‘C’

11  class SameKind a b => C (k :: Const Type a) (b :: k)
 ^
```
I imagine that the real issue is that `SameKind a b` would force `a :: k`, which would be illscoped. But figuring that out from this strange error message requires a lot of thought.
<details><summary>Trac metadata</summary>
 Trac field  Value 
    
 Version  8.6.3 
 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":"Couldn't match kind ‘k1’ with ‘k1’","status":"New","operating_system":"","component":"Compiler (Type checker)","related":[],"milestone":"8.10.1","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"8.6.3","keywords":["TypeInType"],"differentials":[],"test_case":"","architecture":"","cc":[""],"type":"Bug","description":"The following program gives a hopelessly confusing error message on GHC 8.6.3 and HEAD:\r\n\r\n{{{#!hs\r\n{# LANGUAGE ConstraintKinds #}\r\n{# LANGUAGE DataKinds #}\r\n{# LANGUAGE MultiParamTypeClasses #}\r\n{# LANGUAGE PolyKinds #}\r\nmodule Bug where\r\n\r\nimport Data.Kind\r\n\r\ntype Const a b = a\r\ntype SameKind (a :: k) (b :: k) = (() :: Constraint)\r\nclass SameKind a b => C (k :: Const Type a) (b :: k)\r\n}}}\r\n{{{\r\n$ /opt/ghc/8.6.3/bin/ghc Bug.hs\r\n[1 of 1] Compiling Bug ( Bug.hs, Bug.o )\r\n\r\nBug.hs:11:18: error:\r\n • Couldn't match kind ‘k1’ with ‘k1’\r\n • In the second argument of ‘SameKind’, namely ‘b’\r\n In the class declaration for ‘C’\r\n \r\n11  class SameKind a b => C (k :: Const Type a) (b :: k)\r\n  ^\r\n}}}\r\n\r\nI imagine that the real issue is that `SameKind a b` would force `a :: k`, which would be illscoped. But figuring that out from this strange error message requires a lot of thought.","type_of_failure":"OtherFailure","blocking":[]} >The following program gives a hopelessly confusing error message on GHC 8.6.3 and HEAD:
```hs
{# LANGUAGE ConstraintKinds #}
{# LANGUAGE DataKinds #}
{# LANGUAGE MultiParamTypeClasses #}
{# LANGUAGE PolyKinds #}
module Bug where
import Data.Kind
type Const a b = a
type SameKind (a :: k) (b :: k) = (() :: Constraint)
class SameKind a b => C (k :: Const Type a) (b :: k)
```
```
$ /opt/ghc/8.6.3/bin/ghc Bug.hs
[1 of 1] Compiling Bug ( Bug.hs, Bug.o )
Bug.hs:11:18: error:
• Couldn't match kind ‘k1’ with ‘k1’
• In the second argument of ‘SameKind’, namely ‘b’
In the class declaration for ‘C’

11  class SameKind a b => C (k :: Const Type a) (b :: k)
 ^
```
I imagine that the real issue is that `SameKind a b` would force `a :: k`, which would be illscoped. But figuring that out from this strange error message requires a lot of thought.
<details><summary>Trac metadata</summary>
 Trac field  Value 
    
 Version  8.6.3 
 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":"Couldn't match kind ‘k1’ with ‘k1’","status":"New","operating_system":"","component":"Compiler (Type checker)","related":[],"milestone":"8.10.1","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"8.6.3","keywords":["TypeInType"],"differentials":[],"test_case":"","architecture":"","cc":[""],"type":"Bug","description":"The following program gives a hopelessly confusing error message on GHC 8.6.3 and HEAD:\r\n\r\n{{{#!hs\r\n{# LANGUAGE ConstraintKinds #}\r\n{# LANGUAGE DataKinds #}\r\n{# LANGUAGE MultiParamTypeClasses #}\r\n{# LANGUAGE PolyKinds #}\r\nmodule Bug where\r\n\r\nimport Data.Kind\r\n\r\ntype Const a b = a\r\ntype SameKind (a :: k) (b :: k) = (() :: Constraint)\r\nclass SameKind a b => C (k :: Const Type a) (b :: k)\r\n}}}\r\n{{{\r\n$ /opt/ghc/8.6.3/bin/ghc Bug.hs\r\n[1 of 1] Compiling Bug ( Bug.hs, Bug.o )\r\n\r\nBug.hs:11:18: error:\r\n • Couldn't match kind ‘k1’ with ‘k1’\r\n • In the second argument of ‘SameKind’, namely ‘b’\r\n In the class declaration for ‘C’\r\n \r\n11  class SameKind a b => C (k :: Const Type a) (b :: k)\r\n  ^\r\n}}}\r\n\r\nI imagine that the real issue is that `SameKind a b` would force `a :: k`, which would be illscoped. But figuring that out from this strange error message requires a lot of thought.","type_of_failure":"OtherFailure","blocking":[]} >https://gitlab.haskell.org/ghc/ghc//issues/16245GHC panic (No skolem info) with RankNTypes and strange scoping20201231T13:44:06ZRyan ScottGHC panic (No skolem info) with RankNTypes and strange scopingThe following program panics with GHC 8.6.3 and HEAD:
```hs
{# LANGUAGE ConstraintKinds #}
{# LANGUAGE DataKinds #}
{# LANGUAGE PolyKinds #}
{# LANGUAGE QuantifiedConstraints #}
module Bug where
import Data.Kind
type Const a b = a
type SameKind (a :: k) (b :: k) = (() :: Constraint)
class (forall (b :: k). SameKind a b) => C (k :: Const Type a)
```
```
$ /opt/ghc/8.6.3/bin/ghc Bug.hs
[1 of 1] Compiling Bug ( Bug.hs, Bug.o )
Bug.hs:11:36: error:ghc: panic! (the 'impossible' happened)
(GHC version 8.6.3 for x86_64unknownlinux):
No skolem info:
[k1_a1X4[sk:1]]
Call stack:
CallStack (from HasCallStack):
callStackDoc, called at compiler/utils/Outputable.hs:1160:37 in ghc:Outputable
pprPanic, called at compiler/typecheck/TcErrors.hs:2891:5 in ghc:TcErrors
```
As with #16244, I imagine that the real culprit is that `SameKind a b` would force `a :: k`, which would be illscoped.
<details><summary>Trac metadata</summary>
 Trac field  Value 
    
 Version  8.6.3 
 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 (No skolem info) with QuantifiedConstraints and strange scoping","status":"New","operating_system":"","component":"Compiler (Type checker)","related":[],"milestone":"","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"8.6.3","keywords":["QuantifiedConstraints","TypeInType,"],"differentials":[],"test_case":"","architecture":"","cc":[""],"type":"Bug","description":"The following program panics with GHC 8.6.3 and HEAD:\r\n\r\n{{{#!hs\r\n{# LANGUAGE ConstraintKinds #}\r\n{# LANGUAGE DataKinds #}\r\n{# LANGUAGE PolyKinds #}\r\n{# LANGUAGE QuantifiedConstraints #}\r\nmodule Bug where\r\n\r\nimport Data.Kind\r\n\r\ntype Const a b = a\r\ntype SameKind (a :: k) (b :: k) = (() :: Constraint)\r\nclass (forall (b :: k). SameKind a b) => C (k :: Const Type a)\r\n}}}\r\n{{{\r\n$ /opt/ghc/8.6.3/bin/ghc Bug.hs\r\n[1 of 1] Compiling Bug ( Bug.hs, Bug.o )\r\n\r\nBug.hs:11:36: error:ghc: panic! (the 'impossible' happened)\r\n (GHC version 8.6.3 for x86_64unknownlinux):\r\n No skolem info:\r\n [k1_a1X4[sk:1]]\r\n Call stack:\r\n CallStack (from HasCallStack):\r\n callStackDoc, called at compiler/utils/Outputable.hs:1160:37 in ghc:Outputable\r\n pprPanic, called at compiler/typecheck/TcErrors.hs:2891:5 in ghc:TcErrors\r\n}}}\r\n\r\nAs with #16244, I imagine that the real culprit is that `SameKind a b` would force `a :: k`, which would be illscoped.","type_of_failure":"OtherFailure","blocking":[]} >The following program panics with GHC 8.6.3 and HEAD:
```hs
{# LANGUAGE ConstraintKinds #}
{# LANGUAGE DataKinds #}
{# LANGUAGE PolyKinds #}
{# LANGUAGE QuantifiedConstraints #}
module Bug where
import Data.Kind
type Const a b = a
type SameKind (a :: k) (b :: k) = (() :: Constraint)
class (forall (b :: k). SameKind a b) => C (k :: Const Type a)
```
```
$ /opt/ghc/8.6.3/bin/ghc Bug.hs
[1 of 1] Compiling Bug ( Bug.hs, Bug.o )
Bug.hs:11:36: error:ghc: panic! (the 'impossible' happened)
(GHC version 8.6.3 for x86_64unknownlinux):
No skolem info:
[k1_a1X4[sk:1]]
Call stack:
CallStack (from HasCallStack):
callStackDoc, called at compiler/utils/Outputable.hs:1160:37 in ghc:Outputable
pprPanic, called at compiler/typecheck/TcErrors.hs:2891:5 in ghc:TcErrors
```
As with #16244, I imagine that the real culprit is that `SameKind a b` would force `a :: k`, which would be illscoped.
<details><summary>Trac metadata</summary>
 Trac field  Value 
    
 Version  8.6.3 
 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 (No skolem info) with QuantifiedConstraints and strange scoping","status":"New","operating_system":"","component":"Compiler (Type checker)","related":[],"milestone":"","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"8.6.3","keywords":["QuantifiedConstraints","TypeInType,"],"differentials":[],"test_case":"","architecture":"","cc":[""],"type":"Bug","description":"The following program panics with GHC 8.6.3 and HEAD:\r\n\r\n{{{#!hs\r\n{# LANGUAGE ConstraintKinds #}\r\n{# LANGUAGE DataKinds #}\r\n{# LANGUAGE PolyKinds #}\r\n{# LANGUAGE QuantifiedConstraints #}\r\nmodule Bug where\r\n\r\nimport Data.Kind\r\n\r\ntype Const a b = a\r\ntype SameKind (a :: k) (b :: k) = (() :: Constraint)\r\nclass (forall (b :: k). SameKind a b) => C (k :: Const Type a)\r\n}}}\r\n{{{\r\n$ /opt/ghc/8.6.3/bin/ghc Bug.hs\r\n[1 of 1] Compiling Bug ( Bug.hs, Bug.o )\r\n\r\nBug.hs:11:36: error:ghc: panic! (the 'impossible' happened)\r\n (GHC version 8.6.3 for x86_64unknownlinux):\r\n No skolem info:\r\n [k1_a1X4[sk:1]]\r\n Call stack:\r\n CallStack (from HasCallStack):\r\n callStackDoc, called at compiler/utils/Outputable.hs:1160:37 in ghc:Outputable\r\n pprPanic, called at compiler/typecheck/TcErrors.hs:2891:5 in ghc:TcErrors\r\n}}}\r\n\r\nAs with #16244, I imagine that the real culprit is that `SameKind a b` would force `a :: k`, which would be illscoped.","type_of_failure":"OtherFailure","blocking":[]} >https://gitlab.haskell.org/ghc/ghc//issues/16247GHC 8.6 Core Lint regression (Kind application error)20190707T18:00:49ZRyan ScottGHC 8.6 Core Lint regression (Kind application error)The following program produces a Core Lint error on GHC 8.6.3 and HEAD:
```hs
{# LANGUAGE GADTs #}
{# LANGUAGE ScopedTypeVariables #}
{# LANGUAGE TypeInType #}
module Bug where
import Data.Kind
data SameKind :: forall k. k > k > Type
data Foo :: forall a k (b :: k). SameKind a b > Type where
MkFoo :: Foo sameKind
```
```
$ /opt/ghc/8.6.3/bin/ghc Bug.hs dcorelint
[1 of 1] Compiling Bug ( Bug.hs, Bug.o )
*** Core Lint errors : in result of CorePrep ***
<no location info>: warning:
In the type ‘forall k (a :: k) k (b :: k) (sameKind :: SameKind
a b).
Foo sameKind’
Kind application error in type ‘SameKind a_aWE b_aWG’
Function kind = forall k. k > k > *
Arg kinds = [(k_aWF, *), (a_aWE, k_aWD), (b_aWG, k_aWF)]
Fun: k_aWF
(a_aWE, k_aWD)
*** Offending Program ***
<elided>
MkFoo
:: forall k (a :: k) k (b :: k) (sameKind :: SameKind a b).
Foo sameKind
```
(Confusingly, the type of `MkFoo` is rendered as `forall k (a :: k) k (b :: k) (sameKind :: SameKind a b). Foo sameKind` in that `dcorelint` error, but I think it really should be `forall k1 (a :: k1) k2 (b :: k2) (sameKind :: SameKind a b). Foo sameKind`.)
On GHC 8.4.4 and earlier, this simply produces an error message:
```
$ /opt/ghc/8.4.4/bin/ghc Bug.hs dcorelint
[1 of 1] Compiling Bug ( Bug.hs, Bug.o )
Bug.hs:9:13: error:
• These kind and type variables: a k (b :: k)
are out of dependency order. Perhaps try this ordering:
k (a :: k) (b :: k)
• In the kind ‘forall a k (b :: k). SameKind a b > Type’

9  data Foo :: forall a k (b :: k). SameKind a b > Type where
 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
```
<details><summary>Trac metadata</summary>
 Trac field  Value 
    
 Version  8.6.3 
 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.6 Core Lint regression (Kind application error)","status":"New","operating_system":"","component":"Compiler (Type checker)","related":[],"milestone":"8.10.1","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"8.6.3","keywords":["TypeInType"],"differentials":[],"test_case":"","architecture":"","cc":[""],"type":"Bug","description":"The following program produces a Core Lint error on GHC 8.6.3 and HEAD:\r\n\r\n{{{#!hs\r\n{# LANGUAGE GADTs #}\r\n{# LANGUAGE ScopedTypeVariables #}\r\n{# LANGUAGE TypeInType #}\r\nmodule Bug where\r\n\r\nimport Data.Kind\r\n\r\ndata SameKind :: forall k. k > k > Type\r\ndata Foo :: forall a k (b :: k). SameKind a b > Type where\r\n MkFoo :: Foo sameKind\r\n}}}\r\n\r\n{{{\r\n$ /opt/ghc/8.6.3/bin/ghc Bug.hs dcorelint \r\n[1 of 1] Compiling Bug ( Bug.hs, Bug.o )\r\n*** Core Lint errors : in result of CorePrep ***\r\n<no location info>: warning:\r\n In the type ‘forall k (a :: k) k (b :: k) (sameKind :: SameKind\r\n a b).\r\n Foo sameKind’\r\n Kind application error in type ‘SameKind a_aWE b_aWG’\r\n Function kind = forall k. k > k > *\r\n Arg kinds = [(k_aWF, *), (a_aWE, k_aWD), (b_aWG, k_aWF)]\r\n Fun: k_aWF\r\n (a_aWE, k_aWD)\r\n*** Offending Program ***\r\n\r\n<elided>\r\n\r\nMkFoo\r\n :: forall k (a :: k) k (b :: k) (sameKind :: SameKind a b).\r\n Foo sameKind\r\n}}}\r\n\r\n(Confusingly, the type of `MkFoo` is rendered as `forall k (a :: k) k (b :: k) (sameKind :: SameKind a b). Foo sameKind` in that `dcorelint` error, but I think it really should be `forall k1 (a :: k1) k2 (b :: k2) (sameKind :: SameKind a b). Foo sameKind`.)\r\n\r\nOn GHC 8.4.4 and earlier, this simply produces an error message:\r\n\r\n{{{\r\n$ /opt/ghc/8.4.4/bin/ghc Bug.hs dcorelint\r\n[1 of 1] Compiling Bug ( Bug.hs, Bug.o )\r\n\r\nBug.hs:9:13: error:\r\n • These kind and type variables: a k (b :: k)\r\n are out of dependency order. Perhaps try this ordering:\r\n k (a :: k) (b :: k)\r\n • In the kind ‘forall a k (b :: k). SameKind a b > Type’\r\n \r\n9  data Foo :: forall a k (b :: k). SameKind a b > Type where\r\n  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\r\n}}}","type_of_failure":"OtherFailure","blocking":[]} >The following program produces a Core Lint error on GHC 8.6.3 and HEAD:
```hs
{# LANGUAGE GADTs #}
{# LANGUAGE ScopedTypeVariables #}
{# LANGUAGE TypeInType #}
module Bug where
import Data.Kind
data SameKind :: forall k. k > k > Type
data Foo :: forall a k (b :: k). SameKind a b > Type where
MkFoo :: Foo sameKind
```
```
$ /opt/ghc/8.6.3/bin/ghc Bug.hs dcorelint
[1 of 1] Compiling Bug ( Bug.hs, Bug.o )
*** Core Lint errors : in result of CorePrep ***
<no location info>: warning:
In the type ‘forall k (a :: k) k (b :: k) (sameKind :: SameKind
a b).
Foo sameKind’
Kind application error in type ‘SameKind a_aWE b_aWG’
Function kind = forall k. k > k > *
Arg kinds = [(k_aWF, *), (a_aWE, k_aWD), (b_aWG, k_aWF)]
Fun: k_aWF
(a_aWE, k_aWD)
*** Offending Program ***
<elided>
MkFoo
:: forall k (a :: k) k (b :: k) (sameKind :: SameKind a b).
Foo sameKind
```
(Confusingly, the type of `MkFoo` is rendered as `forall k (a :: k) k (b :: k) (sameKind :: SameKind a b). Foo sameKind` in that `dcorelint` error, but I think it really should be `forall k1 (a :: k1) k2 (b :: k2) (sameKind :: SameKind a b). Foo sameKind`.)
On GHC 8.4.4 and earlier, this simply produces an error message:
```
$ /opt/ghc/8.4.4/bin/ghc Bug.hs dcorelint
[1 of 1] Compiling Bug ( Bug.hs, Bug.o )
Bug.hs:9:13: error:
• These kind and type variables: a k (b :: k)
are out of dependency order. Perhaps try this ordering:
k (a :: k) (b :: k)
• In the kind ‘forall a k (b :: k). SameKind a b > Type’

9  data Foo :: forall a k (b :: k). SameKind a b > Type where
 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
```
<details><summary>Trac metadata</summary>
 Trac field  Value 
    
 Version  8.6.3 
 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.6 Core Lint regression (Kind application error)","status":"New","operating_system":"","component":"Compiler (Type checker)","related":[],"milestone":"8.10.1","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"8.6.3","keywords":["TypeInType"],"differentials":[],"test_case":"","architecture":"","cc":[""],"type":"Bug","description":"The following program produces a Core Lint error on GHC 8.6.3 and HEAD:\r\n\r\n{{{#!hs\r\n{# LANGUAGE GADTs #}\r\n{# LANGUAGE ScopedTypeVariables #}\r\n{# LANGUAGE TypeInType #}\r\nmodule Bug where\r\n\r\nimport Data.Kind\r\n\r\ndata SameKind :: forall k. k > k > Type\r\ndata Foo :: forall a k (b :: k). SameKind a b > Type where\r\n MkFoo :: Foo sameKind\r\n}}}\r\n\r\n{{{\r\n$ /opt/ghc/8.6.3/bin/ghc Bug.hs dcorelint \r\n[1 of 1] Compiling Bug ( Bug.hs, Bug.o )\r\n*** Core Lint errors : in result of CorePrep ***\r\n<no location info>: warning:\r\n In the type ‘forall k (a :: k) k (b :: k) (sameKind :: SameKind\r\n a b).\r\n Foo sameKind’\r\n Kind application error in type ‘SameKind a_aWE b_aWG’\r\n Function kind = forall k. k > k > *\r\n Arg kinds = [(k_aWF, *), (a_aWE, k_aWD), (b_aWG, k_aWF)]\r\n Fun: k_aWF\r\n (a_aWE, k_aWD)\r\n*** Offending Program ***\r\n\r\n<elided>\r\n\r\nMkFoo\r\n :: forall k (a :: k) k (b :: k) (sameKind :: SameKind a b).\r\n Foo sameKind\r\n}}}\r\n\r\n(Confusingly, the type of `MkFoo` is rendered as `forall k (a :: k) k (b :: k) (sameKind :: SameKind a b). Foo sameKind` in that `dcorelint` error, but I think it really should be `forall k1 (a :: k1) k2 (b :: k2) (sameKind :: SameKind a b). Foo sameKind`.)\r\n\r\nOn GHC 8.4.4 and earlier, this simply produces an error message:\r\n\r\n{{{\r\n$ /opt/ghc/8.4.4/bin/ghc Bug.hs dcorelint\r\n[1 of 1] Compiling Bug ( Bug.hs, Bug.o )\r\n\r\nBug.hs:9:13: error:\r\n • These kind and type variables: a k (b :: k)\r\n are out of dependency order. Perhaps try this ordering:\r\n k (a :: k) (b :: k)\r\n • In the kind ‘forall a k (b :: k). SameKind a b > Type’\r\n \r\n9  data Foo :: forall a k (b :: k). SameKind a b > Type where\r\n  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\r\n}}}","type_of_failure":"OtherFailure","blocking":[]} >8.10.1https://gitlab.haskell.org/ghc/ghc//issues/16255Visible kind application defeats type family with higherrank result kind20190707T18:00:47ZRyan ScottVisible kind application defeats type family with higherrank result kindAfter #15740, GHC now (correctly) rejects this program:
```hs
{# LANGUAGE DataKinds #}
{# LANGUAGE PolyKinds #}
{# LANGUAGE RankNTypes #}
{# LANGUAGE TypeApplications #}
{# LANGUAGE TypeFamilies #}
module Bug where
import Data.Kind
data SBool :: Bool > Type
type family F :: forall k. k > Type where
F = SBool
```
```
$ ~/Software/ghc5/inplace/bin/ghcstage2 interactive Bug.hs
GHCi, version 8.7.20190115: https://www.haskell.org/ghc/ :? for help
Loaded GHCi configuration from /home/rgscott/.ghci
[1 of 1] Compiling Bug ( Bug.hs, interpreted )
Bug.hs:12:7: error:
• Expected kind ‘forall k. k > *’,
but ‘SBool’ has kind ‘Bool > *’
• In the type ‘SBool’
In the type family declaration for ‘F’

12  F = SBool
 ^^^^^
```
However, there's a very simple way to circumvent this: add a visible kind application to `F`'s equation.
```hs
type family F :: forall k. k > Type where
F @Bool = SBool
```
If I understand things correctly, GHC shouldn't allow this.
<details><summary>Trac metadata</summary>
 Trac field  Value 
    
 Version  8.7 
 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":"Visible kind application defeats type family with higherrank result kind","status":"New","operating_system":"","component":"Compiler (Type checker)","related":[],"milestone":"","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"8.7","keywords":["TypeApplications,","TypeFamilies"],"differentials":[],"test_case":"","architecture":"","cc":[""],"type":"Bug","description":"After #15740, GHC now (correctly) rejects this program:\r\n\r\n{{{#!hs\r\n{# LANGUAGE DataKinds #}\r\n{# LANGUAGE PolyKinds #}\r\n{# LANGUAGE RankNTypes #}\r\n{# LANGUAGE TypeApplications #}\r\n{# LANGUAGE TypeFamilies #}\r\nmodule Bug where\r\n\r\nimport Data.Kind\r\n\r\ndata SBool :: Bool > Type\r\ntype family F :: forall k. k > Type where\r\n F = SBool\r\n}}}\r\n{{{\r\n$ ~/Software/ghc5/inplace/bin/ghcstage2 interactive Bug.hs\r\nGHCi, version 8.7.20190115: https://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:12:7: error:\r\n • Expected kind ‘forall k. k > *’,\r\n but ‘SBool’ has kind ‘Bool > *’\r\n • In the type ‘SBool’\r\n In the type family declaration for ‘F’\r\n \r\n12  F = SBool\r\n  ^^^^^\r\n}}}\r\n\r\nHowever, there's a very simple way to circumvent this: add a visible kind application to `F`'s equation.\r\n\r\n{{{#!hs\r\ntype family F :: forall k. k > Type where\r\n F @Bool = SBool\r\n}}}\r\n\r\nIf I understand things correctly, GHC shouldn't allow this.","type_of_failure":"OtherFailure","blocking":[]} >After #15740, GHC now (correctly) rejects this program:
```hs
{# LANGUAGE DataKinds #}
{# LANGUAGE PolyKinds #}
{# LANGUAGE RankNTypes #}
{# LANGUAGE TypeApplications #}
{# LANGUAGE TypeFamilies #}
module Bug where
import Data.Kind
data SBool :: Bool > Type
type family F :: forall k. k > Type where
F = SBool
```
```
$ ~/Software/ghc5/inplace/bin/ghcstage2 interactive Bug.hs
GHCi, version 8.7.20190115: https://www.haskell.org/ghc/ :? for help
Loaded GHCi configuration from /home/rgscott/.ghci
[1 of 1] Compiling Bug ( Bug.hs, interpreted )
Bug.hs:12:7: error:
• Expected kind ‘forall k. k > *’,
but ‘SBool’ has kind ‘Bool > *’
• In the type ‘SBool’
In the type family declaration for ‘F’

12  F = SBool
 ^^^^^
```
However, there's a very simple way to circumvent this: add a visible kind application to `F`'s equation.
```hs
type family F :: forall k. k > Type where
F @Bool = SBool
```
If I understand things correctly, GHC shouldn't allow this.
<details><summary>Trac metadata</summary>
 Trac field  Value 
    
 Version  8.7 
 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":"Visible kind application defeats type family with higherrank result kind","status":"New","operating_system":"","component":"Compiler (Type checker)","related":[],"milestone":"","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"8.7","keywords":["TypeApplications,","TypeFamilies"],"differentials":[],"test_case":"","architecture":"","cc":[""],"type":"Bug","description":"After #15740, GHC now (correctly) rejects this program:\r\n\r\n{{{#!hs\r\n{# LANGUAGE DataKinds #}\r\n{# LANGUAGE PolyKinds #}\r\n{# LANGUAGE RankNTypes #}\r\n{# LANGUAGE TypeApplications #}\r\n{# LANGUAGE TypeFamilies #}\r\nmodule Bug where\r\n\r\nimport Data.Kind\r\n\r\ndata SBool :: Bool > Type\r\ntype family F :: forall k. k > Type where\r\n F = SBool\r\n}}}\r\n{{{\r\n$ ~/Software/ghc5/inplace/bin/ghcstage2 interactive Bug.hs\r\nGHCi, version 8.7.20190115: https://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:12:7: error:\r\n • Expected kind ‘forall k. k > *’,\r\n but ‘SBool’ has kind ‘Bool > *’\r\n • In the type ‘SBool’\r\n In the type family declaration for ‘F’\r\n \r\n12  F = SBool\r\n  ^^^^^\r\n}}}\r\n\r\nHowever, there's a very simple way to circumvent this: add a visible kind application to `F`'s equation.\r\n\r\n{{{#!hs\r\ntype family F :: forall k. k > Type where\r\n F @Bool = SBool\r\n}}}\r\n\r\nIf I understand things correctly, GHC shouldn't allow this.","type_of_failure":"OtherFailure","blocking":[]} >8.8.1https://gitlab.haskell.org/ghc/ghc//issues/16334Named wildcards in kinds20200326T11:47:19ZVladislav ZavialovNamed wildcards in kindsThis works:
```
Prelude> :set XNamedWildCards XPartialTypeSignatures XPolyKinds
Prelude> k :: (Int :: _); k = 42
<interactive>:2:14: warning: [Wpartialtypesignatures]
• Found type wildcard ‘_’ standing for ‘*’
• In the type signature: k :: (Int :: _)
```
And this doesn't:
```
Prelude> k :: (Int :: _t); k = 42
<interactive>:3:7: error:
• Expected kind ‘_t’, but ‘Int’ has kind ‘*’
• In the type signature: k :: (Int :: _t)
```
The issue, I suspect, is in `partition_nwcs`, which ignores kind variables for some reason.This works:
```
Prelude> :set XNamedWildCards XPartialTypeSignatures XPolyKinds
Prelude> k :: (Int :: _); k = 42
<interactive>:2:14: warning: [Wpartialtypesignatures]
• Found type wildcard ‘_’ standing for ‘*’
• In the type signature: k :: (Int :: _)
```
And this doesn't:
```
Prelude> k :: (Int :: _t); k = 42
<interactive>:3:7: error:
• Expected kind ‘_t’, but ‘Int’ has kind ‘*’
• In the type signature: k :: (Int :: _t)
```
The issue, I suspect, is in `partition_nwcs`, which ignores kind variables for some reason.8.10.1https://gitlab.haskell.org/ghc/ghc//issues/16347GHC HEAD regression: piResultTys120190707T18:00:25ZRyan ScottGHC HEAD regression: piResultTys1The following program typechecks on GHC 8.0.2 through 8.6.3, but panics on HEAD:
```hs
{# LANGUAGE GADTs #}
{# LANGUAGE TypeInType #}
module Bug where
import Data.Kind
data T f :: f Type > Type where
MkT :: T f a
```
```
$ ~/Software/ghc4/inplace/bin/ghcstage2 Bug.hs
[1 of 1] Compiling Bug ( Bug.hs, Bug.o )
ghcstage2: panic! (the 'impossible' happened)
(GHC version 8.7.20190219 for x86_64unknownlinux):
piResultTys1
k_a10k[tau:1]
[*]
Call stack:
CallStack (from HasCallStack):
callStackDoc, called at compiler/utils/Outputable.hs:1159:37 in ghc:Outputable
pprPanic, called at compiler/types/Type.hs:1063:5 in ghc:Type
```The following program typechecks on GHC 8.0.2 through 8.6.3, but panics on HEAD:
```hs
{# LANGUAGE GADTs #}
{# LANGUAGE TypeInType #}
module Bug where
import Data.Kind
data T f :: f Type > Type where
MkT :: T f a
```
```
$ ~/Software/ghc4/inplace/bin/ghcstage2 Bug.hs
[1 of 1] Compiling Bug ( Bug.hs, Bug.o )
ghcstage2: panic! (the 'impossible' happened)
(GHC version 8.7.20190219 for x86_64unknownlinux):
piResultTys1
k_a10k[tau:1]
[*]
Call stack:
CallStack (from HasCallStack):
callStackDoc, called at compiler/utils/Outputable.hs:1159:37 in ghc:Outputable
pprPanic, called at compiler/types/Type.hs:1063:5 in ghc:Type
```8.10.1https://gitlab.haskell.org/ghc/ghc//issues/16356Unexpected type application in default declaration20200505T13:29:33ZVladislav ZavialovUnexpected type application in default declarationAll of these work:
```hs
{# LANGUAGE PolyKinds, TypeApplications, TypeFamilies, FlexibleInstances #}
import Data.Kind (Type)
data B (a :: k)
type family FClosed :: k > Type where
FClosed @k = B @k
type family FOpen :: k > Type
type instance FOpen @k = B @k
class FAssocClass k where
type FAssoc :: k > Type
instance FAssocClass k where
type FAssoc @k = B @k
```
This one doesn't:
```hs
class FAssocDefaultClass k where
type FAssocDefault :: k > Type
type FAssocDefault @k = B @k
```
```
A.hs:21:23: error:
Unexpected type application @k
In the default declaration for ‘FAssocDefault’

21  type FAssocDefault @k = B @k

```
So, what are the rules of the game? Let's fix this and document in the User's Guide.
<details><summary>Trac metadata</summary>
 Trac field  Value 
    
 Version  8.6.3 
 Type  Bug 
 TypeOfFailure  OtherFailure 
 Priority  normal 
 Resolution  Unresolved 
 Component  Compiler (Type checker) 
 Test case  
 Differential revisions  
 BlockedBy  
 Related  
 Blocking  
 CC  RyanGlScott, goldfire, simonpj 
 Operating system  
 Architecture  
</details>
<! {"blocked_by":[],"summary":"Unexpected type application in default declaration","status":"New","operating_system":"","component":"Compiler (Type checker)","related":[],"milestone":"","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"8.6.3","keywords":[],"differentials":[],"test_case":"","architecture":"","cc":["RyanGlScott","goldfire","simonpj"],"type":"Bug","description":"All of these work:\r\n\r\n{{{#!hs\r\n{# LANGUAGE PolyKinds, TypeApplications, TypeFamilies, FlexibleInstances #}\r\n\r\nimport Data.Kind (Type)\r\n\r\ndata B (a :: k)\r\n\r\ntype family FClosed :: k > Type where\r\n FClosed @k = B @k\r\n\r\ntype family FOpen :: k > Type\r\ntype instance FOpen @k = B @k\r\n\r\nclass FAssocClass k where\r\n type FAssoc :: k > Type\r\n\r\ninstance FAssocClass k where\r\n type FAssoc @k = B @k\r\n}}}\r\n\r\nThis one doesn't:\r\n\r\n{{{#!hs\r\nclass FAssocDefaultClass k where\r\n type FAssocDefault :: k > Type\r\n type FAssocDefault @k = B @k\r\n}}}\r\n\r\n{{{\r\nA.hs:21:23: error:\r\n Unexpected type application @k\r\n In the default declaration for ‘FAssocDefault’\r\n \r\n21  type FAssocDefault @k = B @k\r\n \r\n}}}\r\n\r\nSo, what are the rules of the game? Let's fix this and document in the User's Guide.","type_of_failure":"OtherFailure","blocking":[]} >All of these work:
```hs
{# LANGUAGE PolyKinds, TypeApplications, TypeFamilies, FlexibleInstances #}
import Data.Kind (Type)
data B (a :: k)
type family FClosed :: k > Type where
FClosed @k = B @k
type family FOpen :: k > Type
type instance FOpen @k = B @k
class FAssocClass k where
type FAssoc :: k > Type
instance FAssocClass k where
type FAssoc @k = B @k
```
This one doesn't:
```hs
class FAssocDefaultClass k where
type FAssocDefault :: k > Type
type FAssocDefault @k = B @k
```
```
A.hs:21:23: error:
Unexpected type application @k
In the default declaration for ‘FAssocDefault’

21  type FAssocDefault @k = B @k

```
So, what are the rules of the game? Let's fix this and document in the User's Guide.
<details><summary>Trac metadata</summary>
 Trac field  Value 
    
 Version  8.6.3 
 Type  Bug 
 TypeOfFailure  OtherFailure 
 Priority  normal 
 Resolution  Unresolved 
 Component  Compiler (Type checker) 
 Test case  
 Differential revisions  
 BlockedBy  
 Related  
 Blocking  
 CC  RyanGlScott, goldfire, simonpj 
 Operating system  
 Architecture  
</details>
<! {"blocked_by":[],"summary":"Unexpected type application in default declaration","status":"New","operating_system":"","component":"Compiler (Type checker)","related":[],"milestone":"","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"8.6.3","keywords":[],"differentials":[],"test_case":"","architecture":"","cc":["RyanGlScott","goldfire","simonpj"],"type":"Bug","description":"All of these work:\r\n\r\n{{{#!hs\r\n{# LANGUAGE PolyKinds, TypeApplications, TypeFamilies, FlexibleInstances #}\r\n\r\nimport Data.Kind (Type)\r\n\r\ndata B (a :: k)\r\n\r\ntype family FClosed :: k > Type where\r\n FClosed @k = B @k\r\n\r\ntype family FOpen :: k > Type\r\ntype instance FOpen @k = B @k\r\n\r\nclass FAssocClass k where\r\n type FAssoc :: k > Type\r\n\r\ninstance FAssocClass k where\r\n type FAssoc @k = B @k\r\n}}}\r\n\r\nThis one doesn't:\r\n\r\n{{{#!hs\r\nclass FAssocDefaultClass k where\r\n type FAssocDefault :: k > Type\r\n type FAssocDefault @k = B @k\r\n}}}\r\n\r\n{{{\r\nA.hs:21:23: error:\r\n Unexpected type application @k\r\n In the default declaration for ‘FAssocDefault’\r\n \r\n21  type FAssocDefault @k = B @k\r\n \r\n}}}\r\n\r\nSo, what are the rules of the game? Let's fix this and document in the User's Guide.","type_of_failure":"OtherFailure","blocking":[]} >https://gitlab.haskell.org/ghc/ghc//issues/16377`TypeError` in a pattern should flag inaccessible code20190707T18:00:19ZIavor S. Diatchki`TypeError` in a pattern should flag inaccessible codeWhen we pattern match, if the context ends up having a custom `TypeError`, we should probably report it, as we've essentially found some inaccessible code. At present this doesn't happen and the custom error is only triggered if the function is applied to an invalid argument. Here is an example to illustrate the issue:
```
{# LANGUAGE ConstraintKinds #}
{# LANGUAGE DataKinds #}
{# LANGUAGE KindSignatures #}
{# LANGUAGE TypeFamilies #}
{# LANGUAGE UndecidableInstances #}
{# LANGUAGE GADTs #}
module Test where
import GHC.TypeLits
import Data.Kind(Constraint)
type family F a :: Constraint
type instance F Int = ()
type instance F Char = TypeError ('Text "Nope")
type instance F Bool = (Int ~ Char)
data T where
A :: F Int => T
B :: F Char => T
C :: F Bool => T
exhaustive :: T > ()
exhaustive A = ()
exhaustive B = ()  this is not flagged as inaccessible, but it should
 exhaustive C = ()  this is flagged as inaccessible, as expected
```
If the match with constructor `C` is added to the program, GHC detects that this equation is inaccessible because `Int` will never match `Char`. I think that we'd like the same to happen in the second equation when we match on `B`, except we should report the custom type error, instead of GHC's message about unreachable code.
<details><summary>Trac metadata</summary>
 Trac field  Value 
    
 Version  8.6.3 
 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":"`TypeError` in a pattern should flag inaccessible code","status":"New","operating_system":"","component":"Compiler (Type checker)","related":[],"milestone":"","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"8.6.3","keywords":[],"differentials":[],"test_case":"","architecture":"","cc":[""],"type":"Bug","description":"When we pattern match, if the context ends up having a custom `TypeError`, we should probably report it, as we've essentially found some inaccessible code. At present this doesn't happen and the custom error is only triggered if the function is applied to an invalid argument. Here is an example to illustrate the issue:\r\n\r\n{{{\r\n{# LANGUAGE ConstraintKinds #}\r\n{# LANGUAGE DataKinds #}\r\n{# LANGUAGE KindSignatures #}\r\n{# LANGUAGE TypeFamilies #}\r\n{# LANGUAGE UndecidableInstances #}\r\n{# LANGUAGE GADTs #}\r\n\r\nmodule Test where\r\n\r\nimport GHC.TypeLits\r\nimport Data.Kind(Constraint)\r\n\r\ntype family F a :: Constraint\r\ntype instance F Int = ()\r\ntype instance F Char = TypeError ('Text \"Nope\")\r\ntype instance F Bool = (Int ~ Char)\r\n\r\ndata T where\r\n A :: F Int => T\r\n B :: F Char => T\r\n C :: F Bool => T\r\n\r\nexhaustive :: T > ()\r\nexhaustive A = ()\r\nexhaustive B = ()  this is not flagged as inaccessible, but it should\r\n exhaustive C = ()  this is flagged as inaccessible, as expected\r\n}}}\r\n\r\n\r\nIf the match with constructor `C` is added to the program, GHC detects that this equation is inaccessible because `Int` will never match `Char`. I think that we'd like the same to happen in the second equation when we match on `B`, except we should report the custom type error, instead of GHC's message about unreachable code.\r\n","type_of_failure":"OtherFailure","blocking":[]} >When we pattern match, if the context ends up having a custom `TypeError`, we should probably report it, as we've essentially found some inaccessible code. At present this doesn't happen and the custom error is only triggered if the function is applied to an invalid argument. Here is an example to illustrate the issue:
```
{# LANGUAGE ConstraintKinds #}
{# LANGUAGE DataKinds #}
{# LANGUAGE KindSignatures #}
{# LANGUAGE TypeFamilies #}
{# LANGUAGE UndecidableInstances #}
{# LANGUAGE GADTs #}
module Test where
import GHC.TypeLits
import Data.Kind(Constraint)
type family F a :: Constraint
type instance F Int = ()
type instance F Char = TypeError ('Text "Nope")
type instance F Bool = (Int ~ Char)
data T where
A :: F Int => T
B :: F Char => T
C :: F Bool => T
exhaustive :: T > ()
exhaustive A = ()
exhaustive B = ()  this is not flagged as inaccessible, but it should
 exhaustive C = ()  this is flagged as inaccessible, as expected
```
If the match with constructor `C` is added to the program, GHC detects that this equation is inaccessible because `Int` will never match `Char`. I think that we'd like the same to happen in the second equation when we match on `B`, except we should report the custom type error, instead of GHC's message about unreachable code.
<details><summary>Trac metadata</summary>
 Trac field  Value 
    
 Version  8.6.3 
 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":"`TypeError` in a pattern should flag inaccessible code","status":"New","operating_system":"","component":"Compiler (Type checker)","related":[],"milestone":"","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"8.6.3","keywords":[],"differentials":[],"test_case":"","architecture":"","cc":[""],"type":"Bug","description":"When we pattern match, if the context ends up having a custom `TypeError`, we should probably report it, as we've essentially found some inaccessible code. At present this doesn't happen and the custom error is only triggered if the function is applied to an invalid argument. Here is an example to illustrate the issue:\r\n\r\n{{{\r\n{# LANGUAGE ConstraintKinds #}\r\n{# LANGUAGE DataKinds #}\r\n{# LANGUAGE KindSignatures #}\r\n{# LANGUAGE TypeFamilies #}\r\n{# LANGUAGE UndecidableInstances #}\r\n{# LANGUAGE GADTs #}\r\n\r\nmodule Test where\r\n\r\nimport GHC.TypeLits\r\nimport Data.Kind(Constraint)\r\n\r\ntype family F a :: Constraint\r\ntype instance F Int = ()\r\ntype instance F Char = TypeError ('Text \"Nope\")\r\ntype instance F Bool = (Int ~ Char)\r\n\r\ndata T where\r\n A :: F Int => T\r\n B :: F Char => T\r\n C :: F Bool => T\r\n\r\nexhaustive :: T > ()\r\nexhaustive A = ()\r\nexhaustive B = ()  this is not flagged as inaccessible, but it should\r\n exhaustive C = ()  this is flagged as inaccessible, as expected\r\n}}}\r\n\r\n\r\nIf the match with constructor `C` is added to the program, GHC detects that this equation is inaccessible because `Int` will never match `Char`. I think that we'd like the same to happen in the second equation when we match on `B`, except we should report the custom type error, instead of GHC's message about unreachable code.\r\n","type_of_failure":"OtherFailure","blocking":[]} >https://gitlab.haskell.org/ghc/ghc//issues/16381Regression: Implicitly kind variables not in scope20190707T18:00:18ZBen GamariRegression: Implicitly kind variables not in scopeOur new `head.hackage` CI infrastructure has caught its first regression, it seems. A number of packages now fail to build due to outofscope kind variables. For instance, `singletonbool`:
```
[1 of 1] Compiling Data.Singletons.Bool ( src/Data/Singletons/Bool.hs, dist/build/Data/Singletons/Bool.o )
*** Parser [Data.Singletons.Bool]:
Parser [Data.Singletons.Bool]: alloc=4264704 time=6.901
*** Renamer/typechecker [Data.Singletons.Bool]:
Renamer/typechecker [Data.Singletons.Bool]: alloc=17554720 time=92.794
src/Data/Singletons/Bool.hs:119:29: error:
Not in scope: type variable ‘k’

119  sboolEqRefl :: forall (a :: k) (b :: k). SBoolI (a == b) => Maybe (a :~: b)
 ^
src/Data/Singletons/Bool.hs:119:38: error:
Not in scope: type variable ‘k’

119  sboolEqRefl :: forall (a :: k) (b :: k). SBoolI (a == b) => Maybe (a :~: b)
 ^
```
<details><summary>Trac metadata</summary>
 Trac field  Value 
    
 Version  8.9 
 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":"Regression: Implicitly kind variables not in scope","status":"New","operating_system":"","component":"Compiler (Type checker)","related":[],"milestone":"8.10.1","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"8.9","keywords":[],"differentials":[],"test_case":"","architecture":"","cc":[""],"type":"Bug","description":"Our new `head.hackage` CI infrastructure has caught its first regression, it seems. A number of packages now fail to build due to outofscope kind variables. For instance, `singletonbool`:\r\n{{{\r\n[1 of 1] Compiling Data.Singletons.Bool ( src/Data/Singletons/Bool.hs, dist/build/Data/Singletons/Bool.o )\r\n*** Parser [Data.Singletons.Bool]:\r\nParser [Data.Singletons.Bool]: alloc=4264704 time=6.901\r\n*** Renamer/typechecker [Data.Singletons.Bool]:\r\nRenamer/typechecker [Data.Singletons.Bool]: alloc=17554720 time=92.794\r\n\r\nsrc/Data/Singletons/Bool.hs:119:29: error:\r\n Not in scope: type variable ‘k’\r\n \r\n119  sboolEqRefl :: forall (a :: k) (b :: k). SBoolI (a == b) => Maybe (a :~: b)\r\n  ^\r\n\r\nsrc/Data/Singletons/Bool.hs:119:38: error:\r\n Not in scope: type variable ‘k’\r\n \r\n119  sboolEqRefl :: forall (a :: k) (b :: k). SBoolI (a == b) => Maybe (a :~: b)\r\n  ^\r\n}}}\r\n\r\n","type_of_failure":"OtherFailure","blocking":[]} >Our new `head.hackage` CI infrastructure has caught its first regression, it seems. A number of packages now fail to build due to outofscope kind variables. For instance, `singletonbool`:
```
[1 of 1] Compiling Data.Singletons.Bool ( src/Data/Singletons/Bool.hs, dist/build/Data/Singletons/Bool.o )
*** Parser [Data.Singletons.Bool]:
Parser [Data.Singletons.Bool]: alloc=4264704 time=6.901
*** Renamer/typechecker [Data.Singletons.Bool]:
Renamer/typechecker [Data.Singletons.Bool]: alloc=17554720 time=92.794
src/Data/Singletons/Bool.hs:119:29: error:
Not in scope: type variable ‘k’

119  sboolEqRefl :: forall (a :: k) (b :: k). SBoolI (a == b) => Maybe (a :~: b)
 ^
src/Data/Singletons/Bool.hs:119:38: error:
Not in scope: type variable ‘k’

119  sboolEqRefl :: forall (a :: k) (b :: k). SBoolI (a == b) => Maybe (a :~: b)
 ^
```
<details><summary>Trac metadata</summary>
 Trac field  Value 
    
 Version  8.9 
 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":"Regression: Implicitly kind variables not in scope","status":"New","operating_system":"","component":"Compiler (Type checker)","related":[],"milestone":"8.10.1","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"8.9","keywords":[],"differentials":[],"test_case":"","architecture":"","cc":[""],"type":"Bug","description":"Our new `head.hackage` CI infrastructure has caught its first regression, it seems. A number of packages now fail to build due to outofscope kind variables. For instance, `singletonbool`:\r\n{{{\r\n[1 of 1] Compiling Data.Singletons.Bool ( src/Data/Singletons/Bool.hs, dist/build/Data/Singletons/Bool.o )\r\n*** Parser [Data.Singletons.Bool]:\r\nParser [Data.Singletons.Bool]: alloc=4264704 time=6.901\r\n*** Renamer/typechecker [Data.Singletons.Bool]:\r\nRenamer/typechecker [Data.Singletons.Bool]: alloc=17554720 time=92.794\r\n\r\nsrc/Data/Singletons/Bool.hs:119:29: error:\r\n Not in scope: type variable ‘k’\r\n \r\n119  sboolEqRefl :: forall (a :: k) (b :: k). SBoolI (a == b) => Maybe (a :~: b)\r\n  ^\r\n\r\nsrc/Data/Singletons/Bool.hs:119:38: error:\r\n Not in scope: type variable ‘k’\r\n \r\n119  sboolEqRefl :: forall (a :: k) (b :: k). SBoolI (a == b) => Maybe (a :~: b)\r\n  ^\r\n}}}\r\n\r\n","type_of_failure":"OtherFailure","blocking":[]} >8.10.1https://gitlab.haskell.org/ghc/ghc//issues/16391"Quantified type's kind mentions quantified type variable" error with fancyk...20200727T08:24:27ZRyan Scott"Quantified type's kind mentions quantified type variable" error with fancykinded GADTGiven the following:
```hs
{# LANGUAGE DataKinds #}
{# LANGUAGE GADTs #}
{# LANGUAGE PolyKinds #}
{# LANGUAGE TypeFamilies #}
import Data.Kind
type Const (a :: Type) (b :: Type) = a
```
GHC happily accepts these definitions:
```hs
type family F :: Const Type a where
F = Int
type TS = (Int :: Const Type a)
```
However, the situation becomes murkier with data types. For some reason, GHC //rejects// this definition:
```hs
data T :: Const Type a where
MkT :: T
```
```
$ /opt/ghc/8.6.3/bin/ghc Bug.hs
[1 of 1] Compiling Main ( Bug.hs, Bug.o )
Bug.hs:14:3: error:
• Quantified type's kind mentions quantified type variable
(skolem escape)
type: forall a1. T
of kind: Const * a
• In the definition of data constructor ‘MkT’
In the data type declaration for ‘T’

14  MkT :: T
 ^^^^^^^^
```
I'm not quite sure how to interpret that error message, but it seems fishy to me. Even fishier is the fact that GHC //accepts// this slight modification of `T`:
```hs
data T2 :: Const Type a > Type where
MkT2 :: T2 b
```
Quite mysterious.

I briefly looked into where this error message is being thrown from. It turns out if you make this oneline change to GHC:
```diff
diff git a/compiler/typecheck/TcValidity.hs b/compiler/typecheck/TcValidity.hs
index 218f539c68..c7925767f9 100644
 a/compiler/typecheck/TcValidity.hs
+++ b/compiler/typecheck/TcValidity.hs
@@ 635,7 +635,7 @@ check_type ve@(ValidityEnv{ ve_tidy_env = env, ve_ctxt = ctxt
; check_type (ve{ve_tidy_env = env'}) tau
 Allow foralls to right of arrow
 ; checkTcM (not (any (`elemVarSet` tyCoVarsOfType phi_kind) tvs))
+ ; checkTcM (not (any (`elemVarSet` exactTyCoVarsOfType phi_kind) tvs))
(forAllEscapeErr env' ty tau_kind)
}
where
```
Then GHC will accept `T`. Whether this change is the right choice to make, I don't think I'm qualified to say.
<details><summary>Trac metadata</summary>
 Trac field  Value 
    
 Version  8.6.3 
 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":"\"Quantified type's kind mentions quantified type variable\" error with fancykinded GADT","status":"New","operating_system":"","component":"Compiler (Type checker)","related":[],"milestone":"","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"8.6.3","keywords":["TypeInType"],"differentials":[],"test_case":"","architecture":"","cc":[""],"type":"Bug","description":"Given the following:\r\n\r\n{{{#!hs\r\n{# LANGUAGE DataKinds #}\r\n{# LANGUAGE GADTs #}\r\n{# LANGUAGE PolyKinds #}\r\n{# LANGUAGE TypeFamilies #}\r\n\r\nimport Data.Kind\r\n\r\ntype Const (a :: Type) (b :: Type) = a\r\n}}}\r\n\r\nGHC happily accepts these definitions:\r\n\r\n{{{#!hs\r\ntype family F :: Const Type a where\r\n F = Int\r\ntype TS = (Int :: Const Type a)\r\n}}}\r\n\r\nHowever, the situation becomes murkier with data types. For some reason, GHC //rejects// this definition:\r\n\r\n{{{#!hs\r\ndata T :: Const Type a where\r\n MkT :: T\r\n}}}\r\n{{{\r\n$ /opt/ghc/8.6.3/bin/ghc Bug.hs\r\n[1 of 1] Compiling Main ( Bug.hs, Bug.o )\r\n\r\nBug.hs:14:3: error:\r\n • Quantified type's kind mentions quantified type variable\r\n (skolem escape)\r\n type: forall a1. T\r\n of kind: Const * a\r\n • In the definition of data constructor ‘MkT’\r\n In the data type declaration for ‘T’\r\n \r\n14  MkT :: T\r\n  ^^^^^^^^\r\n}}}\r\n\r\nI'm not quite sure how to interpret that error message, but it seems fishy to me. Even fishier is the fact that GHC //accepts// this slight modification of `T`:\r\n\r\n{{{#!hs\r\ndata T2 :: Const Type a > Type where\r\n MkT2 :: T2 b\r\n}}}\r\n\r\nQuite mysterious.\r\n\r\n\r\n\r\nI briefly looked into where this error message is being thrown from. It turns out if you make this oneline change to GHC:\r\n\r\n{{{#!diff\r\ndiff git a/compiler/typecheck/TcValidity.hs b/compiler/typecheck/TcValidity.hs\r\nindex 218f539c68..c7925767f9 100644\r\n a/compiler/typecheck/TcValidity.hs\r\n+++ b/compiler/typecheck/TcValidity.hs\r\n@@ 635,7 +635,7 @@ check_type ve@(ValidityEnv{ ve_tidy_env = env, ve_ctxt = ctxt\r\n ; check_type (ve{ve_tidy_env = env'}) tau\r\n  Allow foralls to right of arrow\r\n\r\n ; checkTcM (not (any (`elemVarSet` tyCoVarsOfType phi_kind) tvs))\r\n+ ; checkTcM (not (any (`elemVarSet` exactTyCoVarsOfType phi_kind) tvs))\r\n (forAllEscapeErr env' ty tau_kind)\r\n }\r\n where\r\n}}}\r\n\r\nThen GHC will accept `T`. Whether this change is the right choice to make, I don't think I'm qualified to say.","type_of_failure":"OtherFailure","blocking":[]} >Given the following:
```hs
{# LANGUAGE DataKinds #}
{# LANGUAGE GADTs #}
{# LANGUAGE PolyKinds #}
{# LANGUAGE TypeFamilies #}
import Data.Kind
type Const (a :: Type) (b :: Type) = a
```
GHC happily accepts these definitions:
```hs
type family F :: Const Type a where
F = Int
type TS = (Int :: Const Type a)
```
However, the situation becomes murkier with data types. For some reason, GHC //rejects// this definition:
```hs
data T :: Const Type a where
MkT :: T
```
```
$ /opt/ghc/8.6.3/bin/ghc Bug.hs
[1 of 1] Compiling Main ( Bug.hs, Bug.o )
Bug.hs:14:3: error:
• Quantified type's kind mentions quantified type variable
(skolem escape)
type: forall a1. T
of kind: Const * a
• In the definition of data constructor ‘MkT’
In the data type declaration for ‘T’

14  MkT :: T
 ^^^^^^^^
```
I'm not quite sure how to interpret that error message, but it seems fishy to me. Even fishier is the fact that GHC //accepts// this slight modification of `T`:
```hs
data T2 :: Const Type a > Type where
MkT2 :: T2 b
```
Quite mysterious.

I briefly looked into where this error message is being thrown from. It turns out if you make this oneline change to GHC:
```diff
diff git a/compiler/typecheck/TcValidity.hs b/compiler/typecheck/TcValidity.hs
index 218f539c68..c7925767f9 100644
 a/compiler/typecheck/TcValidity.hs
+++ b/compiler/typecheck/TcValidity.hs
@@ 635,7 +635,7 @@ check_type ve@(ValidityEnv{ ve_tidy_env = env, ve_ctxt = ctxt
; check_type (ve{ve_tidy_env = env'}) tau
 Allow foralls to right of arrow
 ; checkTcM (not (any (`elemVarSet` tyCoVarsOfType phi_kind) tvs))
+ ; checkTcM (not (any (`elemVarSet` exactTyCoVarsOfType phi_kind) tvs))
(forAllEscapeErr env' ty tau_kind)
}
where
```
Then GHC will accept `T`. Whether this change is the right choice to make, I don't think I'm qualified to say.
<details><summary>Trac metadata</summary>
 Trac field  Value 
    
 Version  8.6.3 
 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":"\"Quantified type's kind mentions quantified type variable\" error with fancykinded GADT","status":"New","operating_system":"","component":"Compiler (Type checker)","related":[],"milestone":"","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"8.6.3","keywords":["TypeInType"],"differentials":[],"test_case":"","architecture":"","cc":[""],"type":"Bug","description":"Given the following:\r\n\r\n{{{#!hs\r\n{# LANGUAGE DataKinds #}\r\n{# LANGUAGE GADTs #}\r\n{# LANGUAGE PolyKinds #}\r\n{# LANGUAGE TypeFamilies #}\r\n\r\nimport Data.Kind\r\n\r\ntype Const (a :: Type) (b :: Type) = a\r\n}}}\r\n\r\nGHC happily accepts these definitions:\r\n\r\n{{{#!hs\r\ntype family F :: Const Type a where\r\n F = Int\r\ntype TS = (Int :: Const Type a)\r\n}}}\r\n\r\nHowever, the situation becomes murkier with data types. For some reason, GHC //rejects// this definition:\r\n\r\n{{{#!hs\r\ndata T :: Const Type a where\r\n MkT :: T\r\n}}}\r\n{{{\r\n$ /opt/ghc/8.6.3/bin/ghc Bug.hs\r\n[1 of 1] Compiling Main ( Bug.hs, Bug.o )\r\n\r\nBug.hs:14:3: error:\r\n • Quantified type's kind mentions quantified type variable\r\n (skolem escape)\r\n type: forall a1. T\r\n of kind: Const * a\r\n • In the definition of data constructor ‘MkT’\r\n In the data type declaration for ‘T’\r\n \r\n14  MkT :: T\r\n  ^^^^^^^^\r\n}}}\r\n\r\nI'm not quite sure how to interpret that error message, but it seems fishy to me. Even fishier is the fact that GHC //accepts// this slight modification of `T`:\r\n\r\n{{{#!hs\r\ndata T2 :: Const Type a > Type where\r\n MkT2 :: T2 b\r\n}}}\r\n\r\nQuite mysterious.\r\n\r\n\r\n\r\nI briefly looked into where this error message is being thrown from. It turns out if you make this oneline change to GHC:\r\n\r\n{{{#!diff\r\ndiff git a/compiler/typecheck/TcValidity.hs b/compiler/typecheck/TcValidity.hs\r\nindex 218f539c68..c7925767f9 100644\r\n a/compiler/typecheck/TcValidity.hs\r\n+++ b/compiler/typecheck/TcValidity.hs\r\n@@ 635,7 +635,7 @@ check_type ve@(ValidityEnv{ ve_tidy_env = env, ve_ctxt = ctxt\r\n ; check_type (ve{ve_tidy_env = env'}) tau\r\n  Allow foralls to right of arrow\r\n\r\n ; checkTcM (not (any (`elemVarSet` tyCoVarsOfType phi_kind) tvs))\r\n+ ; checkTcM (not (any (`elemVarSet` exactTyCoVarsOfType phi_kind) tvs))\r\n (forAllEscapeErr env' ty tau_kind)\r\n }\r\n where\r\n}}}\r\n\r\nThen GHC will accept `T`. Whether this change is the right choice to make, I don't think I'm qualified to say.","type_of_failure":"OtherFailure","blocking":[]} >8.10.1https://gitlab.haskell.org/ghc/ghc//issues/16394GHC internal error while typechecking of instance definition20190707T18:00:15ZDay1721GHC internal error while typechecking of instance definitionHello. \\\\
This code won't typecheck because of GHC internal error.
```hs
{# LANGUAGE PolyKinds, TypeFamilies, DataKinds #}
class C a where
type T (n :: a)
 vDIFFv
instance C a => C b => C (a, b) where
type T '(n, m) = (T n, T m)
```
with error message:
```
Bug.hs:7:10: error:
• GHC internal error: ‘T’ is not in scope during type checking, but it passed the renamer
tcl_env of environment: [a1LS :> Type variable ‘a’ = a :: *,
a1LT :> Type variable ‘b’ = b :: *]
• In the type instance declaration for ‘T’
In the instance declaration for ‘C b => C (a, b)’

7  type T (n, m) = (T n, T m)
 ^
Failed, no modules loaded.
```
but this works fine:
```hs
{# LANGUAGE PolyKinds, TypeFamilies, DataKinds #}
class C a where
type T (n :: a)
 vDIFFv
instance (C a, C b) => C (a, b) where
type T '(n, m) = (T n, T m)
```
Not sure is a bug, but either way it would be better to make more understandable error message
<details><summary>Trac metadata</summary>
 Trac field  Value 
    
 Version  8.6.3 
 Type  Bug 
 TypeOfFailure  OtherFailure 
 Priority  low 
 Resolution  Unresolved 
 Component  Compiler (Type checker) 
 Test case  
 Differential revisions  
 BlockedBy  
 Related  
 Blocking  
 CC  
 Operating system  
 Architecture  
</details>
<! {"blocked_by":[],"summary":"GHC internal error while typechecking of instance definition","status":"New","operating_system":"","component":"Compiler (Type checker)","related":[],"milestone":"","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"8.6.3","keywords":[],"differentials":[],"test_case":"","architecture":"","cc":[""],"type":"Bug","description":"Hello. \\\\\r\nThis code won't typecheck because of GHC internal error.\r\n\r\n{{{#!hs\r\n{# LANGUAGE PolyKinds, TypeFamilies, DataKinds #}\r\n\r\nclass C a where\r\n type T (n :: a)\r\n\r\n vDIFFv\r\ninstance C a => C b => C (a, b) where\r\n type T '(n, m) = (T n, T m)\r\n}}}\r\n\r\nwith error message: \r\n{{{\r\nBug.hs:7:10: error:\r\n • GHC internal error: ‘T’ is not in scope during type checking, but it passed the renamer\r\n tcl_env of environment: [a1LS :> Type variable ‘a’ = a :: *,\r\n a1LT :> Type variable ‘b’ = b :: *]\r\n • In the type instance declaration for ‘T’\r\n In the instance declaration for ‘C b => C (a, b)’\r\n \r\n7  type T (n, m) = (T n, T m)\r\n  ^\r\nFailed, no modules loaded.\r\n\r\n}}}\r\n\r\nbut this works fine:\r\n{{{#!hs\r\n{# LANGUAGE PolyKinds, TypeFamilies, DataKinds #}\r\n\r\nclass C a where\r\n type T (n :: a)\r\n\r\n vDIFFv\r\ninstance (C a, C b) => C (a, b) where\r\n type T '(n, m) = (T n, T m)\r\n}}}\r\n\r\nNot sure is a bug, but either way it would be better to make more understandable error message","type_of_failure":"OtherFailure","blocking":[]} >Hello. \\\\
This code won't typecheck because of GHC internal error.
```hs
{# LANGUAGE PolyKinds, TypeFamilies, DataKinds #}
class C a where
type T (n :: a)
 vDIFFv
instance C a => C b => C (a, b) where
type T '(n, m) = (T n, T m)
```
with error message:
```
Bug.hs:7:10: error:
• GHC internal error: ‘T’ is not in scope during type checking, but it passed the renamer
tcl_env of environment: [a1LS :> Type variable ‘a’ = a :: *,
a1LT :> Type variable ‘b’ = b :: *]
• In the type instance declaration for ‘T’
In the instance declaration for ‘C b => C (a, b)’

7  type T (n, m) = (T n, T m)
 ^
Failed, no modules loaded.
```
but this works fine:
```hs
{# LANGUAGE PolyKinds, TypeFamilies, DataKinds #}
class C a where
type T (n :: a)
 vDIFFv
instance (C a, C b) => C (a, b) where
type T '(n, m) = (T n, T m)
```
Not sure is a bug, but either way it would be better to make more understandable error message
<details><summary>Trac metadata</summary>
 Trac field  Value 
    
 Version  8.6.3 
 Type  Bug 
 TypeOfFailure  OtherFailure 
 Priority  low 
 Resolution  Unresolved 
 Component  Compiler (Type checker) 
 Test case  
 Differential revisions  
 BlockedBy  
 Related  
 Blocking  
 CC  
 Operating system  
 Architecture  
</details>
<! {"blocked_by":[],"summary":"GHC internal error while typechecking of instance definition","status":"New","operating_system":"","component":"Compiler (Type checker)","related":[],"milestone":"","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"8.6.3","keywords":[],"differentials":[],"test_case":"","architecture":"","cc":[""],"type":"Bug","description":"Hello. \\\\\r\nThis code won't typecheck because of GHC internal error.\r\n\r\n{{{#!hs\r\n{# LANGUAGE PolyKinds, TypeFamilies, DataKinds #}\r\n\r\nclass C a where\r\n type T (n :: a)\r\n\r\n vDIFFv\r\ninstance C a => C b => C (a, b) where\r\n type T '(n, m) = (T n, T m)\r\n}}}\r\n\r\nwith error message: \r\n{{{\r\nBug.hs:7:10: error:\r\n • GHC internal error: ‘T’ is not in scope during type checking, but it passed the renamer\r\n tcl_env of environment: [a1LS :> Type variable ‘a’ = a :: *,\r\n a1LT :> Type variable ‘b’ = b :: *]\r\n • In the type instance declaration for ‘T’\r\n In the instance declaration for ‘C b => C (a, b)’\r\n \r\n7  type T (n, m) = (T n, T m)\r\n  ^\r\nFailed, no modules loaded.\r\n\r\n}}}\r\n\r\nbut this works fine:\r\n{{{#!hs\r\n{# LANGUAGE PolyKinds, TypeFamilies, DataKinds #}\r\n\r\nclass C a where\r\n type T (n :: a)\r\n\r\n vDIFFv\r\ninstance (C a, C b) => C (a, b) where\r\n type T '(n, m) = (T n, T m)\r\n}}}\r\n\r\nNot sure is a bug, but either way it would be better to make more understandable error message","type_of_failure":"OtherFailure","blocking":[]} >8.8.1https://gitlab.haskell.org/ghc/ghc//issues/16418GHC internal error with strange scoping (GHC HEAD regression)20191108T20:46:21ZRyan ScottGHC internal error with strange scoping (GHC HEAD regression)The following program simply errors with GHC 8.6.4:
```haskell
{# LANGUAGE PolyKinds #}
{# LANGUAGE ScopedTypeVariables #}
module Bug where
import Data.Kind
data SameKind :: forall k. k > k > Type
f :: forall a k (b :: k). SameKind a b > ()
f = g
where
g :: SameKind a b > ()
g _ = ()
```
```
$ /opt/ghc/8.6.4/bin/ghc Bug.hs
[1 of 1] Compiling Bug ( Bug.hs, Bug.o )
Bug.hs:9:6: error:
• These kind and type variables: a k (b :: k)
are out of dependency order. Perhaps try this ordering:
k (a :: k) (b :: k)
• In the type signature:
f :: forall a k (b :: k). SameKind a b > ()

9  f :: forall a k (b :: k). SameKind a b > ()
 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
```
On GHC HEAD, however, it throws a GHC internal error:
```
GHCi, version 8.9.20190309: https://www.haskell.org/ghc/ :? for help
Loaded GHCi configuration from /home/rgscott/.ghci
[1 of 1] Compiling Bug ( Bug.hs, interpreted )
Bug.hs:9:6: error:
• These kind and type variables: a k (b :: k)
are out of dependency order. Perhaps try this ordering:
k (a :: k) (b :: k)
• In the type signature:
f :: forall a k (b :: k). SameKind a b > ()

9  f :: forall a k (b :: k). SameKind a b > ()
 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Bug.hs:12:19: error:
• GHC internal error: ‘a’ is not in scope during type checking, but it passed the renamer
tcl_env of environment: []
• In the first argument of ‘SameKind’, namely ‘a’
In the type signature: g :: SameKind a b > ()
In an equation for ‘f’:
f = g
where
g :: SameKind a b > ()
g _ = ()

12  g :: SameKind a b > ()
 ^
```The following program simply errors with GHC 8.6.4:
```haskell
{# LANGUAGE PolyKinds #}
{# LANGUAGE ScopedTypeVariables #}
module Bug where
import Data.Kind
data SameKind :: forall k. k > k > Type
f :: forall a k (b :: k). SameKind a b > ()
f = g
where
g :: SameKind a b > ()
g _ = ()
```
```
$ /opt/ghc/8.6.4/bin/ghc Bug.hs
[1 of 1] Compiling Bug ( Bug.hs, Bug.o )
Bug.hs:9:6: error:
• These kind and type variables: a k (b :: k)
are out of dependency order. Perhaps try this ordering:
k (a :: k) (b :: k)
• In the type signature:
f :: forall a k (b :: k). SameKind a b > ()

9  f :: forall a k (b :: k). SameKind a b > ()
 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
```
On GHC HEAD, however, it throws a GHC internal error:
```
GHCi, version 8.9.20190309: https://www.haskell.org/ghc/ :? for help
Loaded GHCi configuration from /home/rgscott/.ghci
[1 of 1] Compiling Bug ( Bug.hs, interpreted )
Bug.hs:9:6: error:
• These kind and type variables: a k (b :: k)
are out of dependency order. Perhaps try this ordering:
k (a :: k) (b :: k)
• In the type signature:
f :: forall a k (b :: k). SameKind a b > ()

9  f :: forall a k (b :: k). SameKind a b > ()
 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Bug.hs:12:19: error:
• GHC internal error: ‘a’ is not in scope during type checking, but it passed the renamer
tcl_env of environment: []
• In the first argument of ‘SameKind’, namely ‘a’
In the type signature: g :: SameKind a b > ()
In an equation for ‘f’:
f = g
where
g :: SameKind a b > ()
g _ = ()

12  g :: SameKind a b > ()
 ^
```8.10.1https://gitlab.haskell.org/ghc/ghc//issues/16596Can't write instances of higherrank kinded variables20190519T18:33:57ZIcelandjackCan't write instances of higherrank kinded variables```haskell
{# language PolyKinds #}
{# language QuantifiedConstraints #}
{# language RankNTypes #}
import Data.Kind (Type)
class C (co :: forall k. k > Type)
instance C (co :: forall k. k > Type)
```
gives
```
$ ./ghcstage2 interactive ignoredotghci 1260_bug.hs
GHCi, version 8.7.20190211: https://www.haskell.org/ghc/ :? for help
[1 of 1] Compiling Main ( 1260_bug.hs, interpreted )
1260_bug.hs:8:13: error:
• Expected kind ‘forall k. k > *’, but ‘co’ has kind ‘k0’
• In the first argument of ‘C’, namely
‘(co :: forall k. k > Type)’
In the instance declaration for ‘C (co :: forall k. k > Type)’

8  instance C (co :: forall k. k > Type)
 ^^
Failed, no modules loaded.
Prelude>
```
Only the `instance` part causes trouble, should this work or not?```haskell
{# language PolyKinds #}
{# language QuantifiedConstraints #}
{# language RankNTypes #}
import Data.Kind (Type)
class C (co :: forall k. k > Type)
instance C (co :: forall k. k > Type)
```
gives
```
$ ./ghcstage2 interactive ignoredotghci 1260_bug.hs
GHCi, version 8.7.20190211: https://www.haskell.org/ghc/ :? for help
[1 of 1] Compiling Main ( 1260_bug.hs, interpreted )
1260_bug.hs:8:13: error:
• Expected kind ‘forall k. k > *’, but ‘co’ has kind ‘k0’
• In the first argument of ‘C’, namely
‘(co :: forall k. k > Type)’
In the instance declaration for ‘C (co :: forall k. k > Type)’

8  instance C (co :: forall k. k > Type)
 ^^
Failed, no modules loaded.
Prelude>
```
Only the `instance` part causes trouble, should this work or not?https://gitlab.haskell.org/ghc/ghc//issues/16609Only skip decls with CUSKs in kcLTyClDecl with PolyKinds on20201102T14:31:51ZNingning XieOnly skip decls with CUSKs in kcLTyClDecl with PolyKinds on# Summary
Data type kind checking skips decls with CUSKs in `kcLTyClDecl` (see note [Skip decls with CUSKs in kcLTyClDecl] in `TcTyClsDecls`).
However, when we have no PolyKinds, we shouldn't skip the check, because we have defaulting. Skipping won't bring us more polymorphism when we have defaulting.
WITHOUT any language extension, the following program is rejected nowadays.
```
data T1 a = MkT1 T2
data T2 = MkT2 (T1 Maybe)
```
What happened: `T1` and `T2` are in the same recursive group. Since `T2` has a CUSK (which is `Type`), `(T1 Maybe)` is skipped when kindchecking. So the kind of `a` remains unsolved and is thus defaulted to `Type`. Then `(T1 Maybe)` fails to typecheck because of a kind mismatch between `Type` and `Type > Type`.
The program typechecks in GHC 8.4 but fails to typecheck since GHC 8.6.
Propose: when we have NoPolyKinds, we don't skip the check; when we have PolyKinds, we skip the check.
# Steps to reproduce
Typecheck the example program.
# Expected behavior
The program should typecheck.
# Environment
* GHC version used: since 8.6# Summary
Data type kind checking skips decls with CUSKs in `kcLTyClDecl` (see note [Skip decls with CUSKs in kcLTyClDecl] in `TcTyClsDecls`).
However, when we have no PolyKinds, we shouldn't skip the check, because we have defaulting. Skipping won't bring us more polymorphism when we have defaulting.
WITHOUT any language extension, the following program is rejected nowadays.
```
data T1 a = MkT1 T2
data T2 = MkT2 (T1 Maybe)
```
What happened: `T1` and `T2` are in the same recursive group. Since `T2` has a CUSK (which is `Type`), `(T1 Maybe)` is skipped when kindchecking. So the kind of `a` remains unsolved and is thus defaulted to `Type`. Then `(T1 Maybe)` fails to typecheck because of a kind mismatch between `Type` and `Type > Type`.
The program typechecks in GHC 8.4 but fails to typecheck since GHC 8.6.
Propose: when we have NoPolyKinds, we don't skip the check; when we have PolyKinds, we skip the check.
# Steps to reproduce
Typecheck the example program.
# Expected behavior
The program should typecheck.
# Environment
* GHC version used: since 8.68.10.1https://gitlab.haskell.org/ghc/ghc//issues/16630Pass separation for TyClDecl LHS and RHS20190519T17:18:03ZVladislav ZavialovPass separation for TyClDecl LHS and RHSWhile implementing toplevel kind signatures, I faced an issue related to scoped kind variables. Here's an example:
```
type T :: forall k. k > Type
data T a = MkT (Proxy (a :: k))
```
When `XScopedTypeVariables` are on, we want `k` in `Proxy (a :: k)` to refer to `forall k.` in the TLKS.
Now, do we rename the signature or the data declaration first?
1. if we rename the declaration first, then `k` on its RHS won't be able to refer to `k` in the signature (`k` is not in scope)
2. if we rename the signature first, then it will not be able to refer to the declaration LHS (`T` is not in scope)
We have the exact same issue in terms, where it is solved by doing renaming in three steps:
1. rename the LHSs (`rnValBindsLHS`)
2. rename the signatures (`renameSigs`)
3. rename the RHSs (`rnValBindsRHS`)
In order to accommodate this design, `HsValBinds` and `HsBind` are parametrized by two separate passes:
```
data HsValBindsLR idL idR = ...
data HsBindLR idL idR = ...
```
On the other hand, renaming type/class declarations is done in one pass (`rnTyClDecls`), so `TyClDecl` is parametrized only by one pass:
```
data TyClDecl pass = ...
```
We should change this to:
```
data TyClDecl idL idR = ...
```
This is likely to be a fairly invasive change, so I'd rather do it independently from the TLKS implementation.While implementing toplevel kind signatures, I faced an issue related to scoped kind variables. Here's an example:
```
type T :: forall k. k > Type
data T a = MkT (Proxy (a :: k))
```
When `XScopedTypeVariables` are on, we want `k` in `Proxy (a :: k)` to refer to `forall k.` in the TLKS.
Now, do we rename the signature or the data declaration first?
1. if we rename the declaration first, then `k` on its RHS won't be able to refer to `k` in the signature (`k` is not in scope)
2. if we rename the signature first, then it will not be able to refer to the declaration LHS (`T` is not in scope)
We have the exact same issue in terms, where it is solved by doing renaming in three steps:
1. rename the LHSs (`rnValBindsLHS`)
2. rename the signatures (`renameSigs`)
3. rename the RHSs (`rnValBindsRHS`)
In order to accommodate this design, `HsValBinds` and `HsBind` are parametrized by two separate passes:
```
data HsValBindsLR idL idR = ...
data HsBindLR idL idR = ...
```
On the other hand, renaming type/class declarations is done in one pass (`rnTyClDecls`), so `TyClDecl` is parametrized only by one pass:
```
data TyClDecl pass = ...
```
We should change this to:
```
data TyClDecl idL idR = ...
```
This is likely to be a fairly invasive change, so I'd rather do it independently from the TLKS implementation.Vladislav ZavialovVladislav Zavialovhttps://gitlab.haskell.org/ghc/ghc//issues/16651incorrect typedefaults warning for lambda expressions20190519T16:57:39Zgeorge.colpittsincorrect typedefaults warning for lambda expressions# Summary
incorrect typedefaults warning for lambda expressions
# Steps to reproduce
load a file containing
```
{# OPTIONS_GHC Wtypedefaults #}
square = (\x > x * x)
square2 x = x * x
```
You will get the following:
>>>
alcm.hs:6:17: warning: [Wtypedefaults]
• Defaulting the following constraint to type ‘Integer’
Num a0 arising from a use of ‘*’
• In the expression: x * x
In the expression: (\ x > x * x)
In an equation for ‘square’: square = (\ x > x * x)

6  square = (\x > x * x)

>>>
# Expected behavior
There should be no warning for square just as there is no warning for square2
# Environment
* GHC version used: 8.6.5
Optional:
* Operating System: MacOS 10.14.4
* System Architecture:
# Summary
incorrect typedefaults warning for lambda expressions
# Steps to reproduce
load a file containing
```
{# OPTIONS_GHC Wtypedefaults #}
square = (\x > x * x)
square2 x = x * x
```
You will get the following:
>>>
alcm.hs:6:17: warning: [Wtypedefaults]
• Defaulting the following constraint to type ‘Integer’
Num a0 arising from a use of ‘*’
• In the expression: x * x
In the expression: (\ x > x * x)
In an equation for ‘square’: square = (\ x > x * x)

6  square = (\x > x * x)

>>>
# Expected behavior
There should be no warning for square just as there is no warning for square2
# Environment
* GHC version used: 8.6.5
Optional:
* Operating System: MacOS 10.14.4
* System Architecture:
https://gitlab.haskell.org/ghc/ghc//issues/16687No test/assertion for kcLHsQTyVars_Cusk solveEqualities20190806T14:47:09ZVladislav ZavialovNo test/assertion for kcLHsQTyVars_Cusk solveEqualitiesIn `kcLHsQTyVars_Cusk`, there are these lines:
```
do { (scoped_kvs, (tc_tvs, res_kind))
< pushTcLevelM_ $
solveEqualities $
bindImplicitTKBndrs_Q_Skol kv_ns $
bindExplicitTKBndrs_Q_Skol ctxt_kind hs_tvs $
thing_inside
```
I'm using them as a model for the TLKS implementation, and right now I'm trying to understand what `solveEqualities` is doing here. So here's what I did:
1. I commented out the `solveEqualities $` line and ran the test suite. It did not cause any failures.
2. I did some git history digging and found out that this call was added in 55577a91 to fix #11648. From reading the discussion I figured that I need a `DDEBUG` compiler to see the error, as it's an assertion failure.
3. I've built GHC with the `devel2` flavour (it turns on `DDEBUG`) and ran the tests mentioned in #11648, there were no errors still. (Just to make sure that I have assertions enabled, I added `MASSERT(False)` and it failed)
Now I'm puzzled. What purpose does `solveEqualities` serve here? We need a test case that would fail without it!In `kcLHsQTyVars_Cusk`, there are these lines:
```
do { (scoped_kvs, (tc_tvs, res_kind))
< pushTcLevelM_ $
solveEqualities $
bindImplicitTKBndrs_Q_Skol kv_ns $
bindExplicitTKBndrs_Q_Skol ctxt_kind hs_tvs $
thing_inside
```
I'm using them as a model for the TLKS implementation, and right now I'm trying to understand what `solveEqualities` is doing here. So here's what I did:
1. I commented out the `solveEqualities $` line and ran the test suite. It did not cause any failures.
2. I did some git history digging and found out that this call was added in 55577a91 to fix #11648. From reading the discussion I figured that I need a `DDEBUG` compiler to see the error, as it's an assertion failure.
3. I've built GHC with the `devel2` flavour (it turns on `DDEBUG`) and ran the tests mentioned in #11648, there were no errors still. (Just to make sure that I have assertions enabled, I added `MASSERT(False)` and it failed)
Now I'm puzzled. What purpose does `solveEqualities` serve here? We need a test case that would fail without it!⊥Richard Eisenbergrae@richarde.devRichard Eisenbergrae@richarde.devhttps://gitlab.haskell.org/ghc/ghc//issues/16767Quantification by level numbers would fail20191014T12:51:46ZRichard Eisenbergrae@richarde.devQuantification by level numbers would failWitness:
```
rae:11:43:10 ~/ghc/ghchead/testsuite/tests> ~/ghc/ghchead/inplace/bin/ghcstage2 interactive fprintexplicitforalls fprintexplicitkinds XTypeApplications XDataKinds
GHCi, version 8.9.0.20190531: https://www.haskell.org/ghc/ :? for help
Loaded GHCi configuration from /Users/rae/.ghc/ghci.conf
Prelude> import Data.Proxy
Prelude Data.Proxy> :kind! 'Proxy @_
WARNING: file compiler/typecheck/TcMType.hs, line 1470
Quantification by level numbers would fail
Outer level = 0
dep_tkvs = {k_a1Ef[tau:0], __a1Eh[tau:0]}
co_vars =
co_tvs = {}
dep_kvs = [k_a1Ef[tau:0], __a1Eh[tau:0]]
dep_kvs2 = []
nondep_tvs = []
nondep_tvs2 = []
Call stack:
CallStack (from HasCallStack):
callStackDoc, called at compiler/utils/Outputable.hs:1231:29 in ghc:Outputable
warnPprTrace, called at compiler/typecheck/TcMType.hs:1470:11 in ghc:TcMType
'Proxy @_ :: forall {k} {_ :: k}. Proxy @{k} _
= 'Proxy @{k} @_
Prelude Data.Proxy>
```
The problem is that `tcRnType` (the worker for GHCi's `:kind`) does not bump the level before doing its work. Will fix in ongoing work (!951).Witness:
```
rae:11:43:10 ~/ghc/ghchead/testsuite/tests> ~/ghc/ghchead/inplace/bin/ghcstage2 interactive fprintexplicitforalls fprintexplicitkinds XTypeApplications XDataKinds
GHCi, version 8.9.0.20190531: https://www.haskell.org/ghc/ :? for help
Loaded GHCi configuration from /Users/rae/.ghc/ghci.conf
Prelude> import Data.Proxy
Prelude Data.Proxy> :kind! 'Proxy @_
WARNING: file compiler/typecheck/TcMType.hs, line 1470
Quantification by level numbers would fail
Outer level = 0
dep_tkvs = {k_a1Ef[tau:0], __a1Eh[tau:0]}
co_vars =
co_tvs = {}
dep_kvs = [k_a1Ef[tau:0], __a1Eh[tau:0]]
dep_kvs2 = []
nondep_tvs = []
nondep_tvs2 = []
Call stack:
CallStack (from HasCallStack):
callStackDoc, called at compiler/utils/Outputable.hs:1231:29 in ghc:Outputable
warnPprTrace, called at compiler/typecheck/TcMType.hs:1470:11 in ghc:TcMType
'Proxy @_ :: forall {k} {_ :: k}. Proxy @{k} _
= 'Proxy @{k} @_
Prelude Data.Proxy>
```
The problem is that `tcRnType` (the worker for GHCi's `:kind`) does not bump the level before doing its work. Will fix in ongoing work (!951).Richard Eisenbergrae@richarde.devRichard Eisenbergrae@richarde.devhttps://gitlab.haskell.org/ghc/ghc//issues/16775Don't zap naughty quantification candidates: error instead20201215T12:32:56ZRichard Eisenbergrae@richarde.devDon't zap naughty quantification candidates: error insteadNote [Naughty quantification candidates] in TcMType describes a scenario like `forall arg. ... (alpha[tau] :: arg) ...`, where `alpha`, a unification variable, has a bound skolem in its type. If `alpha` is otherwise unconstrained, we simply don't know what to do with it. So, as the Note explains, we zap it to `Any`.
However, we recently decided not to `Any`ify in type declarations. And I think we are wrong to `Any`ify here, too. We should just error. If not, we risk having `Any` leak in error messages, and it seems a nice goal not to ever let users see `Any` (short of TH or reflection or other dastardly deeds).
The example is `partialsigs/should_fail/T14040a`. You can find the program in question at the top of #14040. https://gitlab.haskell.org/ghc/ghc/issues/14040#note_168778 reports HEAD's error message. (The program and error message are all very intricate. Don't get distracted by reading them.) However, some of the wildcards in that error message have locallybound types, meaning there is no hope for them, regardless of other errors about. In other work (some refactoring to be posted soon), I spotted that `tcHsPartialSigType` was missing out on the action in Note [Naughty quantification candidates] and so fixed the problem. This means that the error for that program now mentions `Any`.
Here is a simpler test case:
```
foo :: forall (f :: forall a (b :: a > Type). b _). f _
foo = foo
```
Note that the type of the first `_` must be `a`, which is locally quantified. In HEAD, this program trips an assertion failure around the substitution invariant (and I have not investigated further). In my branch that duly checks partial signatures for naught quantification candidates, we get
```
• Expected kind ‘k > *’, but ‘f’ has kind ‘k > Any @*’
• In the type ‘f _’
In the type signature:
foo :: forall (f :: forall a (b :: a > Type). b _). f _
```
This is correct enough, but there's `Any` in the error message. I think it would be much better just to reject the type signature a priori.
If I make the program correct (by wrapping the `f _` in a call to `Proxy`, I get
```
Scratch.hs:44:50: warning: [Wpartialtypesignatures]
• Found type wildcard ‘_’ standing for ‘Any @a :: a’
Where: ‘a’ is a rigid type variable bound by
‘forall a (b :: a > Type). b _’
at Scratch.hs:44:28
• In the first argument of ‘b’, namely ‘_’
In the kind ‘forall a (b :: a > Type). b _’
In the type signature:
foo :: forall (f :: forall a (b :: a > Type). b _). Proxy (f _)

44  foo :: forall (f :: forall a (b :: a > Type). b _). Proxy (f _)
 ^
Scratch.hs:44:63: warning: [Wpartialtypesignatures]
• Found type wildcard ‘_’ standing for ‘_ :: k’
Where: ‘k’, ‘_’ are rigid type variables bound by
the inferred type of
foo :: Proxy
@{Any @Type} (f @Type @((>) @{'LiftedRep} @{'LiftedRep} k) _)
at Scratch.hs:45:19
• In the first argument of ‘f’, namely ‘_’
In the first argument of ‘Proxy’, namely ‘(f _)’
In the type ‘Proxy (f _)’

44  foo :: forall (f :: forall a (b :: a > Type). b _). Proxy (f _)
 ^
```
More `Any`s. No! Reject!
What think you (for any value of you)?Note [Naughty quantification candidates] in TcMType describes a scenario like `forall arg. ... (alpha[tau] :: arg) ...`, where `alpha`, a unification variable, has a bound skolem in its type. If `alpha` is otherwise unconstrained, we simply don't know what to do with it. So, as the Note explains, we zap it to `Any`.
However, we recently decided not to `Any`ify in type declarations. And I think we are wrong to `Any`ify here, too. We should just error. If not, we risk having `Any` leak in error messages, and it seems a nice goal not to ever let users see `Any` (short of TH or reflection or other dastardly deeds).
The example is `partialsigs/should_fail/T14040a`. You can find the program in question at the top of #14040. https://gitlab.haskell.org/ghc/ghc/issues/14040#note_168778 reports HEAD's error message. (The program and error message are all very intricate. Don't get distracted by reading them.) However, some of the wildcards in that error message have locallybound types, meaning there is no hope for them, regardless of other errors about. In other work (some refactoring to be posted soon), I spotted that `tcHsPartialSigType` was missing out on the action in Note [Naughty quantification candidates] and so fixed the problem. This means that the error for that program now mentions `Any`.
Here is a simpler test case:
```
foo :: forall (f :: forall a (b :: a > Type). b _). f _
foo = foo
```
Note that the type of the first `_` must be `a`, which is locally quantified. In HEAD, this program trips an assertion failure around the substitution invariant (and I have not investigated further). In my branch that duly checks partial signatures for naught quantification candidates, we get
```
• Expected kind ‘k > *’, but ‘f’ has kind ‘k > Any @*’
• In the type ‘f _’
In the type signature:
foo :: forall (f :: forall a (b :: a > Type). b _). f _
```
This is correct enough, but there's `Any` in the error message. I think it would be much better just to reject the type signature a priori.
If I make the program correct (by wrapping the `f _` in a call to `Proxy`, I get
```
Scratch.hs:44:50: warning: [Wpartialtypesignatures]
• Found type wildcard ‘_’ standing for ‘Any @a :: a’
Where: ‘a’ is a rigid type variable bound by
‘forall a (b :: a > Type). b _’
at Scratch.hs:44:28
• In the first argument of ‘b’, namely ‘_’
In the kind ‘forall a (b :: a > Type). b _’
In the type signature:
foo :: forall (f :: forall a (b :: a > Type). b _). Proxy (f _)

44  foo :: forall (f :: forall a (b :: a > Type). b _). Proxy (f _)
 ^
Scratch.hs:44:63: warning: [Wpartialtypesignatures]
• Found type wildcard ‘_’ standing for ‘_ :: k’
Where: ‘k’, ‘_’ are rigid type variables bound by
the inferred type of
foo :: Proxy
@{Any @Type} (f @Type @((>) @{'LiftedRep} @{'LiftedRep} k) _)
at Scratch.hs:45:19
• In the first argument of ‘f’, namely ‘_’
In the first argument of ‘Proxy’, namely ‘(f _)’
In the type ‘Proxy (f _)’

44  foo :: forall (f :: forall a (b :: a > Type). b _). Proxy (f _)
 ^
```
More `Any`s. No! Reject!
What think you (for any value of you)?8.8.2https://gitlab.haskell.org/ghc/ghc//issues/16877GHCi panics using fdefertypeerrors when pattern matching on types with mul...20200218T12:30:12ZBerengalGHCi panics using fdefertypeerrors when pattern matching on types with multiple constructors using outofscope variables# Summary
With fdefertypeerrors enabled GHCi will panic on certain errors involving pattern matching on types with multiple constructors. At least as far as I can tell.
# Steps to reproduce
The following is the smallest module I could find that causes the panic:
```
foo = x
where (x:xs) = bar
```
GHCi command and output:
```
▶ ghci ignoredotghci fdefertypeerrors Foo.hs
GHCi, version 8.6.5: http://www.haskell.org/ghc/ :? for help
[1 of 1] Compiling Main ( Foo.hs, interpreted )
Foo.hs:2:18: warning: [Wdeferredoutofscopevariables]
Variable not in scope: bar :: [a1]

2  where (x:xs) = bar
 ^^^
ghc: panic! (the 'impossible' happened)
(GHC version 8.6.5 for x86_64unknownlinux):
getIdFromTrivialExpr
\ (@ a_a1x4) > case ds_s1yU @ a_a1x4 of wild_Xb { }
Call stack:
CallStack (from HasCallStack):
callStackDoc, called at compiler/utils/Outputable.hs:1160:37 in ghc:Outputable
pprPanic, called at compiler/coreSyn/CoreUtils.hs:977:18 in ghc:CoreUtils
Please report this as a GHC bug: http://www.haskell.org/ghc/reportabug
>
```
The equivalent using `let` also panics. The pattern match in the where is neccessary, as is using a matched variable in the main expression (either one will do). Matching on a tuple does not cause a panic, nor does matching on `data Foo a = Foo a a`, but matching on `data Foo a = Foo a a  Bar a a` panics regardless of which constructor is chosen.
# Expected behavior
GHCi doesn't panic, but either loads the module correctly or explains why it can't do so.
# Environment
* GHC version used: 8.6.5
Optional:
* Operating System: Archlinux
* System Architecture: x86_64# Summary
With fdefertypeerrors enabled GHCi will panic on certain errors involving pattern matching on types with multiple constructors. At least as far as I can tell.
# Steps to reproduce
The following is the smallest module I could find that causes the panic:
```
foo = x
where (x:xs) = bar
```
GHCi command and output:
```
▶ ghci ignoredotghci fdefertypeerrors Foo.hs
GHCi, version 8.6.5: http://www.haskell.org/ghc/ :? for help
[1 of 1] Compiling Main ( Foo.hs, interpreted )
Foo.hs:2:18: warning: [Wdeferredoutofscopevariables]
Variable not in scope: bar :: [a1]

2  where (x:xs) = bar
 ^^^
ghc: panic! (the 'impossible' happened)
(GHC version 8.6.5 for x86_64unknownlinux):
getIdFromTrivialExpr
\ (@ a_a1x4) > case ds_s1yU @ a_a1x4 of wild_Xb { }
Call stack:
CallStack (from HasCallStack):
callStackDoc, called at compiler/utils/Outputable.hs:1160:37 in ghc:Outputable
pprPanic, called at compiler/coreSyn/CoreUtils.hs:977:18 in ghc:CoreUtils
Please report this as a GHC bug: http://www.haskell.org/ghc/reportabug
>
```
The equivalent using `let` also panics. The pattern match in the where is neccessary, as is using a matched variable in the main expression (either one will do). Matching on a tuple does not cause a panic, nor does matching on `data Foo a = Foo a a`, but matching on `data Foo a = Foo a a  Bar a a` panics regardless of which constructor is chosen.
# Expected behavior
GHCi doesn't panic, but either loads the module correctly or explains why it can't do so.
# Environment
* GHC version used: 8.6.5
Optional:
* Operating System: Archlinux
* System Architecture: x86_648.8.2https://gitlab.haskell.org/ghc/ghc//issues/16946"No skolem info"20190726T13:49:54ZGergő Érdi"No skolem info"On GHC 8.6.3, I am trying to typecheck the following code:
```
{# LANGUAGE RankNTypes, TypeFamilies, PolyKinds, FunctionalDependencies #}
import Data.Kind
class CatMonad (c :: k > k > Type) (m :: forall (x :: k) (y :: k). c x y > Type > Type)  c > m where
type Id c :: c x x
xpure :: a > m (Id c) a
boom :: forall (c :: k > k > Type) (m :: forall (x :: k) (y :: k). c x y > Type > Type) a. CatMonad c m => a > m (Id c) a
boom = xpure
```
GHC panics with the following error message:
> ```
> error:ghc: panic! (the 'impossible' happened)
> (GHC version 8.6.3 for x86_64unknownlinux):
> No skolem info:
> [k_a2vT[sk:0]]
> Call stack:
> CallStack (from HasCallStack):
> callStackDoc, called at compiler/utils/Outputable.hs:1160:37 in ghc:Outputable
> pprPanic, called at compiler/typecheck/TcErrors.hs:2891:5 in ghc:TcErrors
>
> Please report this as a GHC bug: http://www.haskell.org/ghc/reportabug
>
> ```
>
If you're thinking, "oh my god, why would you write code like that?!?!?!", the background is [this Stack Overflow answer](https://stackoverflow.com/a/57046042/477476), and specifically, pining for overriding `return` and `(>>=)` using `RebindableSyntax` to be able to use `do`notation with (category)indexed monads.On GHC 8.6.3, I am trying to typecheck the following code:
```
{# LANGUAGE RankNTypes, TypeFamilies, PolyKinds, FunctionalDependencies #}
import Data.Kind
class CatMonad (c :: k > k > Type) (m :: forall (x :: k) (y :: k). c x y > Type > Type)  c > m where
type Id c :: c x x
xpure :: a > m (Id c) a
boom :: forall (c :: k > k > Type) (m :: forall (x :: k) (y :: k). c x y > Type > Type) a. CatMonad c m => a > m (Id c) a
boom = xpure
```
GHC panics with the following error message:
> ```
> error:ghc: panic! (the 'impossible' happened)
> (GHC version 8.6.3 for x86_64unknownlinux):
> No skolem info:
> [k_a2vT[sk:0]]
> Call stack:
> CallStack (from HasCallStack):
> callStackDoc, called at compiler/utils/Outputable.hs:1160:37 in ghc:Outputable
> pprPanic, called at compiler/typecheck/TcErrors.hs:2891:5 in ghc:TcErrors
>
> Please report this as a GHC bug: http://www.haskell.org/ghc/reportabug
>
> ```
>
If you're thinking, "oh my god, why would you write code like that?!?!?!", the background is [this Stack Overflow answer](https://stackoverflow.com/a/57046042/477476), and specifically, pining for overriding `return` and `(>>=)` using `RebindableSyntax` to be able to use `do`notation with (category)indexed monads.https://gitlab.haskell.org/ghc/ghc//issues/17024Poor interaction between functional dependencies and partial type signatures20200312T13:58:57ZDavid FeuerPoor interaction between functional dependencies and partial type signatures## Summary
A fundep is surprisingly unable to fill in a partial type signature
## Steps to reproduce
```haskell
{# language TypeFamilies, FunctionalDependencies, GADTs, DataKinds, TypeOperators, ScopedTypeVariables, FlexibleInstances , UndecidableInstances, PartialTypeSignatures #}
infixr 6 :::
data HList xs where
HNil :: HList '[]
(:::) :: a > HList as > HList (a ': as)
class AppHList ts o f  ts f > o, ts o > f where
appHList :: f > HList ts > o
instance AppHList '[] o o where
appHList x HNil = x
instance AppHList ts o f => AppHList (t : ts) o (t > f) where
appHList f (x ::: xs) = appHList (f x) xs
foo :: (a > b > c) > HList '[a, b] > _
foo = appHList
```
This fails with
```
AbstractList.hs:35:7: error:
• Couldn't match type ‘c’ with ‘w0’
arising from a functional dependency between:
constraint ‘AppHList '[] w0 c’ arising from a use of ‘appHList’
instance ‘AppHList '[] o o’ at AbstractList.hs:29:1025
‘c’ is a rigid type variable bound by
the inferred type of foo :: (a > b > c) > HList '[a, b] > w0
at AbstractList.hs:35:114
• In the expression: appHList
In an equation for ‘foo’: foo = appHList
• Relevant bindings include
foo :: (a > b > c) > HList '[a, b] > w0
(bound at AbstractList.hs:35:1)
```
## Expected behavior
I'd expect GHC to fill in `_` with `c`. Indeed, if I leave out the type signature and write
```haskell
foo (f :: a > b > c) (args :: HList '[a, b]) = appHList f args
```
then GHC correctly infers `foo :: (a > b > c) > HList '[a, b] > c`.
## Environment
* GHC version used: 8.6.3
Optional:
* Operating System:
* System Architecture:## Summary
A fundep is surprisingly unable to fill in a partial type signature
## Steps to reproduce
```haskell
{# language TypeFamilies, FunctionalDependencies, GADTs, DataKinds, TypeOperators, ScopedTypeVariables, FlexibleInstances , UndecidableInstances, PartialTypeSignatures #}
infixr 6 :::
data HList xs where
HNil :: HList '[]
(:::) :: a > HList as > HList (a ': as)
class AppHList ts o f  ts f > o, ts o > f where
appHList :: f > HList ts > o
instance AppHList '[] o o where
appHList x HNil = x
instance AppHList ts o f => AppHList (t : ts) o (t > f) where
appHList f (x ::: xs) = appHList (f x) xs
foo :: (a > b > c) > HList '[a, b] > _
foo = appHList
```
This fails with
```
AbstractList.hs:35:7: error:
• Couldn't match type ‘c’ with ‘w0’
arising from a functional dependency between:
constraint ‘AppHList '[] w0 c’ arising from a use of ‘appHList’
instance ‘AppHList '[] o o’ at AbstractList.hs:29:1025
‘c’ is a rigid type variable bound by
the inferred type of foo :: (a > b > c) > HList '[a, b] > w0
at AbstractList.hs:35:114
• In the expression: appHList
In an equation for ‘foo’: foo = appHList
• Relevant bindings include
foo :: (a > b > c) > HList '[a, b] > w0
(bound at AbstractList.hs:35:1)
```
## Expected behavior
I'd expect GHC to fill in `_` with `c`. Indeed, if I leave out the type signature and write
```haskell
foo (f :: a > b > c) (args :: HList '[a, b]) = appHList f args
```
then GHC correctly infers `foo :: (a > b > c) > HList '[a, b] > c`.
## Environment
* GHC version used: 8.6.3
Optional:
* Operating System:
* System Architecture:https://gitlab.haskell.org/ghc/ghc//issues/17060Compiler ignores Typeable constraint20191008T09:44:26ZRobert PeszekCompiler ignores Typeable constraint## Summary
Compiler allows passing types with no `Typeable` instance to functions declared with `Typeable` constraint.
## Steps to reproduce
The following compiles (no pragmas needed)
```haskell
import Data.Typeable
brokenGhc :: Typeable a => a > a
brokenGhc = id
tst = brokenGhc (Foo "bar")
brokenGhc2 :: (Typeable a) => a > String
brokenGhc2 = show . typeOf
tst2 = brokenGhc2 (Foo "Bar")
 ghci> tst2
 "Foo"
data Foo = Foo String
```
Possibly related to #10770?
## Expected behavior
`tst` and `tst2` should not compile. Note `Foo` has no instances!
## Environment
* GHC version used:
Tested with ghc8.6.5/lts14.0, ghc8.2.2/lts12.22
Optional:
* Operating System:
Ubuntu 18.04 and Ubuntu 18.10
* System Architecture:
## Suggested Labels:
~Typeable
~bug
~"program incorrectly accepted"## Summary
Compiler allows passing types with no `Typeable` instance to functions declared with `Typeable` constraint.
## Steps to reproduce
The following compiles (no pragmas needed)
```haskell
import Data.Typeable
brokenGhc :: Typeable a => a > a
brokenGhc = id
tst = brokenGhc (Foo "bar")
brokenGhc2 :: (Typeable a) => a > String
brokenGhc2 = show . typeOf
tst2 = brokenGhc2 (Foo "Bar")
 ghci> tst2
 "Foo"
data Foo = Foo String
```
Possibly related to #10770?
## Expected behavior
`tst` and `tst2` should not compile. Note `Foo` has no instances!
## Environment
* GHC version used:
Tested with ghc8.6.5/lts14.0, ghc8.2.2/lts12.22
Optional:
* Operating System:
Ubuntu 18.04 and Ubuntu 18.10
* System Architecture:
## Suggested Labels:
~Typeable
~bug
~"program incorrectly accepted"8.10.1https://gitlab.haskell.org/ghc/ghc//issues/17077"Quantification by level numbers would fail" for an illkinded signature20190924T16:49:34ZVladislav Zavialov"Quantification by level numbers would fail" for an illkinded signature## Summary
With assertions enabled, this program causes a warning about level numbers:
```haskell
{# LANGUAGE RankNTypes, PolyKinds #}
{# OPTIONS_GHC fprintexplicitkinds #}
module T where
import Data.Proxy
t :: Proxy (z :: forall k. a)
t = t
```
The warning and the kind error are as follows:
```
WARNING: file compiler/typecheck/TcMType.hs, line 1472
Quantification by level numbers would fail
Outer level = 0
dep_tkvs = {k_a1f6[tau:0], k_a1f7[tau:0], a_a1eI[sk:1],
k_a1f4[tau:1]}
co_vars = co_a1f3 :: k_a1eK[tau:1]
~# (forall (k :: k_a1eX[tau:1]). a_a1eI[sk:1])
co_tvs = {a_a1eI[sk:1], k_a1eK[tau:1], k_a1eX[tau:1], co_a1f3}
dep_kvs = [k_a1f4[tau:1]]
dep_kvs2 = [a_a1eI[sk:1], k_a1f4[tau:1]]
nondep_tvs = []
nondep_tvs2 = []
Call stack:
CallStack (from HasCallStack):
callStackDoc, called at compiler/utils/Outputable.hs:1237:29 in ghc:Outputable
warnPprTrace, called at compiler/typecheck/TcMType.hs:1472:11 in ghc:TcMType
Bug.hs:7:13: error:
• Expected kind ‘forall (k :: k1). a’, but ‘z’ has kind ‘k0’
• In the first argument of ‘Proxy’, namely ‘(z :: forall k. a)’
In the type signature: t :: Proxy (z :: forall k. a)

7  t :: Proxy (z :: forall k. a)

```
## Steps to reproduce
1. Compile GHC with assertions enabled (`hadrian/build.sh j flavour=Devel2`).
2. Load the aforementioned program in GHCi (`_build/stage1/bin/ghc interactive`)
## Expected behavior
No warning.
## Environment
* GHC version used: HEAD## Summary
With assertions enabled, this program causes a warning about level numbers:
```haskell
{# LANGUAGE RankNTypes, PolyKinds #}
{# OPTIONS_GHC fprintexplicitkinds #}
module T where
import Data.Proxy
t :: Proxy (z :: forall k. a)
t = t
```
The warning and the kind error are as follows:
```
WARNING: file compiler/typecheck/TcMType.hs, line 1472
Quantification by level numbers would fail
Outer level = 0
dep_tkvs = {k_a1f6[tau:0], k_a1f7[tau:0], a_a1eI[sk:1],
k_a1f4[tau:1]}
co_vars = co_a1f3 :: k_a1eK[tau:1]
~# (forall (k :: k_a1eX[tau:1]). a_a1eI[sk:1])
co_tvs = {a_a1eI[sk:1], k_a1eK[tau:1], k_a1eX[tau:1], co_a1f3}
dep_kvs = [k_a1f4[tau:1]]
dep_kvs2 = [a_a1eI[sk:1], k_a1f4[tau:1]]
nondep_tvs = []
nondep_tvs2 = []
Call stack:
CallStack (from HasCallStack):
callStackDoc, called at compiler/utils/Outputable.hs:1237:29 in ghc:Outputable
warnPprTrace, called at compiler/typecheck/TcMType.hs:1472:11 in ghc:TcMType
Bug.hs:7:13: error:
• Expected kind ‘forall (k :: k1). a’, but ‘z’ has kind ‘k0’
• In the first argument of ‘Proxy’, namely ‘(z :: forall k. a)’
In the type signature: t :: Proxy (z :: forall k. a)

7  t :: Proxy (z :: forall k. a)

```
## Steps to reproduce
1. Compile GHC with assertions enabled (`hadrian/build.sh j flavour=Devel2`).
2. Load the aforementioned program in GHCi (`_build/stage1/bin/ghc interactive`)
## Expected behavior
No warning.
## Environment
* GHC version used: HEAD8.10.1Simon Peyton JonesRichard Eisenbergrae@richarde.devSimon Peyton Joneshttps://gitlab.haskell.org/ghc/ghc//issues/17105GHC unexpectedly reports variable as untouchable and suggests XAmbiguousType...20190902T10:36:05ZSergey VinokurovGHC unexpectedly reports variable as untouchable and suggests XAmbiguousTypes after enabling constraints via associated type family under rank2 argumentSorry for long subject, couldn't express it in a more succinct way :)
Please consider the following program. I have defined function `hzygo` without any issues, but after slight generalisation GHC doesn't accept `hzygo1` any more. Please see the error message below the program. However, slightly more general `hzygo2` is accepted.
```haskell
{# LANGUAGE ConstraintKinds #}
{# LANGUAGE DataKinds #}
{# LANGUAGE GADTs #}
{# LANGUAGE KindSignatures #}
{# LANGUAGE NoStarIsType #}
{# LANGUAGE PolyKinds #}
{# LANGUAGE RankNTypes #}
{# LANGUAGE ScopedTypeVariables #}
{# LANGUAGE TypeFamilies #}
module Main (main) where
import Data.Kind
import Data.Functor.Product
hfst :: Product a b ix > a ix
hfst (Pair a _) = a
hsnd :: Product a b ix > b ix
hsnd (Pair _ b) = b
newtype HFix (f :: (k > Type) > (k > Type)) (ix :: k) =
HFix { unHFix :: f (HFix f) ix }
class HFunctor (f :: (k > Type) > (k > Type)) where
hmap :: (forall ix. a ix > b ix) > (forall ix. f a ix > f b ix)
hcata
:: forall f a.
HFunctor f
=> (forall ix. f a ix > a ix)
> (forall ix. HFix f ix > a ix)
hcata alg = go
where
go :: forall ix. HFix f ix > a ix
go = alg . hmap go . unHFix
hzygo
:: forall f a b.
HFunctor f
=> (forall ix. f (Product a b) ix > a ix)
> (forall ix. f b ix > b ix)
> (forall ix. HFix f ix > a ix)
hzygo alga algb = hfst . hcata alg
where
alg :: f (Product a b) ix > Product a b ix
alg x = Pair (alga x) (algb $ hmap hsnd x)
class Constrained (f :: (k1 > k2) > (k1 > k2)) where
type Constraints f :: k1 > Constraint
class Constrained f => HFunctor' (f :: (k > Type) > (k > Type)) where
hmap'
:: (forall ix. Constraints f ix => a ix > b ix)
> (forall ix. Constraints f ix => f a ix > f b ix)
hcata'
:: forall f a.
HFunctor' f
=> (forall ix. Constraints f ix => f a ix > a ix)
> (forall ix. Constraints f ix => HFix f ix > a ix)
hcata' alg = go
where
go :: forall ix. Constraints f ix => HFix f ix > a ix
go = alg . hmap' go . unHFix
hzygo2
:: forall f a b.
HFunctor' f
=> (forall ix. Constraints f ix => f (Product a b) ix > a ix)
> (forall ix. Constraints f ix => f b ix > b ix)
> (forall ix. Constraints f ix => HFix f ix > Product a b ix)
hzygo2 alga algb = hcata' alg
where
alg :: Constraints f ix => f (Product a b) ix > Product a b ix
alg x = Pair (alga x) (algb $ hmap' hsnd x)
hzygo1
:: forall f a b.
HFunctor' f
=> (forall ix. Constraints f ix => f (Product a b) ix > a ix)
> (forall ix. Constraints f ix => f b ix > b ix)
> (forall ix. Constraints f ix => HFix f ix > a ix)
hzygo1 alga algb = hfst . hcata' alg
where
alg :: Constraints f ix => f (Product a b) ix > Product a b ix
alg x = Pair (alga x) (algb $ hmap' hsnd x)
main :: IO ()
main =
pure ()
```
```
$ ghc version
The Glorious Glasgow Haskell Compilation System, version 8.6.5
$ ghc c Main.hs
Main.hs:77:6: error:
• Couldn't match type ‘b0’ with ‘b’
‘b0’ is untouchable
inside the constraints: Constraints f ix1
bound by the type signature for:
hzygo' :: forall (ix1 :: k1).
Constraints f ix1 =>
f b0 ix1 > b0 ix1
at Main.hs:(77,6)(81,64)
‘b’ is a rigid type variable bound by
the type signature for:
hzygo' :: forall k1 (f :: (k1 > *) > k1 > *) (a :: k1
> *) (b :: k1 > *).
HFunctor f =>
(forall (ix1 :: k1).
Constraints f ix1 =>
f (Product a b) ix1 > a ix1)
> (forall (ix1 :: k1). Constraints f ix1 => f b ix1 > b ix1)
> forall (ix :: k1). Constraints f ix => HFix f ix > a ix
at Main.hs:(77,6)(81,64)
Expected type: f b0 ix1 > b0 ix1
Actual type: f b ix1 > b ix1
• In the ambiguity check for ‘hzygo'’
To defer the ambiguity check to use sites, enable AllowAmbiguousTypes
In the type signature:
hzygo' :: forall f a b.
HFunctor f =>
(forall ix. Constraints f ix => f (Product a b) ix > a ix)
> (forall ix. Constraints f ix => f b ix > b ix)
> (forall ix. Constraints f ix => HFix f ix > a ix)

77  :: forall f a b.
 ^^^^^^^^^^^^^...
Main.hs:77:6: error:
• Couldn't match type ‘b0’ with ‘b’
‘b0’ is untouchable
inside the constraints: Constraints f ix1
bound by the type signature for:
hzygo' :: forall (ix1 :: k1).
Constraints f ix1 =>
f (Product a b0) ix1 > a ix1
at Main.hs:(77,6)(81,64)
‘b’ is a rigid type variable bound by
the type signature for:
hzygo' :: forall k1 (f :: (k1 > *) > k1 > *) (a :: k1
> *) (b :: k1 > *).
HFunctor f =>
(forall (ix1 :: k1).
Constraints f ix1 =>
f (Product a b) ix1 > a ix1)
> (forall (ix1 :: k1). Constraints f ix1 => f b ix1 > b ix1)
> forall (ix :: k1). Constraints f ix => HFix f ix > a ix
at Main.hs:(77,6)(81,64)
Expected type: f (Product a b0) ix1 > a ix1
Actual type: f (Product a b) ix1 > a ix1
• In the ambiguity check for ‘hzygo'’
To defer the ambiguity check to use sites, enable AllowAmbiguousTypes
In the type signature:
hzygo' :: forall f a b.
HFunctor f =>
(forall ix. Constraints f ix => f (Product a b) ix > a ix)
> (forall ix. Constraints f ix => f b ix > b ix)
> (forall ix. Constraints f ix => HFix f ix > a ix)

77  :: forall f a b.
 ^^^^^^^^^^^^^...
```Sorry for long subject, couldn't express it in a more succinct way :)
Please consider the following program. I have defined function `hzygo` without any issues, but after slight generalisation GHC doesn't accept `hzygo1` any more. Please see the error message below the program. However, slightly more general `hzygo2` is accepted.
```haskell
{# LANGUAGE ConstraintKinds #}
{# LANGUAGE DataKinds #}
{# LANGUAGE GADTs #}
{# LANGUAGE KindSignatures #}
{# LANGUAGE NoStarIsType #}
{# LANGUAGE PolyKinds #}
{# LANGUAGE RankNTypes #}
{# LANGUAGE ScopedTypeVariables #}
{# LANGUAGE TypeFamilies #}
module Main (main) where
import Data.Kind
import Data.Functor.Product
hfst :: Product a b ix > a ix
hfst (Pair a _) = a
hsnd :: Product a b ix > b ix
hsnd (Pair _ b) = b
newtype HFix (f :: (k > Type) > (k > Type)) (ix :: k) =
HFix { unHFix :: f (HFix f) ix }
class HFunctor (f :: (k > Type) > (k > Type)) where
hmap :: (forall ix. a ix > b ix) > (forall ix. f a ix > f b ix)
hcata
:: forall f a.
HFunctor f
=> (forall ix. f a ix > a ix)
> (forall ix. HFix f ix > a ix)
hcata alg = go
where
go :: forall ix. HFix f ix > a ix
go = alg . hmap go . unHFix
hzygo
:: forall f a b.
HFunctor f
=> (forall ix. f (Product a b) ix > a ix)
> (forall ix. f b ix > b ix)
> (forall ix. HFix f ix > a ix)
hzygo alga algb = hfst . hcata alg
where
alg :: f (Product a b) ix > Product a b ix
alg x = Pair (alga x) (algb $ hmap hsnd x)
class Constrained (f :: (k1 > k2) > (k1 > k2)) where
type Constraints f :: k1 > Constraint
class Constrained f => HFunctor' (f :: (k > Type) > (k > Type)) where
hmap'
:: (forall ix. Constraints f ix => a ix > b ix)
> (forall ix. Constraints f ix => f a ix > f b ix)
hcata'
:: forall f a.
HFunctor' f
=> (forall ix. Constraints f ix => f a ix > a ix)
> (forall ix. Constraints f ix => HFix f ix > a ix)
hcata' alg = go
where
go :: forall ix. Constraints f ix => HFix f ix > a ix
go = alg . hmap' go . unHFix
hzygo2
:: forall f a b.
HFunctor' f
=> (forall ix. Constraints f ix => f (Product a b) ix > a ix)
> (forall ix. Constraints f ix => f b ix > b ix)
> (forall ix. Constraints f ix => HFix f ix > Product a b ix)
hzygo2 alga algb = hcata' alg
where
alg :: Constraints f ix => f (Product a b) ix > Product a b ix
alg x = Pair (alga x) (algb $ hmap' hsnd x)
hzygo1
:: forall f a b.
HFunctor' f
=> (forall ix. Constraints f ix => f (Product a b) ix > a ix)
> (forall ix. Constraints f ix => f b ix > b ix)
> (forall ix. Constraints f ix => HFix f ix > a ix)
hzygo1 alga algb = hfst . hcata' alg
where
alg :: Constraints f ix => f (Product a b) ix > Product a b ix
alg x = Pair (alga x) (algb $ hmap' hsnd x)
main :: IO ()
main =
pure ()
```
```
$ ghc version
The Glorious Glasgow Haskell Compilation System, version 8.6.5
$ ghc c Main.hs
Main.hs:77:6: error:
• Couldn't match type ‘b0’ with ‘b’
‘b0’ is untouchable
inside the constraints: Constraints f ix1
bound by the type signature for:
hzygo' :: forall (ix1 :: k1).
Constraints f ix1 =>
f b0 ix1 > b0 ix1
at Main.hs:(77,6)(81,64)
‘b’ is a rigid type variable bound by
the type signature for:
hzygo' :: forall k1 (f :: (k1 > *) > k1 > *) (a :: k1
> *) (b :: k1 > *).
HFunctor f =>
(forall (ix1 :: k1).
Constraints f ix1 =>
f (Product a b) ix1 > a ix1)
> (forall (ix1 :: k1). Constraints f ix1 => f b ix1 > b ix1)
> forall (ix :: k1). Constraints f ix => HFix f ix > a ix
at Main.hs:(77,6)(81,64)
Expected type: f b0 ix1 > b0 ix1
Actual type: f b ix1 > b ix1
• In the ambiguity check for ‘hzygo'’
To defer the ambiguity check to use sites, enable AllowAmbiguousTypes
In the type signature:
hzygo' :: forall f a b.
HFunctor f =>
(forall ix. Constraints f ix => f (Product a b) ix > a ix)
> (forall ix. Constraints f ix => f b ix > b ix)
> (forall ix. Constraints f ix => HFix f ix > a ix)

77  :: forall f a b.
 ^^^^^^^^^^^^^...
Main.hs:77:6: error:
• Couldn't match type ‘b0’ with ‘b’
‘b0’ is untouchable
inside the constraints: Constraints f ix1
bound by the type signature for:
hzygo' :: forall (ix1 :: k1).
Constraints f ix1 =>
f (Product a b0) ix1 > a ix1
at Main.hs:(77,6)(81,64)
‘b’ is a rigid type variable bound by
the type signature for:
hzygo' :: forall k1 (f :: (k1 > *) > k1 > *) (a :: k1
> *) (b :: k1 > *).
HFunctor f =>
(forall (ix1 :: k1).
Constraints f ix1 =>
f (Product a b) ix1 > a ix1)
> (forall (ix1 :: k1). Constraints f ix1 => f b ix1 > b ix1)
> forall (ix :: k1). Constraints f ix => HFix f ix > a ix
at Main.hs:(77,6)(81,64)
Expected type: f (Product a b0) ix1 > a ix1
Actual type: f (Product a b) ix1 > a ix1
• In the ambiguity check for ‘hzygo'’
To defer the ambiguity check to use sites, enable AllowAmbiguousTypes
In the type signature:
hzygo' :: forall f a b.
HFunctor f =>
(forall ix. Constraints f ix => f (Product a b) ix > a ix)
> (forall ix. Constraints f ix => f b ix > b ix)
> (forall ix. Constraints f ix => HFix f ix > a ix)

77  :: forall f a b.
 ^^^^^^^^^^^^^...
```https://gitlab.haskell.org/ghc/ghc//issues/17139Enormous error message when importing seemingly unused module20201226T13:07:15ZRyan ScottEnormous error message when importing seemingly unused module(Originally reported [here](https://github.com/goldfirere/singletons/issues/405).)
Here are two modules:
```hs
{# LANGUAGE DataKinds #}
{# LANGUAGE FlexibleInstances #}
{# LANGUAGE PolyKinds #}
{# LANGUAGE RankNTypes #}
{# LANGUAGE TypeFamilyDependencies #}
{# LANGUAGE TypeOperators #}
 A strippeddown version of singletons
module A where
import Data.Kind (Type)
import Data.Proxy (Proxy)
data family Sing :: k > Type
class SingI a where
sing :: Sing a
class SingKind k where
type Demote k = (r :: Type)  r > k
toSing :: Demote k > Proxy k
data TyFun :: Type > Type > Type
type a ~> b = TyFun a b > Type
infixr 0 ~>
type family Apply (f :: k1 ~> k2) (x :: k1) :: k2
newtype instance Sing (f :: k1 ~> k2) =
SLambda { applySing :: forall t. Sing t > Sing (Apply f t) }
instance (SingKind k1, SingKind k2) => SingKind (k1 ~> k2) where
type Demote (k1 ~> k2) = Demote k1 > Demote k2
toSing = undefined
withSing :: SingI a => (Sing a > b) > b
withSing f = f sing
```
```hs
{# LANGUAGE GADTs #}
{# LANGUAGE TypeFamilies #}
{# LANGUAGE RankNTypes #}
{# LANGUAGE FlexibleInstances #}
{# LANGUAGE AllowAmbiguousTypes #}
module LongTypeError where
import A
type family TypeFam f fun where
TypeFam f (a > b) = f a > TypeFam f b
lift :: (a > b) > TypeFam f (a > b)
lift f = \x > _ (f <*> x)
```
If you try to run the following command using GHC 8.6.5, GHC 8.8.1, or HEAD:
```
$ /opt/ghc/8.6.5/bin/runghc LongTypeError.hs
```
You will be presented with one of the longest type errors in the history of type errors. The full thing is about 5,000 lines long, so here is an excerpt to give you a sense for how bad it is:
```
LongTypeError.hs:15:10: error:
• Couldn't match type ‘f’ with ‘(>) a’
‘f’ is a rigid type variable bound by
the type signature for:
lift :: forall a b (f :: * > *). (a > b) > TypeFam f (a > b)
at LongTypeError.hs:14:138
Expected type: TypeFam f (a > b)
Actual type: (a > a)
> (a > a)
> TypeFam
((>) a)
((a > a)
> (a > a > a)
> (a > a > a > a)
> Demote
((k1 ~> (k1 ~> (k1 ~> (k1 ~> k1))))
~> ((k1 ~> (k1 ~> (k1 ~> (k1 ~> (k1 ~> k1)))))
~> ((k1 ~> (k1 ~> (k1 ~> (k1 ~> (k1 ~> (k1 ~> k1))))))
~> ((k1
~> (k1 ~> (k1 ~> (k1 ~> (k1 ~> (k1 ~> (k1 ~> k1)))))))
~> ((k1
~> (k1
~> (k1
~> (k1
~> (k1
~> (k1 ~> (k1 ~> (k1 ~> k1))))))))
~> ((k1
~> (k1
~> (k1
~> (k1
~> (k1
~> (k1
~> (k1
~> (k1
~> (k1
~> k1)))))))))
~> ((k1
~> (k1
~> (k1
~> (k1
~> (k1
~> (k1
~> (k1
~> (k1
~> (k1
~> (k1
~> k1))))))))))
~> ((k1
~> (k1
~> (k1
~> (k1
~> (k1
<elided>
~> k3)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))
~> k4))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))
Actual type: a > b
• In the first argument of ‘(<*>)’, namely ‘f’
In the first argument of ‘_’, namely ‘(f <*> x)’
In the expression: _ (f <*> x)
• Relevant bindings include
x :: a > a (bound at LongTypeError.hs:15:11)
f :: a > b (bound at LongTypeError.hs:15:6)
lift :: (a > b) > TypeFam f (a > b)
(bound at LongTypeError.hs:15:1)

15  lift f = \x > _ (f <*> x)
 ^
```
What is really curious about this example is that the `LongTypeError` module does not use anything from `A`. If you remove the `import A` line, you will instead get this much simpler error message:
```
LongTypeError.hs:15:10: error:
• Couldn't match type ‘f’ with ‘(>) a’
‘f’ is a rigid type variable bound by
the type signature for:
lift :: forall a b (f :: * > *). (a > b) > TypeFam f (a > b)
at LongTypeError.hs:14:138
Expected type: TypeFam f (a > b)
Actual type: (a > a)
> (a > a)
> TypeFam
((>) a) ((a > a) > (a > a > a) > (a > a > a > a) > t0)
• The lambda expression ‘\ x > _ (f <*> x)’ has one argument,
but its type ‘TypeFam f (a > b)’ has none
In the expression: \ x > _ (f <*> x)
In an equation for ‘lift’: lift f = \ x > _ (f <*> x)
• Relevant bindings include
f :: a > b (bound at LongTypeError.hs:15:6)
lift :: (a > b) > TypeFam f (a > b)
(bound at LongTypeError.hs:15:1)

15  lift f = \x > _ (f <*> x)
 ^^^^^^^^^^^^^^^^^
LongTypeError.hs:15:16: error:
• Found hole: _ :: (a > b0) > (a > a) > TypeFam ((>) a) b0
Where: ‘b0’ is an ambiguous type variable
‘a’ is a rigid type variable bound by
the type signature for:
lift :: forall a b (f :: * > *). (a > b) > TypeFam f (a > b)
at LongTypeError.hs:14:138
• In the expression: _
In the expression: _ (f <*> x)
The lambda expression ‘\ x > _ (f <*> x)’ has one argument,
but its type ‘TypeFam f (a > b)’ has none
• Relevant bindings include
x :: a > a (bound at LongTypeError.hs:15:11)
f :: a > b (bound at LongTypeError.hs:15:6)
lift :: (a > b) > TypeFam f (a > b)
(bound at LongTypeError.hs:15:1)

15  lift f = \x > _ (f <*> x)
 ^
LongTypeError.hs:15:19: error:
• Couldn't match type ‘b’ with ‘a > b0’
‘b’ is a rigid type variable bound by
the type signature for:
lift :: forall a b (f :: * > *). (a > b) > TypeFam f (a > b)
at LongTypeError.hs:14:138
Expected type: a
> a > (a > a) > (a > a > a) > (a > a > a > a) > t0
Actual type: a > b
• In the first argument of ‘(<*>)’, namely ‘f’
In the first argument of ‘_’, namely ‘(f <*> x)’
In the expression: _ (f <*> x)
• Relevant bindings include
x :: a > a (bound at LongTypeError.hs:15:11)
f :: a > b (bound at LongTypeError.hs:15:6)
lift :: (a > b) > TypeFam f (a > b)
(bound at LongTypeError.hs:15:1)

15  lift f = \x > _ (f <*> x)
 ^
```(Originally reported [here](https://github.com/goldfirere/singletons/issues/405).)
Here are two modules:
```hs
{# LANGUAGE DataKinds #}
{# LANGUAGE FlexibleInstances #}
{# LANGUAGE PolyKinds #}
{# LANGUAGE RankNTypes #}
{# LANGUAGE TypeFamilyDependencies #}
{# LANGUAGE TypeOperators #}
 A strippeddown version of singletons
module A where
import Data.Kind (Type)
import Data.Proxy (Proxy)
data family Sing :: k > Type
class SingI a where
sing :: Sing a
class SingKind k where
type Demote k = (r :: Type)  r > k
toSing :: Demote k > Proxy k
data TyFun :: Type > Type > Type
type a ~> b = TyFun a b > Type
infixr 0 ~>
type family Apply (f :: k1 ~> k2) (x :: k1) :: k2
newtype instance Sing (f :: k1 ~> k2) =
SLambda { applySing :: forall t. Sing t > Sing (Apply f t) }
instance (SingKind k1, SingKind k2) => SingKind (k1 ~> k2) where
type Demote (k1 ~> k2) = Demote k1 > Demote k2
toSing = undefined
withSing :: SingI a => (Sing a > b) > b
withSing f = f sing
```
```hs
{# LANGUAGE GADTs #}
{# LANGUAGE TypeFamilies #}
{# LANGUAGE RankNTypes #}
{# LANGUAGE FlexibleInstances #}
{# LANGUAGE AllowAmbiguousTypes #}
module LongTypeError where
import A
type family TypeFam f fun where
TypeFam f (a > b) = f a > TypeFam f b
lift :: (a > b) > TypeFam f (a > b)
lift f = \x > _ (f <*> x)
```
If you try to run the following command using GHC 8.6.5, GHC 8.8.1, or HEAD:
```
$ /opt/ghc/8.6.5/bin/runghc LongTypeError.hs
```
You will be presented with one of the longest type errors in the history of type errors. The full thing is about 5,000 lines long, so here is an excerpt to give you a sense for how bad it is:
```
LongTypeError.hs:15:10: error:
• Couldn't match type ‘f’ with ‘(>) a’
‘f’ is a rigid type variable bound by
the type signature for:
lift :: forall a b (f :: * > *). (a > b) > TypeFam f (a > b)
at LongTypeError.hs:14:138
Expected type: TypeFam f (a > b)
Actual type: (a > a)
> (a > a)
> TypeFam
((>) a)
((a > a)
> (a > a > a)
> (a > a > a > a)
> Demote
((k1 ~> (k1 ~> (k1 ~> (k1 ~> k1))))
~> ((k1 ~> (k1 ~> (k1 ~> (k1 ~> (k1 ~> k1)))))
~> ((k1 ~> (k1 ~> (k1 ~> (k1 ~> (k1 ~> (k1 ~> k1))))))
~> ((k1
~> (k1 ~> (k1 ~> (k1 ~> (k1 ~> (k1 ~> (k1 ~> k1)))))))
~> ((k1
~> (k1
~> (k1
~> (k1
~> (k1
~> (k1 ~> (k1 ~> (k1 ~> k1))))))))
~> ((k1
~> (k1
~> (k1
~> (k1
~> (k1
~> (k1
~> (k1
~> (k1
~> (k1
~> k1)))))))))
~> ((k1
~> (k1
~> (k1
~> (k1
~> (k1
~> (k1
~> (k1
~> (k1
~> (k1
~> (k1
~> k1))))))))))
~> ((k1
~> (k1
~> (k1
~> (k1
~> (k1
<elided>
~> k3)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))
~> k4))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))
Actual type: a > b
• In the first argument of ‘(<*>)’, namely ‘f’
In the first argument of ‘_’, namely ‘(f <*> x)’
In the expression: _ (f <*> x)
• Relevant bindings include
x :: a > a (bound at LongTypeError.hs:15:11)
f :: a > b (bound at LongTypeError.hs:15:6)
lift :: (a > b) > TypeFam f (a > b)
(bound at LongTypeError.hs:15:1)

15  lift f = \x > _ (f <*> x)
 ^
```
What is really curious about this example is that the `LongTypeError` module does not use anything from `A`. If you remove the `import A` line, you will instead get this much simpler error message:
```
LongTypeError.hs:15:10: error:
• Couldn't match type ‘f’ with ‘(>) a’
‘f’ is a rigid type variable bound by
the type signature for:
lift :: forall a b (f :: * > *). (a > b) > TypeFam f (a > b)
at LongTypeError.hs:14:138
Expected type: TypeFam f (a > b)
Actual type: (a > a)
> (a > a)
> TypeFam
((>) a) ((a > a) > (a > a > a) > (a > a > a > a) > t0)
• The lambda expression ‘\ x > _ (f <*> x)’ has one argument,
but its type ‘TypeFam f (a > b)’ has none
In the expression: \ x > _ (f <*> x)
In an equation for ‘lift’: lift f = \ x > _ (f <*> x)
• Relevant bindings include
f :: a > b (bound at LongTypeError.hs:15:6)
lift :: (a > b) > TypeFam f (a > b)
(bound at LongTypeError.hs:15:1)

15  lift f = \x > _ (f <*> x)
 ^^^^^^^^^^^^^^^^^
LongTypeError.hs:15:16: error:
• Found hole: _ :: (a > b0) > (a > a) > TypeFam ((>) a) b0
Where: ‘b0’ is an ambiguous type variable
‘a’ is a rigid type variable bound by
the type signature for:
lift :: forall a b (f :: * > *). (a > b) > TypeFam f (a > b)
at LongTypeError.hs:14:138
• In the expression: _
In the expression: _ (f <*> x)
The lambda expression ‘\ x > _ (f <*> x)’ has one argument,
but its type ‘TypeFam f (a > b)’ has none
• Relevant bindings include
x :: a > a (bound at LongTypeError.hs:15:11)
f :: a > b (bound at LongTypeError.hs:15:6)
lift :: (a > b) > TypeFam f (a > b)
(bound at LongTypeError.hs:15:1)

15  lift f = \x > _ (f <*> x)
 ^
LongTypeError.hs:15:19: error:
• Couldn't match type ‘b’ with ‘a > b0’
‘b’ is a rigid type variable bound by
the type signature for:
lift :: forall a b (f :: * > *). (a > b) > TypeFam f (a > b)
at LongTypeError.hs:14:138
Expected type: a
> a > (a > a) > (a > a > a) > (a > a > a > a) > t0
Actual type: a > b
• In the first argument of ‘(<*>)’, namely ‘f’
In the first argument of ‘_’, namely ‘(f <*> x)’
In the expression: _ (f <*> x)
• Relevant bindings include
x :: a > a (bound at LongTypeError.hs:15:11)
f :: a > b (bound at LongTypeError.hs:15:6)
lift :: (a > b) > TypeFam f (a > b)
(bound at LongTypeError.hs:15:1)

15  lift f = \x > _ (f <*> x)
 ^
```https://gitlab.haskell.org/ghc/ghc//issues/17202GHC does not use quantified constraint from transitive superclass20200319T18:05:13ZAlexis KingGHC does not use quantified constraint from transitive superclass## Summary
GHC sometimes does not choose to use a quantified constraint made available by a superclass, and I am not sure why. The program typechecks if a type annotation is added to give the instance search a hint. Here’s a small program that reproduces the issue:
```haskell
{# LANGUAGE ConstraintKinds #}
{# LANGUAGE GADTs #}
{# LANGUAGE QuantifiedConstraints #}
{# LANGUAGE TypeFamilies #}
module Sandbox where
type family F a
class C1 a
class (forall c. C1 c) => C2 a
class (forall b. (b ~ F a) => C2 a) => C3 a
data Dict c = c => Dict
foo :: forall a. C3 a => Dict (C1 a)
foo = Dict
bar :: forall a. C3 a => Dict (C1 a)
bar = Dict :: C2 a => Dict (C1 a)
```
The definition of `foo` is rejected with the following error:
```
error:
• Could not deduce (C1 a) arising from a use of ‘Dict’
from the context: C3 a
bound by the type signature for:
foo :: forall a. C3 a => Dict (C1 a)
Possible fix:
add (C1 a) to the context of
the type signature for:
foo :: forall a. C3 a => Dict (C1 a)
• In the expression: Dict
In an equation for ‘foo’: foo = Dict
```
However, `bar` is accepted, as GHC successfully solves the `C2 a` constraint using the quantified superclass of `C3`, then proceeds to use the quantified superclass of `C2` to solve `C1 a`.
What’s especially strange to me about this program is that the problem goes away if either constraint is nonquantified *or* if the type family is removed from the context of `C3`’s superclass. The second of those two conditions makes it sound like maybe this is related to #15347, but I don’t think it is. That issue is about equalities in quantified heads, while this involves an equality in a quantified instance context, and equalities in instance contexts are entirely legal.
I think `foo` should typecheck, but if it can’t for some reason I don’t understand, I’d prefer it at least fail with a more helpful error message.
## Environment
* GHC version used: 8.8.1## Summary
GHC sometimes does not choose to use a quantified constraint made available by a superclass, and I am not sure why. The program typechecks if a type annotation is added to give the instance search a hint. Here’s a small program that reproduces the issue:
```haskell
{# LANGUAGE ConstraintKinds #}
{# LANGUAGE GADTs #}
{# LANGUAGE QuantifiedConstraints #}
{# LANGUAGE TypeFamilies #}
module Sandbox where
type family F a
class C1 a
class (forall c. C1 c) => C2 a
class (forall b. (b ~ F a) => C2 a) => C3 a
data Dict c = c => Dict
foo :: forall a. C3 a => Dict (C1 a)
foo = Dict
bar :: forall a. C3 a => Dict (C1 a)
bar = Dict :: C2 a => Dict (C1 a)
```
The definition of `foo` is rejected with the following error:
```
error:
• Could not deduce (C1 a) arising from a use of ‘Dict’
from the context: C3 a
bound by the type signature for:
foo :: forall a. C3 a => Dict (C1 a)
Possible fix:
add (C1 a) to the context of
the type signature for:
foo :: forall a. C3 a => Dict (C1 a)
• In the expression: Dict
In an equation for ‘foo’: foo = Dict
```
However, `bar` is accepted, as GHC successfully solves the `C2 a` constraint using the quantified superclass of `C3`, then proceeds to use the quantified superclass of `C2` to solve `C1 a`.
What’s especially strange to me about this program is that the problem goes away if either constraint is nonquantified *or* if the type family is removed from the context of `C3`’s superclass. The second of those two conditions makes it sound like maybe this is related to #15347, but I don’t think it is. That issue is about equalities in quantified heads, while this involves an equality in a quantified instance context, and equalities in instance contexts are entirely legal.
I think `foo` should typecheck, but if it can’t for some reason I don’t understand, I’d prefer it at least fail with a more helpful error message.
## Environment
* GHC version used: 8.8.1https://gitlab.haskell.org/ghc/ghc//issues/17213Rankntypes without XRankNTypes20200714T17:14:18ZKrzysztof GogolewskiRankntypes without XRankNTypesConsider two modules:
```
{# LANGUAGE RankNTypes #}
module X where
foo :: (forall a. a > a) > Int
foo = foo
```
```
module Y where
import X
g = foo
```
Note that `Y` does not use `RankNTypes`.
Currently, `g` is accepted. However, the inferred type of `g` is `(forall a. a > a) > Int`, which cannot be written. We should not allow a value if writing its type requires an additional extension.
Reporting on behalf of Simon PJ.Consider two modules:
```
{# LANGUAGE RankNTypes #}
module X where
foo :: (forall a. a > a) > Int
foo = foo
```
```
module Y where
import X
g = foo
```
Note that `Y` does not use `RankNTypes`.
Currently, `g` is accepted. However, the inferred type of `g` is `(forall a. a > a) > Int`, which cannot be written. We should not allow a value if writing its type requires an additional extension.
Reporting on behalf of Simon PJ.8.10.1https://gitlab.haskell.org/ghc/ghc//issues/17301GHC.TypeLits.TypeError can print 'GHC.Types.Any' when existentials are involved20210111T13:10:21ZsheafGHC.TypeLits.TypeError can print 'GHC.Types.Any' when existentials are involvedI've run into a situation where GHC seems to forget some information.
Specifically: when wrapping typelevel information into a promoted existential datatype, and then unwrapping it, `Any` can appear.
I've boiled it down to the following simple example:
```haskell
{# LANGUAGE DataKinds #}
{# LANGUAGE GADTs #}
{# LANGUAGE PolyKinds #}
{# LANGUAGE TypeFamilies #}
{# LANGUAGE UndecidableInstances #}
module AnyTypeError where
import GHC.TypeLits
( TypeError, ErrorMessage(..) )
data A = MkA
data B (a :: A)
data TySing ty where
SB :: TySing (B a)
data ATySing where
MkATySing :: TySing ty > ATySing
type family Forget ty :: ATySing where
Forget (B a) = MkATySing SB
type family Message ty where
Message (MkATySing (_ :: TySing ty)) =
TypeError ( ShowType ty )
type KnownType = B MkA
foo :: Message (Forget KnownType) => ()
foo = ()
bar :: ()
bar = foo
```
```
AnyTypeError.hs:36:7: error:
* B GHC.Types.Any
* In the expression: foo
In an equation for `bar': bar = foo

36  bar = foo
 ^^^
Failed, no modules loaded.
```
I think the error message should instead be:
```
AnyTypeError.hs:36:7: error:
* B 'MkA
...
```
<p>
<details>
<summary> Show/hide background information (i.e. why this matters to me).</summary>
I ran into this code when working on giving helpful custom type errors. In a library I'm working on, the user can layout vertex data passed to the GPU by specifing interface slots (see e.g. [the OpenGL wiki](https://www.khronos.org/opengl/wiki/Layout_Qualifier_(GLSL)#Interface_components) for reference). For instance the following would be an invalid layout:
```haskell
type InvalidLayout = '[ Slot 0 0 ':> V 3 Double, Slot 1 0 ':> V 4 Float ]
```
After some lengthy typelevel computations with type families (involving existential types similar to those described above), I need to throw an error: the `V 4 Double` spills into the second slot (`Slot 1`) so overlaps with the `V 4 Float`. However the error message I end up throwing, because of the bug described here, comes out looking like this:
```
* Overlap at location 1, component 0:
 V GHC.Types.Any Double based at location 0, component 0,
 V GHC.Types.Any Float based at location 1, component 0.
```
The size of the vectors are lost, so the error message becomes confusingly vague.
</details>
</p>
I've tested this on GHC 8.6.5, 8.8.1 and HEAD (8.9.0.20190930), all giving identical results.I've run into a situation where GHC seems to forget some information.
Specifically: when wrapping typelevel information into a promoted existential datatype, and then unwrapping it, `Any` can appear.
I've boiled it down to the following simple example:
```haskell
{# LANGUAGE DataKinds #}
{# LANGUAGE GADTs #}
{# LANGUAGE PolyKinds #}
{# LANGUAGE TypeFamilies #}
{# LANGUAGE UndecidableInstances #}
module AnyTypeError where
import GHC.TypeLits
( TypeError, ErrorMessage(..) )
data A = MkA
data B (a :: A)
data TySing ty where
SB :: TySing (B a)
data ATySing where
MkATySing :: TySing ty > ATySing
type family Forget ty :: ATySing where
Forget (B a) = MkATySing SB
type family Message ty where
Message (MkATySing (_ :: TySing ty)) =
TypeError ( ShowType ty )
type KnownType = B MkA
foo :: Message (Forget KnownType) => ()
foo = ()
bar :: ()
bar = foo
```
```
AnyTypeError.hs:36:7: error:
* B GHC.Types.Any
* In the expression: foo
In an equation for `bar': bar = foo

36  bar = foo
 ^^^
Failed, no modules loaded.
```
I think the error message should instead be:
```
AnyTypeError.hs:36:7: error:
* B 'MkA
...
```
<p>
<details>
<summary> Show/hide background information (i.e. why this matters to me).</summary>
I ran into this code when working on giving helpful custom type errors. In a library I'm working on, the user can layout vertex data passed to the GPU by specifing interface slots (see e.g. [the OpenGL wiki](https://www.khronos.org/opengl/wiki/Layout_Qualifier_(GLSL)#Interface_components) for reference). For instance the following would be an invalid layout:
```haskell
type InvalidLayout = '[ Slot 0 0 ':> V 3 Double, Slot 1 0 ':> V 4 Float ]
```
After some lengthy typelevel computations with type families (involving existential types similar to those described above), I need to throw an error: the `V 4 Double` spills into the second slot (`Slot 1`) so overlaps with the `V 4 Float`. However the error message I end up throwing, because of the bug described here, comes out looking like this:
```
* Overlap at location 1, component 0:
 V GHC.Types.Any Double based at location 0, component 0,
 V GHC.Types.Any Float based at location 1, component 0.
```
The size of the vectors are lost, so the error message becomes confusingly vague.
</details>
</p>
I've tested this on GHC 8.6.5, 8.8.1 and HEAD (8.9.0.20190930), all giving identical results.https://gitlab.haskell.org/ghc/ghc//issues/17343BangPatterns in PatternGuards don't work like docs would suggest20191016T11:38:42ZJakob BrünkerBangPatterns in PatternGuards don't work like docs would suggest## Summary and Steps to reproduce
The docs don't seem to say anything special about the interaction between bang patterns and pattern guards, so I wouldn't expect them to work any differently there. And yet:
```haskell
let f = case undefined of !_ > () in f  (a) fails (as expected)
let f  let !_ = undefined = () in f  (b) fails (as expected)
let f  !_ < undefined = () in f  (c) succeeds...
```
## Expected behavior
I would expect `(c)` to fail, in the same way as `(a)` and `(b)` do.
Alternatively, an explanation for how BangPatterns interact with PatternGuards could be added to the "Bang patterns" section in `glasgow_exts.rst`.
## Environment
* GHC version used: 8.6.5, 8.8.1## Summary and Steps to reproduce
The docs don't seem to say anything special about the interaction between bang patterns and pattern guards, so I wouldn't expect them to work any differently there. And yet:
```haskell
let f = case undefined of !_ > () in f  (a) fails (as expected)
let f  let !_ = undefined = () in f  (b) fails (as expected)
let f  !_ < undefined = () in f  (c) succeeds...
```
## Expected behavior
I would expect `(c)` to fail, in the same way as `(a)` and `(b)` do.
Alternatively, an explanation for how BangPatterns interact with PatternGuards could be added to the "Bang patterns" section in `glasgow_exts.rst`.
## Environment
* GHC version used: 8.6.5, 8.8.18.10.1Sebastian GrafSebastian Grafhttps://gitlab.haskell.org/ghc/ghc//issues/17367Letbound wildcards are not letgeneralised20200205T23:07:07ZSebastian GrafLetbound wildcards are not letgeneralisedWith `XBangPatterns`, the act of declaring a letbinding without using it might have a sideeffect. Consider this example:
```haskell
{# LANGUAGE BangPatterns #}
f :: ()
f = let !x = undefined in ()
g :: ()
g = let !_ = undefined in ()
main = do
print f
print g
```
Both `f` and `g` declare a variable in a strict binding that is actually dead. Surprisingly, they lead to different code. Here's the Core (GHC 8.6.5) after optimisation:
```
main
= >>
(print
@ ()
GHC.Show.$fShow()
(case \ (@ a_a2hW) >
undefined
@ 'GHC.Types.LiftedRep
@ a_a2hW
(<snip>)
of
{ __DEFAULT >
GHC.Tuple.()
}))
(print
@ ()
GHC.Show.$fShow()
(case undefined
@ 'GHC.Types.LiftedRep
@ GHC.Types.Any
(<snip>)
of
{ __DEFAULT >
GHC.Tuple.()
}))
```
Note the `/\a. undefined @LiftedRep @a` in the first scrutinee. This is ultimately due to the fact that `x` is letgeneralised, whereas `_` is not. The first case is on a lambda, so I expect it to perform no forcing at all. The first case evaluates a complete application of `undefined`, so should crash. As a result, I'd expect this program to generate the following output:
```
()
test: Prelude.undefined
CallStack (from HasCallStack):
error, called at libraries/base/GHC/Err.hs:78:14 in base:GHC.Err
undefined, called at test.hs:4:15 in main:Main
```
Currently (tested on GHC 8.6.5), even the first `print f` will crash, so the behavior is actually consistent. I think this is actually a reasonable semantics, but I didn't expect it based on the difference in Core. My understanding of Core semantics might be off here.
So: Is letgeneralisation of `x` but not of `_` expected? If so, why does `let !x = undefined in ()` crash?
CC @simonpj @rae since this is a continuation of the discussion in https://gitlab.haskell.org/ghc/ghc/merge_requests/1954#note_229057.With `XBangPatterns`, the act of declaring a letbinding without using it might have a sideeffect. Consider this example:
```haskell
{# LANGUAGE BangPatterns #}
f :: ()
f = let !x = undefined in ()
g :: ()
g = let !_ = undefined in ()
main = do
print f
print g
```
Both `f` and `g` declare a variable in a strict binding that is actually dead. Surprisingly, they lead to different code. Here's the Core (GHC 8.6.5) after optimisation:
```
main
= >>
(print
@ ()
GHC.Show.$fShow()
(case \ (@ a_a2hW) >
undefined
@ 'GHC.Types.LiftedRep
@ a_a2hW
(<snip>)
of
{ __DEFAULT >
GHC.Tuple.()
}))
(print
@ ()
GHC.Show.$fShow()
(case undefined
@ 'GHC.Types.LiftedRep
@ GHC.Types.Any
(<snip>)
of
{ __DEFAULT >
GHC.Tuple.()
}))
```
Note the `/\a. undefined @LiftedRep @a` in the first scrutinee. This is ultimately due to the fact that `x` is letgeneralised, whereas `_` is not. The first case is on a lambda, so I expect it to perform no forcing at all. The first case evaluates a complete application of `undefined`, so should crash. As a result, I'd expect this program to generate the following output:
```
()
test: Prelude.undefined
CallStack (from HasCallStack):
error, called at libraries/base/GHC/Err.hs:78:14 in base:GHC.Err
undefined, called at test.hs:4:15 in main:Main
```
Currently (tested on GHC 8.6.5), even the first `print f` will crash, so the behavior is actually consistent. I think this is actually a reasonable semantics, but I didn't expect it based on the difference in Core. My understanding of Core semantics might be off here.
So: Is letgeneralisation of `x` but not of `_` expected? If so, why does `let !x = undefined in ()` crash?
CC @simonpj @rae since this is a continuation of the discussion in https://gitlab.haskell.org/ghc/ghc/merge_requests/1954#note_229057.https://gitlab.haskell.org/ghc/ghc//issues/17395`tcMatchTy` is terribly broken20191101T09:28:24ZSimon Peyton Jones`tcMatchTy` is terribly brokenSuppose `(T :: forall k. k > Type)` and we are matching
```
tcMatchTy (T k (a::k)) (T j (b::j))
```
Then we'll match `k :> j`, as expected. But then in `TcUnify.unify_tys`
we invoke
```
unify_tys env (a::k) (b::j) (Refl k)
```
Despite `Note [Kind coercions in Unify]` it's not clear to
me why we need that Refl coercion.
But, assuming we need it, very very bad things now happen.
In `uUnrefined` we end up adding the binding `a :> (b > Refl k)`.
Alas! Alack! `k` is one of the template variables, which we are
substituting away, so it's **terrible** if `k` appears in the
range of the substitution  it belongs only in the range.
A oneline (actually onecharacter) fix is this:
```
 = do { unify_ty env x y (mkNomReflCo $ typeKind x)
+ = do { unify_ty env x y (mkNomReflCo $ typeKind y)
```
But I am hardpressed to explain exactly why this is the correct fix.
@rae, help?
This actually bit me when working on `mkCastTy` in #17323.Suppose `(T :: forall k. k > Type)` and we are matching
```
tcMatchTy (T k (a::k)) (T j (b::j))
```
Then we'll match `k :> j`, as expected. But then in `TcUnify.unify_tys`
we invoke
```
unify_tys env (a::k) (b::j) (Refl k)
```
Despite `Note [Kind coercions in Unify]` it's not clear to
me why we need that Refl coercion.
But, assuming we need it, very very bad things now happen.
In `uUnrefined` we end up adding the binding `a :> (b > Refl k)`.
Alas! Alack! `k` is one of the template variables, which we are
substituting away, so it's **terrible** if `k` appears in the
range of the substitution  it belongs only in the range.
A oneline (actually onecharacter) fix is this:
```
 = do { unify_ty env x y (mkNomReflCo $ typeKind x)
+ = do { unify_ty env x y (mkNomReflCo $ typeKind y)
```
But I am hardpressed to explain exactly why this is the correct fix.
@rae, help?
This actually bit me when working on `mkCastTy` in #17323.8.10.1https://gitlab.haskell.org/ghc/ghc//issues/17541Regression involving unboxed types and type families20191212T16:20:40ZMatthew PickeringRegression involving unboxed types and type familiesThis program compiles with 8.6.5 and 8.8.1 but not with HEAD.
```
{# LANGUAGE
MagicHash,
FlexibleInstances,
MultiParamTypeClasses,
TypeFamilies,
PolyKinds,
DataKinds,
FunctionalDependencies,
TypeFamilyDependencies #}
module A where
import GHC.Prim
import GHC.Exts
type family Rep rep where
Rep Int = IntRep
type family Unboxed rep = (urep :: TYPE (Rep rep))  urep > rep where
Unboxed Int = Int#
```
```
[1 of 1] Compiling A ( A.hs, A.o )
A.hs:20:17: error:
• Expected kind ‘TYPE (Rep rep)’,
but ‘Int#’ has kind ‘TYPE 'IntRep’
• In the type ‘Int#’
In the type family declaration for ‘Unboxed’

20  Unboxed Int = Int#
 ^^^^
```This program compiles with 8.6.5 and 8.8.1 but not with HEAD.
```
{# LANGUAGE
MagicHash,
FlexibleInstances,
MultiParamTypeClasses,
TypeFamilies,
PolyKinds,
DataKinds,
FunctionalDependencies,
TypeFamilyDependencies #}
module A where
import GHC.Prim
import GHC.Exts
type family Rep rep where
Rep Int = IntRep
type family Unboxed rep = (urep :: TYPE (Rep rep))  urep > rep where
Unboxed Int = Int#
```
```
[1 of 1] Compiling A ( A.hs, A.o )
A.hs:20:17: error:
• Expected kind ‘TYPE (Rep rep)’,
but ‘Int#’ has kind ‘TYPE 'IntRep’
• In the type ‘Int#’
In the type family declaration for ‘Unboxed’

20  Unboxed Int = Int#
 ^^^^
```https://gitlab.haskell.org/ghc/ghc//issues/17562`Any` appearing in a quantified constraint20210111T13:07:45ZRichard Eisenbergrae@richarde.dev`Any` appearing in a quantified constraintIf I say
```hs
{# LANGUAGE QuantifiedConstraints, MultiParamTypeClasses #}
module Bug where
class (forall a. a b ~ a c) => C b c
```
I get
```
Bug.hs:5:1: error:
• Illegal type synonym family application ‘GHC.Types.Any
@*’ in instance:
(a b :: GHC.Types.Any @*) ~ (a c :: GHC.Types.Any @*)
• In the quantified constraint ‘forall (a :: k > GHC.Types.Any).
a b ~ a c’
In the context: forall (a :: k > GHC.Types.Any). a b ~ a c
While checking the superclasses of class ‘C’
In the class declaration for ‘C’

5  class (forall a. a b ~ a c) => C b c
 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
```
This is a specific case of #17567. Despite superficial similarity, this is unrelated to #16775.If I say
```hs
{# LANGUAGE QuantifiedConstraints, MultiParamTypeClasses #}
module Bug where
class (forall a. a b ~ a c) => C b c
```
I get
```
Bug.hs:5:1: error:
• Illegal type synonym family application ‘GHC.Types.Any
@*’ in instance:
(a b :: GHC.Types.Any @*) ~ (a c :: GHC.Types.Any @*)
• In the quantified constraint ‘forall (a :: k > GHC.Types.Any).
a b ~ a c’
In the context: forall (a :: k > GHC.Types.Any). a b ~ a c
While checking the superclasses of class ‘C’
In the class declaration for ‘C’

5  class (forall a. a b ~ a c) => C b c
 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
```
This is a specific case of #17567. Despite superficial similarity, this is unrelated to #16775.9.0.1Richard Eisenbergrae@richarde.devRichard Eisenbergrae@richarde.devhttps://gitlab.haskell.org/ghc/ghc//issues/17567Never `Any`ify during kind inference20210111T13:09:30ZRichard Eisenbergrae@richarde.devNever `Any`ify during kind inference#14198 concludes with a new plan: never `Any`ify during kind inference. This ticket tracks this particular problem, separate from #14198.
Here are some examples of `Any`ification during kind inference:
#17301:
```hs
data B a
data TySing ty where
SB :: TySing (B a)
data ATySing where
MkATySing :: TySing ty > ATySing
type family Forget ty :: ATySing where
Forget (B a) = MkATySing SB
```
The RHS of that type family equation is really `MkATySing @alpha (SB @alpha)`, and the `alpha` gets zonked to `Any`.
#14198:
```hs
type T = forall a. Proxy a
```
The RHS of the type synonym is really `forall (a :: kappa). Proxy @kappa a`, and the `kappa` gets zonked to `Any`.
#17562:
```hs
class (forall a. a b ~ a c) => C b c
```
The superclass constraint is really `forall (a :: Type > kappa). (~) @kappa (a b) (a c))`, and the `kappa` gets zonked to `Any`.
We want to stop zonking to `Any`, preferring to error instead. But how should we implement?
* Option A: Use a new variant of `ZonkFlexi`, a choice carried around in a `ZonkEnv` that says what to do with empty metavariables. The new choice would cause an error. This new form of `ZonkFlexi` would be used in the final zonks in e.g. TcTyClsDecls. Open question: how to get a decent error message? I think we'd have to pass around the original, toplevel type in order to report it. By the time we have just the unbound metavariable, we have no context to report.
* Option B: Similar to (A), but don't report an error in the zonker. Instead, the new variant of `ZonkFlexi` would insert some magical error type. Then, the validity checker could do an early pass, looking for the error type; it can then report a nice error message.
* Option C: Look for all cases where `Any`ification might happen, and detect each one separately. This can produce lovely error messages. The solution for #17562 in !2313 does this. Perhaps we can pair this choice with a new `ZonkFlexi` that panics. That way, we'll know if we've missed a case.
* Simon below proposes Option D: Zap to `Type` instead of `Any`. I (Richard) view D as an addon to any of the above plans. Because `Type` is not always wellkinded, we can only zap to `Type` sometimes, and we still need to decide what we do at other times. Personally, I prefer not to treat `Type` specially with XPolyKinds` enabled, and so I'd prefer that we don't do this.
* EDIT: Also, we can consider Option E: Report poor error messages, saying something about an unconstrained kind variable. Users would be helped only via the context (the "In the data declaration for `Wurble`" bits). This would mean building up useful contexts in the zonker.
* Option F: The new constructor for `ZonkFlexi` could carry the toplevel type we are trying to zonk. If we encounter an unconstrained metavariable, we just look at this bit of context to produce the error message. Perhaps this could be combined with the contextbuilding in Option E for good effect. This is the first solution I'm actually happy with.
Thoughts?#14198 concludes with a new plan: never `Any`ify during kind inference. This ticket tracks this particular problem, separate from #14198.
Here are some examples of `Any`ification during kind inference:
#17301:
```hs
data B a
data TySing ty where
SB :: TySing (B a)
data ATySing where
MkATySing :: TySing ty > ATySing
type family Forget ty :: ATySing where
Forget (B a) = MkATySing SB
```
The RHS of that type family equation is really `MkATySing @alpha (SB @alpha)`, and the `alpha` gets zonked to `Any`.
#14198:
```hs
type T = forall a. Proxy a
```
The RHS of the type synonym is really `forall (a :: kappa). Proxy @kappa a`, and the `kappa` gets zonked to `Any`.
#17562:
```hs
class (forall a. a b ~ a c) => C b c
```
The superclass constraint is really `forall (a :: Type > kappa). (~) @kappa (a b) (a c))`, and the `kappa` gets zonked to `Any`.
We want to stop zonking to `Any`, preferring to error instead. But how should we implement?
* Option A: Use a new variant of `ZonkFlexi`, a choice carried around in a `ZonkEnv` that says what to do with empty metavariables. The new choice would cause an error. This new form of `ZonkFlexi` would be used in the final zonks in e.g. TcTyClsDecls. Open question: how to get a decent error message? I think we'd have to pass around the original, toplevel type in order to report it. By the time we have just the unbound metavariable, we have no context to report.
* Option B: Similar to (A), but don't report an error in the zonker. Instead, the new variant of `ZonkFlexi` would insert some magical error type. Then, the validity checker could do an early pass, looking for the error type; it can then report a nice error message.
* Option C: Look for all cases where `Any`ification might happen, and detect each one separately. This can produce lovely error messages. The solution for #17562 in !2313 does this. Perhaps we can pair this choice with a new `ZonkFlexi` that panics. That way, we'll know if we've missed a case.
* Simon below proposes Option D: Zap to `Type` instead of `Any`. I (Richard) view D as an addon to any of the above plans. Because `Type` is not always wellkinded, we can only zap to `Type` sometimes, and we still need to decide what we do at other times. Personally, I prefer not to treat `Type` specially with XPolyKinds` enabled, and so I'd prefer that we don't do this.
* EDIT: Also, we can consider Option E: Report poor error messages, saying something about an unconstrained kind variable. Users would be helped only via the context (the "In the data declaration for `Wurble`" bits). This would mean building up useful contexts in the zonker.
* Option F: The new constructor for `ZonkFlexi` could carry the toplevel type we are trying to zonk. If we encounter an unconstrained metavariable, we just look at this bit of context to produce the error message. Perhaps this could be combined with the contextbuilding in Option E for good effect. This is the first solution I'm actually happy with.
Thoughts?https://gitlab.haskell.org/ghc/ghc//issues/17625Evidence for equality constraints on typeclass methods isn’t erased20200108T16:45:20ZAlexis KingEvidence for equality constraints on typeclass methods isn’t erasedGenerally, I expect `a ~ b` constraints to have no runtime cost, so I was surprised to discover that they sometimes do. If I understand correctly, constraints of type `a ~ b` are boxed versions of `a ~# b`, the latter of which have no runtime representation. Ordinarily, this boxing and unboxing is eliminated via worker/wrapper just like any other boxing, but worker/wrapper can only be performed at call sites to known functions, so equality constraints on typeclass methods are not erased unless the method is specialized. This program illustrates that:
```haskell
{# LANGUAGE ConstrainedClassMethods, TypeFamilies #}
module M where
type family F a
class C a where
m :: F a ~ Int => a > Bool
f :: (C a, F a ~ Int) => a > Bool
f x = not (m x)
```
Compiling with `O ddumpsimpl` reveals that the call to `m` inside `F a ~ Int` really does pass a boxed equality.
This seems silly to me. As far as I can tell, equalities are aggressively forced, so it would be entirely safe to perform a worker/wrapperesque transformation to the `C` constructor itself. Specifically, GHC could desugar `C` into the following:
```haskell
newtype C a = $WC { $wm :: F a ~# Int > a > Bool }
C :: (F a ~ Int => a > Bool) > C a
C m = $WC { $wm = m `seq` \co > m (Eq# co) }
m :: (C a, F a ~ Int) => a > Bool
m ($WC { $wm }) (Eq# co) = $wm co
```
The equality argument would be erased on both ends via the same mechanism that exists today for worker/wrapper DataCons, and the resulting program would be slightly more efficient.
Maybe there is some problem with this scheme I’m not seeing; it’s entirely possible. I don’t know all the subtleties. But seeing as it seems totally sound to me based on the investigation I’ve done so far, and since equalities *not* being erased was so surprising to me, I feel like it isn’t entirely unreasonable to consider this a bug rather than a missing feature (though that is admittedly arguable).Generally, I expect `a ~ b` constraints to have no runtime cost, so I was surprised to discover that they sometimes do. If I understand correctly, constraints of type `a ~ b` are boxed versions of `a ~# b`, the latter of which have no runtime representation. Ordinarily, this boxing and unboxing is eliminated via worker/wrapper just like any other boxing, but worker/wrapper can only be performed at call sites to known functions, so equality constraints on typeclass methods are not erased unless the method is specialized. This program illustrates that:
```haskell
{# LANGUAGE ConstrainedClassMethods, TypeFamilies #}
module M where
type family F a
class C a where
m :: F a ~ Int => a > Bool
f :: (C a, F a ~ Int) => a > Bool
f x = not (m x)
```
Compiling with `O ddumpsimpl` reveals that the call to `m` inside `F a ~ Int` really does pass a boxed equality.
This seems silly to me. As far as I can tell, equalities are aggressively forced, so it would be entirely safe to perform a worker/wrapperesque transformation to the `C` constructor itself. Specifically, GHC could desugar `C` into the following:
```haskell
newtype C a = $WC { $wm :: F a ~# Int > a > Bool }
C :: (F a ~ Int => a > Bool) > C a
C m = $WC { $wm = m `seq` \co > m (Eq# co) }
m :: (C a, F a ~ Int) => a > Bool
m ($WC { $wm }) (Eq# co) = $wm co
```
The equality argument would be erased on both ends via the same mechanism that exists today for worker/wrapper DataCons, and the resulting program would be slightly more efficient.
Maybe there is some problem with this scheme I’m not seeing; it’s entirely possible. I don’t know all the subtleties. But seeing as it seems totally sound to me based on the investigation I’ve done so far, and since equalities *not* being erased was so surprising to me, I feel like it isn’t entirely unreasonable to consider this a bug rather than a missing feature (though that is admittedly arguable).https://gitlab.haskell.org/ghc/ghc//issues/17633Closed type family declaration accepts any name in LHS20200103T21:33:08ZMaxim KoltsovClosed type family declaration accepts any name in LHS## Summary
Closed type family declaration will accept (almost) any name instead of family's name left of `=`.
## Steps to reproduce
```haskell
{# LANGUAGE TypeFamilies #}
module WTF where
type family Bar (a :: *) :: * where
Bar Int = ()
type family Foo (a :: *) :: * where
Bar Int = Bool
Bar Bool = Int
Bar a = a
```
When loaded to ghci, this file not only compiles, but works as if `Foo` were defined the normal way:
```
λ> :kind! Bar Int
Bar Int :: *
= ()
λ> :kind! Bar Bool
Bar Bool :: *
= Bar Bool
λ> :kind! Foo Int
Foo Int :: *
= Bool
λ> :kind! Foo Bool
Foo Bool :: *
= Int
λ> :kind! Foo Char
Foo Char :: *
= Char
```
It's clear that `Foo` is defined as it should be and that `Bar` is not broken by this definition.
## Expected behavior
GHC should emit an error in this case, as this code seems very strange.
Curiously, if `Bar` is not in scope GHC detects an error at `Foo`'s definition:
```
<interactive>:5:3: error:
Not in scope: type constructor or class ‘Bar’
```
Moreover, if I try to use some family from another module, it fails as well:
```
> import GHC.Generics
> :{
 type family Foo (a :: *) where
 Rep Bool = Maybe
 :}
<interactive>:6:3: error:
• Mismatched type name in type family instance.
Expected: Foo
Actual: Rep
```
## Environment
* GHC version used:
```console
$ stack exec  ghc V
The Glorious Glasgow Haskell Compilation System, version 8.6.3
```
* Operating System: macOS## Summary
Closed type family declaration will accept (almost) any name instead of family's name left of `=`.
## Steps to reproduce
```haskell
{# LANGUAGE TypeFamilies #}
module WTF where
type family Bar (a :: *) :: * where
Bar Int = ()
type family Foo (a :: *) :: * where
Bar Int = Bool
Bar Bool = Int
Bar a = a
```
When loaded to ghci, this file not only compiles, but works as if `Foo` were defined the normal way:
```
λ> :kind! Bar Int
Bar Int :: *
= ()
λ> :kind! Bar Bool
Bar Bool :: *
= Bar Bool
λ> :kind! Foo Int
Foo Int :: *
= Bool
λ> :kind! Foo Bool
Foo Bool :: *
= Int
λ> :kind! Foo Char
Foo Char :: *
= Char
```
It's clear that `Foo` is defined as it should be and that `Bar` is not broken by this definition.
## Expected behavior
GHC should emit an error in this case, as this code seems very strange.
Curiously, if `Bar` is not in scope GHC detects an error at `Foo`'s definition:
```
<interactive>:5:3: error:
Not in scope: type constructor or class ‘Bar’
```
Moreover, if I try to use some family from another module, it fails as well:
```
> import GHC.Generics
> :{
 type family Foo (a :: *) where
 Rep Bool = Maybe
 :}
<interactive>:6:3: error:
• Mismatched type name in type family instance.
Expected: Foo
Actual: Rep
```
## Environment
* GHC version used:
```console
$ stack exec  ghc V
The Glorious Glasgow Haskell Compilation System, version 8.6.3
```
* Operating System: macOS8.8.1https://gitlab.haskell.org/ghc/ghc//issues/17672Never kick out Given Nominal equalities20210413T14:16:56ZRichard Eisenbergrae@richarde.devNever kick out Given Nominal equalitiesIn other explorations (#17323 and friends) Simon and I determined that a Given Nominal equality should never be kicked out. Why? Because the mutable update of a unification variable should really behave just like a given nominal equality (really, the solver should be pure, but that would be inefficient). Mutable variable updates can't get revisited (i.e. kicked out), so neither should given nominal equalities. And we almost have this property. Here is the relevant text:
Lemma: Nominal Given equalities are never kicked out. Proof: Let `a fw> t` be a work item and `b G/N> s` be an inert equality. We must show that, regardless of `a`, `t`, `b`, and `s`, condition K from the Note always hold. (Condition K is the "keep" condition.)
K0 is true when `fw /= G/N`. If K0 is true, then K is true, and we are done. So, we assume that `fw = G/N`.
We must show all of K1K3.
K1: `not (a = b)`. This must be true, because if `a = b`, then `a` would have been rewritten during canonicalization. This is the case because `G/N >= G/N`.
K2: `not (G/N >= G/N) OR G/N >= G/N OR ...`. True by the law of the excluded middle.
K3: Actually, only K3a applies, because the role is nominal: `s /= a`. Actually, we might indeed have `s = a`. But we still shouldn't kick out; see Note \[K3: completeness of solving\], which makes this clear. So, **Action Item**: modify the kickout conditions so that this proof holds.
QED.
We think the new keep condition should be `s /= a && t /= b`. This ticket is to doublecheck this intuition and execute.
We believe that there is no loop or other misbehavior here. It's just good hygiene to have given nominals and metavar unifications to be treated identically within the solver. And less kicking out is good, all else being equal.In other explorations (#17323 and friends) Simon and I determined that a Given Nominal equality should never be kicked out. Why? Because the mutable update of a unification variable should really behave just like a given nominal equality (really, the solver should be pure, but that would be inefficient). Mutable variable updates can't get revisited (i.e. kicked out), so neither should given nominal equalities. And we almost have this property. Here is the relevant text:
Lemma: Nominal Given equalities are never kicked out. Proof: Let `a fw> t` be a work item and `b G/N> s` be an inert equality. We must show that, regardless of `a`, `t`, `b`, and `s`, condition K from the Note always hold. (Condition K is the "keep" condition.)
K0 is true when `fw /= G/N`. If K0 is true, then K is true, and we are done. So, we assume that `fw = G/N`.
We must show all of K1K3.
K1: `not (a = b)`. This must be true, because if `a = b`, then `a` would have been rewritten during canonicalization. This is the case because `G/N >= G/N`.
K2: `not (G/N >= G/N) OR G/N >= G/N OR ...`. True by the law of the excluded middle.
K3: Actually, only K3a applies, because the role is nominal: `s /= a`. Actually, we might indeed have `s = a`. But we still shouldn't kick out; see Note \[K3: completeness of solving\], which makes this clear. So, **Action Item**: modify the kickout conditions so that this proof holds.
QED.
We think the new keep condition should be `s /= a && t /= b`. This ticket is to doublecheck this intuition and execute.
We believe that there is no loop or other misbehavior here. It's just good hygiene to have given nominals and metavar unifications to be treated identically within the solver. And less kicking out is good, all else being equal.https://gitlab.haskell.org/ghc/ghc//issues/17710Polykinded rewrite rule fails to typecheck (HEAD only)20200315T18:51:16ZRyan ScottPolykinded rewrite rule fails to typecheck (HEAD only)I originally noticed this issue since it prevents the `freealgebras0.0.8.1` library from building with HEAD (build log [here](https://gitlab.haskell.org/RyanGlScott/head.hackage//jobs/240129)). Here is a minimized example that demonstrates the issue:
```hs
{# LANGUAGE PolyKinds #}
{# LANGUAGE RankNTypes #}
module Bug where
import Data.Proxy
foo :: forall k (b :: k). (forall (a :: k). Proxy a > Proxy a) > Proxy b
foo g = g Proxy
{# INLINABLE [1] foo #}
{# RULES "foo" forall (g :: forall (a :: k). Proxy a > Proxy a). foo g = g Proxy #}
```
This typechecks on GHC 8.8.2 and 8.10.1alpha2, but on HEAD it fails to typecheck:
```
$ ~/Software/ghc5/inplace/bin/ghcstage2 Bug.hs
[1 of 1] Compiling Bug ( Bug.hs, Bug.o )
Bug.hs:10:11: error:
• Cannot generalise type; skolem ‘k’ would escape its scope
if I tried to quantify (b0 :: k) in this type:
forall k. Proxy @{k} b0
(Indeed, I sometimes struggle even printing this correctly,
due to its illscoped nature.)
• When checking the transformation rule "foo"

10  {# RULES "foo" forall (g :: forall (a :: k). Proxy a > Proxy a). foo g = g Proxy #}
 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
```
Judging by the error message, this regression was likely introduced in commit 350e2b78788d47255d27489dfc62d664498b5de4 (`Don't zap to Any; error instead`). cc'ing @rae, the author of that commit.I originally noticed this issue since it prevents the `freealgebras0.0.8.1` library from building with HEAD (build log [here](https://gitlab.haskell.org/RyanGlScott/head.hackage//jobs/240129)). Here is a minimized example that demonstrates the issue:
```hs
{# LANGUAGE PolyKinds #}
{# LANGUAGE RankNTypes #}
module Bug where
import Data.Proxy
foo :: forall k (b :: k). (forall (a :: k). Proxy a > Proxy a) > Proxy b
foo g = g Proxy
{# INLINABLE [1] foo #}
{# RULES "foo" forall (g :: forall (a :: k). Proxy a > Proxy a). foo g = g Proxy #}
```
This typechecks on GHC 8.8.2 and 8.10.1alpha2, but on HEAD it fails to typecheck:
```
$ ~/Software/ghc5/inplace/bin/ghcstage2 Bug.hs
[1 of 1] Compiling Bug ( Bug.hs, Bug.o )
Bug.hs:10:11: error:
• Cannot generalise type; skolem ‘k’ would escape its scope
if I tried to quantify (b0 :: k) in this type:
forall k. Proxy @{k} b0
(Indeed, I sometimes struggle even printing this correctly,
due to its illscoped nature.)
• When checking the transformation rule "foo"

10  {# RULES "foo" forall (g :: forall (a :: k). Proxy a > Proxy a). foo g = g Proxy #}
 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
```
Judging by the error message, this regression was likely introduced in commit 350e2b78788d47255d27489dfc62d664498b5de4 (`Don't zap to Any; error instead`). cc'ing @rae, the author of that commit.9.0.1https://gitlab.haskell.org/ghc/ghc//issues/17772CUSKless class typechecks on 8.4, but not on 8.6+20210331T17:39:10ZRyan ScottCUSKless class typechecks on 8.4, but not on 8.6+This code will typecheck with GHC 8.0.2 through 8.4.4:
```hs
{# LANGUAGE ScopedTypeVariables #}
{# LANGUAGE TypeFamilies #}
{# LANGUAGE TypeInType #}
module Bug where
import Data.Kind
import Data.Proxy
class C f where
type T (x :: f a) :: Type
sT :: forall a (x :: f a).
Proxy x > T x
```
However, it mysteriously _does_ not typecheck on GHC 8.6.5 or later:
```
$ /opt/ghc/8.8.2/bin/ghc Bug.hs
[1 of 1] Compiling Bug ( Bug.hs, Bug.o )
Bug.hs:13:22: error:
• Expected kind ‘f a’, but ‘x’ has kind ‘f a1’
• In the first argument of ‘T’, namely ‘x’
In the type signature: sT :: forall a (x :: f a). Proxy x > T x
In the class declaration for ‘C’

13  Proxy x > T x
 ^
```
I cannot think of a good reason why this shouldn't typecheck, especially since there appears to be no polymorphic recursion happening in `C`, `T`, or `sT`.
Some observations:
* Giving `C` a CUSK (i.e., `class C (f :: k > Type) where ...`) makes it typecheck:
* Splitting up `C` into two classes like so also makes it typecheck:
```hs
class C1 f where
type T (x :: f a) :: Type
class C2 f where
sT :: forall a (x :: f a).
Proxy x > T x
```This code will typecheck with GHC 8.0.2 through 8.4.4:
```hs
{# LANGUAGE ScopedTypeVariables #}
{# LANGUAGE TypeFamilies #}
{# LANGUAGE TypeInType #}
module Bug where
import Data.Kind
import Data.Proxy
class C f where
type T (x :: f a) :: Type
sT :: forall a (x :: f a).
Proxy x > T x
```
However, it mysteriously _does_ not typecheck on GHC 8.6.5 or later:
```
$ /opt/ghc/8.8.2/bin/ghc Bug.hs
[1 of 1] Compiling Bug ( Bug.hs, Bug.o )
Bug.hs:13:22: error:
• Expected kind ‘f a’, but ‘x’ has kind ‘f a1’
• In the first argument of ‘T’, namely ‘x’
In the type signature: sT :: forall a (x :: f a). Proxy x > T x
In the class declaration for ‘C’

13  Proxy x > T x
 ^
```
I cannot think of a good reason why this shouldn't typecheck, especially since there appears to be no polymorphic recursion happening in `C`, `T`, or `sT`.
Some observations:
* Giving `C` a CUSK (i.e., `class C (f :: k > Type) where ...`) makes it typecheck:
* Splitting up `C` into two classes like so also makes it typecheck:
```hs
class C1 f where
type T (x :: f a) :: Type
class C2 f where
sT :: forall a (x :: f a).
Proxy x > T x
```https://gitlab.haskell.org/ghc/ghc//issues/17789Instantiation doesn't look through dictionaries20200205T11:16:36ZRichard Eisenbergrae@richarde.devInstantiation doesn't look through dictionariesThe bug is simple to state in terms of GHC's implementation: `topInstantiate` does not look past dictionaries. Thus a type like `forall a. C a => forall b. ...` only gets its `a` instantiated, not its `b`. This can be witnessed is some uglylooking code:
```hs
data Rec a b = MkRec { x :: Bool }
class C a where
r :: Rec a b
instance C Int where
r = MkRec { x = True }
foo :: Rec Int Bool
foo = r { x = False }
```
This fails with
```
/Users/rae/temp/Bug.hs:10:7: error:
• Ambiguous type variable ‘a0’ arising from a use of ‘r’
prevents the constraint ‘(C a0)’ from being solved.
Probable fix: use a type annotation to specify what ‘a0’ should be.
These potential instance exist:
instance C Int  Defined at /Users/rae/temp/Bug.hs:6:10
• In the expression: r
In the expression: r {x = False}
In an equation for ‘foo’: foo = r {x = False}
```
I have no idea why it's an ambiguousvariable error, but let's not get distracted by that. The problem is that GHC does not instantiate `r` vigorously enough to notice that it's a record. The solution is straightforward: have `topInstantiate` be recursive, looking past dictionaries. `topInstantiate` is used in other places, too, and perhaps there are other similar bugs to find.The bug is simple to state in terms of GHC's implementation: `topInstantiate` does not look past dictionaries. Thus a type like `forall a. C a => forall b. ...` only gets its `a` instantiated, not its `b`. This can be witnessed is some uglylooking code:
```hs
data Rec a b = MkRec { x :: Bool }
class C a where
r :: Rec a b
instance C Int where
r = MkRec { x = True }
foo :: Rec Int Bool
foo = r { x = False }
```
This fails with
```
/Users/rae/temp/Bug.hs:10:7: error:
• Ambiguous type variable ‘a0’ arising from a use of ‘r’
prevents the constraint ‘(C a0)’ from being solved.
Probable fix: use a type annotation to specify what ‘a0’ should be.
These potential instance exist:
instance C Int  Defined at /Users/rae/temp/Bug.hs:6:10
• In the expression: r
In the expression: r {x = False}
In an equation for ‘foo’: foo = r {x = False}
```
I have no idea why it's an ambiguousvariable error, but let's not get distracted by that. The problem is that GHC does not instantiate `r` vigorously enough to notice that it's a record. The solution is straightforward: have `topInstantiate` be recursive, looking past dictionaries. `topInstantiate` is used in other places, too, and perhaps there are other similar bugs to find.https://gitlab.haskell.org/ghc/ghc//issues/17827Deduplicate overlapping Notes [TyVar/TyVar orientation] in TcUnify and [Canon...20200214T16:54:11ZRichard Eisenbergrae@richarde.devDeduplicate overlapping Notes [TyVar/TyVar orientation] in TcUnify and [Canonical orientation for tyvar/tyvar equality constraints] in TcCanonicalThese Notes cover similar ground but say different things.These Notes cover similar ground but say different things.https://gitlab.haskell.org/ghc/ghc//issues/17841"No skolem info" panic with PolyKinds20201019T09:16:46ZJakob Brünker"No skolem info" panic with PolyKinds## Summary
Making a class with a kindpolymorphic parameter and a single method can lead to a GHC panic stating "No skolem info".
## Steps to reproduce
The following program
```haskell
{# LANGUAGE PolyKinds #}
data Proxy a = Proxy
class Foo (t :: k) where foo :: Proxy (a :: t)
```
results in the error
```
Bug.hs:5:40: error:ghc: panic! (the 'impossible' happened)
(GHC version 8.11.0.20200215:
No skolem info:
[k_a1q3[sk:1]]
Call stack:
CallStack (from HasCallStack):
callStackDoc, called at compiler/utils/Outputable.hs:1187:37 in ghc:Outputable
pprPanic, called at compiler/typecheck/TcErrors.hs:2793:17 in ghc:TcErrors
```
On 8.6.5, it instead emits the error message
```
Bug.hs:5:45: error:
• Expected a type, but ‘t’ has kind ‘k’
• In the kind ‘t’
In the first argument of ‘Proxy’, namely ‘(a :: t)’
In the type signature: foo :: Proxy (a :: t)

5  class Foo (t :: k) where foo :: Proxy (a :: t)

```
I thought at first it might be https://gitlab.haskell.org/ghc/ghc/issues/16245 but for the facts that that issue specifically mentions RankNTypes, and produces an error already on GHC 8.6, which this example doesn't.
## Expected behavior
It should probably emit the same error message it emitted in 8.6.
## Environment
* GHC versions used: 8.8.1, HEAD
* Does *not* happen on 8.6.5
Optional:
* Operating System: linux
* System Architecture: x86_64## Summary
Making a class with a kindpolymorphic parameter and a single method can lead to a GHC panic stating "No skolem info".
## Steps to reproduce
The following program
```haskell
{# LANGUAGE PolyKinds #}
data Proxy a = Proxy
class Foo (t :: k) where foo :: Proxy (a :: t)
```
results in the error
```
Bug.hs:5:40: error:ghc: panic! (the 'impossible' happened)
(GHC version 8.11.0.20200215:
No skolem info:
[k_a1q3[sk:1]]
Call stack:
CallStack (from HasCallStack):
callStackDoc, called at compiler/utils/Outputable.hs:1187:37 in ghc:Outputable
pprPanic, called at compiler/typecheck/TcErrors.hs:2793:17 in ghc:TcErrors
```
On 8.6.5, it instead emits the error message
```
Bug.hs:5:45: error:
• Expected a type, but ‘t’ has kind ‘k’
• In the kind ‘t’
In the first argument of ‘Proxy’, namely ‘(a :: t)’
In the type signature: foo :: Proxy (a :: t)

5  class Foo (t :: k) where foo :: Proxy (a :: t)

```
I thought at first it might be https://gitlab.haskell.org/ghc/ghc/issues/16245 but for the facts that that issue specifically mentions RankNTypes, and produces an error already on GHC 8.6, which this example doesn't.
## Expected behavior
It should probably emit the same error message it emitted in 8.6.
## Environment
* GHC versions used: 8.8.1, HEAD
* Does *not* happen on 8.6.5
Optional:
* Operating System: linux
* System Architecture: x86_648.10.2https://gitlab.haskell.org/ghc/ghc//issues/17873Lazy instantiation is incompatible with implicit parameters20200715T09:06:16ZRichard Eisenbergrae@richarde.devLazy instantiation is incompatible with implicit parametersIn thinking about issues around #17173, I came up with this silliness:
```hs
getx :: (?x :: Bool > Bool) => Bool > Bool
getx = ?x
z3 = (let ?x = not in getx) False
```
GHC's current response is utter garbage:
```
Scratch.hs:52:23: error:
• Couldn't match type ‘?x::Bool > Bool’ with ‘Bool’
Expected type: Bool > Bool > Bool
Actual type: (?x::Bool > Bool) => Bool > Bool
• In the expression: getx
In the expression: let ?x = not in getx
In the expression: (let ?x = not in getx) False

52  z3 = (let ?x = not in getx) False

```
The "couldn't match type" bit is illkinded, and I have no idea why GHC is expecting `Bool > Bool > Bool` here. But the root cause, I believe, is lazy instantiation. Functions are instantiated lazily. So the `let ?x = not in getx` is instantiated lazily. The body of a `let` inherits its instantiation behavior from the outer context. So the `getx` is instantiated lazily. This means that GHC happily infers type `(?x :: Bool > Bool) => Bool > Bool` for `getx`. And then, with no incentive to instantiate, it infers `(let ?x = not in getx) :: (?x :: Bool > Bool) => Bool > Bool`. Now, when we apply such a thing to a term argument, GHC instantiates. But, lo!, there is no longer a `?x :: Bool > Bool` constraint in scope, causing unhappiness.
If we instantiate eagerly, I claim this should all work just fine.
I believe this will be fixed alongside #17173, but given that #17173 is about general improvement rather than bugfixing, I made this outright bug a separate ticket.In thinking about issues around #17173, I came up with this silliness:
```hs
getx :: (?x :: Bool > Bool) => Bool > Bool
getx = ?x
z3 = (let ?x = not in getx) False
```
GHC's current response is utter garbage:
```
Scratch.hs:52:23: error:
• Couldn't match type ‘?x::Bool > Bool’ with ‘Bool’
Expected type: Bool > Bool > Bool
Actual type: (?x::Bool > Bool) => Bool > Bool
• In the expression: getx
In the expression: let ?x = not in getx
In the expression: (let ?x = not in getx) False

52  z3 = (let ?x = not in getx) False

```
The "couldn't match type" bit is illkinded, and I have no idea why GHC is expecting `Bool > Bool > Bool` here. But the root cause, I believe, is lazy instantiation. Functions are instantiated lazily. So the `let ?x = not in getx` is instantiated lazily. The body of a `let` inherits its instantiation behavior from the outer context. So the `getx` is instantiated lazily. This means that GHC happily infers type `(?x :: Bool > Bool) => Bool > Bool` for `getx`. And then, with no incentive to instantiate, it infers `(let ?x = not in getx) :: (?x :: Bool > Bool) => Bool > Bool`. Now, when we apply such a thing to a term argument, GHC instantiates. But, lo!, there is no longer a `?x :: Bool > Bool` constraint in scope, causing unhappiness.
If we instantiate eagerly, I claim this should all work just fine.
I believe this will be fixed alongside #17173, but given that #17173 is about general improvement rather than bugfixing, I made this outright bug a separate ticket.https://gitlab.haskell.org/ghc/ghc//issues/17955mkNewTyConRhs panic when trying to constrain newtype with Coercible20210123T06:44:33ZmatzemathicsmkNewTyConRhs panic when trying to constrain newtype with Coercible## Summary
The following code panics in ghc 8.8.3:
```haskell
{# LANGUAGE FlexibleContexts #}
import Data.Coerce
newtype T = Coercible () T => T ()
```
Error message:
```
[1 of 1] Compiling Main ( abug.hs, abug.o )
ghc: panic! (the 'impossible' happened)
(GHC version 8.8.3 for x86_64unknownlinux):
mkNewTyConRhs
T [Coercible () T, ()]
Call stack:
CallStack (from HasCallStack):
callStackDoc, called at compiler/utils/Outputable.hs:1159:37 in ghc:Outputable
pprPanic, called at compiler/iface/BuildTyCl.hs:65:27 in ghc:BuildTyCl
```
This seems to come from whatever is done to infer Coercible's instances.
Any other Constraint (weather or not using a multi parameter class) gives an error message:
```haskell
{# LANGUAGE FlexibleContexts #}
newtype T = Show T => T ()
```
results in:
```
[1 of 1] Compiling Main ( abug.hs, abug.o )
abug.hs:3:13: error:
* A newtype constructor cannot have a context in its type
T :: Show T => () > T
* In the definition of data constructor `T'
In the newtype declaration for `T'

3  newtype T = Show T => T ()
 ^^^^^^^^^^^^^^
```
## Expected behavior
Should most likely print an error message as in the second example.
## Environment
* GHC version used: 8.8.3## Summary
The following code panics in ghc 8.8.3:
```haskell
{# LANGUAGE FlexibleContexts #}
import Data.Coerce
newtype T = Coercible () T => T ()
```
Error message:
```
[1 of 1] Compiling Main ( abug.hs, abug.o )
ghc: panic! (the 'impossible' happened)
(GHC version 8.8.3 for x86_64unknownlinux):
mkNewTyConRhs
T [Coercible () T, ()]
Call stack:
CallStack (from HasCallStack):
callStackDoc, called at compiler/utils/Outputable.hs:1159:37 in ghc:Outputable
pprPanic, called at compiler/iface/BuildTyCl.hs:65:27 in ghc:BuildTyCl
```
This seems to come from whatever is done to infer Coercible's instances.
Any other Constraint (weather or not using a multi parameter class) gives an error message:
```haskell
{# LANGUAGE FlexibleContexts #}
newtype T = Show T => T ()
```
results in:
```
[1 of 1] Compiling Main ( abug.hs, abug.o )
abug.hs:3:13: error:
* A newtype constructor cannot have a context in its type
T :: Show T => () > T
* In the definition of data constructor `T'
In the newtype declaration for `T'

3  newtype T = Show T => T ()
 ^^^^^^^^^^^^^^
```
## Expected behavior
Should most likely print an error message as in the second example.
## Environment
* GHC version used: 8.8.39.0.1https://gitlab.haskell.org/ghc/ghc//issues/18073Outofdate commentary in Tc.Deriv.Infer20200423T03:49:06ZRichard Eisenbergrae@richarde.devOutofdate commentary in Tc.Deriv.InferCheck out https://gitlab.haskell.org/ghc/ghc//blob/15ab6cd548f284732a7f89d78c2b89b1bfc4ea1d/compiler/GHC/Tc/Deriv/Infer.hs#L805
* The commentary there talks about creating a variable `unsolved`, which does not seem to exist.
* In addition, the partition below creates `bad`, which is just ignored. Maybe this is right  I have not thought about it. But if it is right, it should be documented.
cc @RyanGlScottCheck out https://gitlab.haskell.org/ghc/ghc//blob/15ab6cd548f284732a7f89d78c2b89b1bfc4ea1d/compiler/GHC/Tc/Deriv/Infer.hs#L805
* The commentary there talks about creating a variable `unsolved`, which does not seem to exist.
* In addition, the partition below creates `bad`, which is just ignored. Maybe this is right  I have not thought about it. But if it is right, it should be documented.
cc @RyanGlScotthttps://gitlab.haskell.org/ghc/ghc//issues/18151Etaexpansion of a leftsection20210112T23:04:49ZRichard Eisenbergrae@richarde.devEtaexpansion of a leftsectionIf I say
```hs
x = seq (True `undefined`) ()
```
what should I get when evaluating `x`?
According to my understanding of the Haskell Report, I should get `()`. And according to my understanding of GHC's source code (in `GHC.Tc.Gen.Expr`), I should get `()`. But I get an exception.
Why?
NB: `XPostfixOperators` is off. If it were on, the exception would be expected.
Spun off from https://github.com/ghcproposals/ghcproposals/pull/275#issuecomment624282022If I say
```hs
x = seq (True `undefined`) ()
```
what should I get when evaluating `x`?
According to my understanding of the Haskell Report, I should get `()`. And according to my understanding of GHC's source code (in `GHC.Tc.Gen.Expr`), I should get `()`. But I get an exception.
Why?
NB: `XPostfixOperators` is off. If it were on, the exception would be expected.
Spun off from https://github.com/ghcproposals/ghcproposals/pull/275#issuecomment6242820229.0.1Vladislav ZavialovVladislav Zavialovhttps://gitlab.haskell.org/ghc/ghc//issues/18300UnliftedNewtypesDifficultUnification broken due to simplified subsumption20200703T21:33:23ZBen GamariUnliftedNewtypesDifficultUnification broken due to simplified subsumption`UnliftedNewtypesDifficultUnification` fails due to simplified subsumption patch (!2600) in `DEBUG`enabled compiler.
```
Compile failed (exit code 1) errors were:
ghcstage2: panic! (the 'impossible' happened)
(GHC version 8.11.0.20200603:
ASSERT failed! file compiler/GHC/Core/FamInstEnv.hs, line 651
Please report this as a GHC bug: https://www.haskell.org/ghc/reportabug
*** unexpected failure for UnliftedNewtypesDifficultUnification(normal)
```
I have marked this test as broken in the interest of getting !2600 merged.
As seen in Job [#356282](https://gitlab.haskell.org/ghc/ghc//jobs/356282).`UnliftedNewtypesDifficultUnification` fails due to simplified subsumption patch (!2600) in `DEBUG`enabled compiler.
```
Compile failed (exit code 1) errors were:
ghcstage2: panic! (the 'impossible' happened)
(GHC version 8.11.0.20200603:
ASSERT failed! file compiler/GHC/Core/FamInstEnv.hs, line 651
Please report this as a GHC bug: https://www.haskell.org/ghc/reportabug
*** unexpected failure for UnliftedNewtypesDifficultUnification(normal)
```
I have marked this test as broken in the interest of getting !2600 merged.
As seen in Job [#356282](https://gitlab.haskell.org/ghc/ghc//jobs/356282).9.0.1Simon Peyton JonesSimon Peyton Joneshttps://gitlab.haskell.org/ghc/ghc//issues/18412Monotype check for case branches should not recur through arrows20200720T07:57:36ZRichard Eisenbergrae@richarde.devMonotype check for case branches should not recur through arrowsConsider this module:
```hs
{# LANGUAGE RankNTypes #}
module Bug where
hr :: (forall a. a > a) > ()
hr _ = ()
foo x = case x of () > hr
bar x = case x of True > hr
False > hr
```
On HEAD, `foo` is accepted while `bar` is rejected. (This is not a change from previous behavior.) The reason is that GHC requires `case` branches (when there are more than 1; and when the result of the `case` is being inferred, not checked) to have monotypes, lest it be left with the task of finding the most general supertype of a bunch of polytypes. However, now that we have simplified subsumption, it is draconian to propagate the monotype check past arrows. I thus claim that `bar` should be accepted.Consider this module:
```hs
{# LANGUAGE RankNTypes #}
module Bug where
hr :: (forall a. a > a) > ()
hr _ = ()
foo x = case x of () > hr
bar x = case x of True > hr
False > hr
```
On HEAD, `foo` is accepted while `bar` is rejected. (This is not a change from previous behavior.) The reason is that GHC requires `case` branches (when there are more than 1; and when the result of the `case` is being inferred, not checked) to have monotypes, lest it be left with the task of finding the most general supertype of a bunch of polytypes. However, now that we have simplified subsumption, it is draconian to propagate the monotype check past arrows. I thus claim that `bar` should be accepted.https://gitlab.haskell.org/ghc/ghc//issues/18439Pattern guards can break linearity20210108T16:49:06ZArnaud SpiwackPattern guards can break linearity## Summary
Patterns, in patternguards guards are not checked for linearity. Which let's us write incorrect program with respect to linearity. The linter rightfully rejects those.
## Steps to reproduce
This typechecks but should not:
```
{# LANGUAGE LinearTypes #}
unsafeConsume :: a #> ()
unsafeConsume x  _ < x = ()
```
## Environment
* GHC version used: master 3656dff8259199d0dab2d1a1f1b887c252a9c1a3
## Note
Originally reported by Roman Cheplyaka.## Summary
Patterns, in patternguards guards are not checked for linearity. Which let's us write incorrect program with respect to linearity. The linter rightfully rejects those.
## Steps to reproduce
This typechecks but should not:
```
{# LANGUAGE LinearTypes #}
unsafeConsume :: a #> ()
unsafeConsume x  _ < x = ()
```
## Environment
* GHC version used: master 3656dff8259199d0dab2d1a1f1b887c252a9c1a3
## Note
Originally reported by Roman Cheplyaka.Arnaud SpiwackArnaud Spiwackhttps://gitlab.haskell.org/ghc/ghc//issues/18451Infinite loop during kind inference20200727T08:10:18ZSimon Peyton JonesInfinite loop during kind inferenceThis program
```
{# LANGUAGE RankNTypes #}
{# LANGUAGE TypeInType #}
module Bug where
import Data.Kind
type Const a b = a
data SameKind :: k > k > Type
type T (k :: Const Type a) = forall (b :: k). SameKind a b
```
goes into an infinite loop during kind checking. (Extracted from #16245.)
We have
```
a_agk :: k_au5
k_atM :: Const Type a_agk
k_au5 := k_au7
```
and then we try to unify `k_au7 := k_atM`. That should be an occurscheck error, since `k_atM`'s kind mentions `a_agk`, whose kind mentions `k_au5`, which is equal to `k_au7`.
But `occCheckExpand` (called from `GHC.Tc.Utils.Unify.metaTyVarUpdateOK`) expands the `Const` synonym in `k_atM`'s kind so that it no longer mentions `a_agk`, which allows the update to go ahead.
Wrong! We can't do this `occCheckExpand` business inside kinds! Let's just not do that.This program
```
{# LANGUAGE RankNTypes #}
{# LANGUAGE TypeInType #}
module Bug where
import Data.Kind
type Const a b = a
data SameKind :: k > k > Type
type T (k :: Const Type a) = forall (b :: k). SameKind a b
```
goes into an infinite loop during kind checking. (Extracted from #16245.)
We have
```
a_agk :: k_au5
k_atM :: Const Type a_agk
k_au5 := k_au7
```
and then we try to unify `k_au7 := k_atM`. That should be an occurscheck error, since `k_atM`'s kind mentions `a_agk`, whose kind mentions `k_au5`, which is equal to `k_au7`.
But `occCheckExpand` (called from `GHC.Tc.Utils.Unify.metaTyVarUpdateOK`) expands the `Const` synonym in `k_atM`'s kind so that it no longer mentions `a_agk`, which allows the update to go ahead.
Wrong! We can't do this `occCheckExpand` business inside kinds! Let's just not do that.https://gitlab.haskell.org/ghc/ghc//issues/18481Improve instantiation of datacons20210507T20:05:28ZKrzysztof GogolewskiImprove instantiation of dataconsThis ticket tracks a possible improvement to `return_data_con`.
When typechecking a datacon `T`, do we instantiate its arguments? We'd like to avoid instantiation, because it breaks VTA.
Currently, we instantiate levitypolymorphic constructors. Quoting Note [Linear fields generalization]:
```
A small hitch: if the constructor is levitypolymorphic (unboxed tuples, sums,
certain newtypes with XUnliftedNewtypes) then this strategy produces
\r1 r2 a b (x # p :: a) (y # q :: b) > (# a, b #)
Which has type
forall r1 r2 a b. a #p> b #q> (# a, b #)
Which violates the levitypolymorphism restriction see Note [Levity polymorphism
checking] in DsMonad.
So we really must instantiate r1 and r2 rather than quantify over them. For
simplicity, we just instantiate the entire type, as described in Note
[Instantiating stupid theta]. It breaks visible type application with unboxed
tuples, sums and levitypolymorphic newtypes, but this doesn't appear to be used
anywhere.
A better plan: let's force all representation variable to be *inferred*, so that
they are not subject to visible type applications. Then we can instantiate
inferred argument eagerly.
```
The goal of this ticket is to implement the last paragraph.This ticket tracks a possible improvement to `return_data_con`.
When typechecking a datacon `T`, do we instantiate its arguments? We'd like to avoid instantiation, because it breaks VTA.
Currently, we instantiate levitypolymorphic constructors. Quoting Note [Linear fields generalization]:
```
A small hitch: if the constructor is levitypolymorphic (unboxed tuples, sums,
certain newtypes with XUnliftedNewtypes) then this strategy produces
\r1 r2 a b (x # p :: a) (y # q :: b) > (# a, b #)
Which has type
forall r1 r2 a b. a #p> b #q> (# a, b #)
Which violates the levitypolymorphism restriction see Note [Levity polymorphism
checking] in DsMonad.
So we really must instantiate r1 and r2 rather than quantify over them. For
simplicity, we just instantiate the entire type, as described in Note
[Instantiating stupid theta]. It breaks visible type application with unboxed
tuples, sums and levitypolymorphic newtypes, but this doesn't appear to be used
anywhere.
A better plan: let's force all representation variable to be *inferred*, so that
they are not subject to visible type applications. Then we can instantiate
inferred argument eagerly.
```
The goal of this ticket is to implement the last paragraph.https://gitlab.haskell.org/ghc/ghc//issues/18542Kind error when using partial type signatures20200806T21:34:14Zlennart@augustsson.netKind error when using partial type signatures## Summary
When using a partial type signature I get a kind error, which is surprising.
## Steps to reproduce
Compile the following module. The function bar type checks, whereas baz gets a kind error
```
{# LANGUAGE RankNTypes #}
module Bug where
foo :: (Functor g) =>
(forall aa . Num aa => f aa > g aa) >
f a > g (f a)
foo f x = undefined
bar :: (forall aa . Num aa => f aa > Int > aa) >
f a > Int > f a
bar f = foo f
baz :: (forall aa . Num aa => f aa > Int > aa) >
f a > _ > f a
baz f = foo f
```
## Environment
* GHC version used:
The Glorious Glasgow Haskell Compilation System, version 8.10.1## Summary
When using a partial type signature I get a kind error, which is surprising.
## Steps to reproduce
Compile the following module. The function bar type checks, whereas baz gets a kind error
```
{# LANGUAGE RankNTypes #}
module Bug where
foo :: (Functor g) =>
(forall aa . Num aa => f aa > g aa) >
f a > g (f a)
foo f x = undefined
bar :: (forall aa . Num aa => f aa > Int > aa) >
f a > Int > f a
bar f = foo f
baz :: (forall aa . Num aa => f aa > Int > aa) >
f a > _ > f a
baz f = foo f
```
## Environment
* GHC version used:
The Glorious Glasgow Haskell Compilation System, version 8.10.19.2.1https://gitlab.haskell.org/ghc/ghc//issues/18645Incremental `tcCheckSatisfiability` API20200914T13:16:06ZSebastian GrafIncremental `tcCheckSatisfiability` APIThe patternmatch checker makes use of the function `tcCheckSatisfiability :: Bag EvVar > TcM Bool` (henceforth `tcCS`) offered by the typechecker to solve type constraints. Over the course of a patternmatch checking session, such a `Bag EvVar` is accumulated and incrementally checked after each addition. As #17836 shows in a rather painful way, that scales quadratically, because the typechecker chews through the same type constraints over and over again.
But look at how the patternmatch checker uses `tcCS`:
```hs
  Add some extra type constraints to the 'TyState'; return 'Nothing' if we
 find a contradiction (e.g. @Int ~ Bool@).
tyOracle :: TyState > Bag PredType > DsM (Maybe TyState)
tyOracle (TySt inert) cts
= do { evs < traverse nameTyCt cts
; let new_inert = inert `unionBags` evs
; ... < initTcDsForSolver $ tcCheckSatisfiability new_inert
; ... }
```
The `inert` set is a `Bag EvVar` for which *we already know they are compatible with each other*, as they were checked by `tcCS` in a previous call. Only `cts :: Bag PredType` are unchecked. And as far as the patternmatch checker is concerned, the type of `inert` is completely opaque, so the API to `tcCS` could very well be
```hs
tcCheckSatisfiability :: TcInert > Bag EvVar > TcM (Maybe TcInert)
  Add some extra type constraints to the 'TyState'; return 'Nothing' if we
 find a contradiction (e.g. @Int ~ Bool@).
tyOracle :: TyState > Bag PredType > DsM (Maybe TyState)
tyOracle (TySt inert) cts
= do { evs < traverse nameTyCt cts
; ...mb_new_inert... < initTcDsForSolver $ tcCheckSatisfiability inert evs
; ... }
```
I'm sure there already is something like `TcInert` in the typechecker. Looking at the implementation of `tcCS`, that might be the unused `EvBindMap`, but I'm not sure. Or is it the `InertCans` in `getInertCans`/`setInertCans`? CC @rae, @RyanGlScott, @simonpj
This blocks #17836 and would probably lead to quite a few (possibly rather drastic) metric decreases in other cases.The patternmatch checker makes use of the function `tcCheckSatisfiability :: Bag EvVar > TcM Bool` (henceforth `tcCS`) offered by the typechecker to solve type constraints. Over the course of a patternmatch checking session, such a `Bag EvVar` is accumulated and incrementally checked after each addition. As #17836 shows in a rather painful way, that scales quadratically, because the typechecker chews through the same type constraints over and over again.
But look at how the patternmatch checker uses `tcCS`:
```hs
  Add some extra type constraints to the 'TyState'; return 'Nothing' if we
 find a contradiction (e.g. @Int ~ Bool@).
tyOracle :: TyState > Bag PredType > DsM (Maybe TyState)
tyOracle (TySt inert) cts
= do { evs < traverse nameTyCt cts
; let new_inert = inert `unionBags` evs
; ... < initTcDsForSolver $ tcCheckSatisfiability new_inert
; ... }
```
The `inert` set is a `Bag EvVar` for which *we already know they are compatible with each other*, as they were checked by `tcCS` in a previous call. Only `cts :: Bag PredType` are unchecked. And as far as the patternmatch checker is concerned, the type of `inert` is completely opaque, so the API to `tcCS` could very well be
```hs
tcCheckSatisfiability :: TcInert > Bag EvVar > TcM (Maybe TcInert)
  Add some extra type constraints to the 'TyState'; return 'Nothing' if we
 find a contradiction (e.g. @Int ~ Bool@).
tyOracle :: TyState > Bag PredType > DsM (Maybe TyState)
tyOracle (TySt inert) cts
= do { evs < traverse nameTyCt cts
; ...mb_new_inert... < initTcDsForSolver $ tcCheckSatisfiability inert evs
; ... }
```
I'm sure there already is something like `TcInert` in the typechecker. Looking at the implementation of `tcCS`, that might be the unused `EvBindMap`, but I'm not sure. Or is it the `InertCans` in `getInertCans`/`setInertCans`? CC @rae, @RyanGlScott, @simonpj
This blocks #17836 and would probably lead to quite a few (possibly rather drastic) metric decreases in other cases.https://gitlab.haskell.org/ghc/ghc//issues/18715ThBrackCtxt is unused20200921T21:17:06ZRyan ScottThBrackCtxt is unusedThe [`UserTypeCtxt`](https://gitlab.haskell.org/ghc/ghc//blob/a1f34d37b47826e86343e368a5c00f1a4b1f2bce/compiler/GHC/Tc/Types/Origin.hs#L5792) data type defines a context for TH brackets:
```hs
data UserTypeCtxt
= ...
 ThBrackCtxt  Template Haskell type brackets [t ... ]
 ...
```
However, this does not appear to actually be used anywhere and can be removed relatively easily:
<details>
```diff
diff git a/compiler/GHC/Tc/Gen/HsType.hs b/compiler/GHC/Tc/Gen/HsType.hs
index 3a1ab09c9b..e81a87c3a8 100644
 a/compiler/GHC/Tc/Gen/HsType.hs
+++ b/compiler/GHC/Tc/Gen/HsType.hs
@@ 2831,7 +2831,6 @@ expectedKindInCtxt :: UserTypeCtxt > ContextKind
 Depending on the context, we might accept any kind (for instance, in a TH
 splice), or only certain kinds (like in type signatures).
expectedKindInCtxt (TySynCtxt _) = AnyKind
expectedKindInCtxt ThBrackCtxt = AnyKind
expectedKindInCtxt (GhciCtxt {}) = AnyKind
 The types in a 'default' decl can have varying kinds
 See Note [Extended defaults]" in GHC.Tc.Utils.Env
diff git a/compiler/GHC/Tc/Types/Origin.hs b/compiler/GHC/Tc/Types/Origin.hs
index b2fdefa4cd..cc63f7a5c5 100644
 a/compiler/GHC/Tc/Types/Origin.hs
+++ b/compiler/GHC/Tc/Types/Origin.hs
@@ 92,7 +92,6 @@ data UserTypeCtxt
 True: standalone deriving
 False: vanilla instance declaration
 SpecInstCtxt  SPECIALISE instance pragma
  ThBrackCtxt  Template Haskell type brackets [t ... ]
 GenSigCtxt  Higherrank or impredicative situations
 e.g. (f e) where f has a higherrank type
 We might want to elaborate this
@@ 136,7 +135,6 @@ pprUserTypeCtxt (StandaloneKindSigCtxt n) = text "a standalone kind signature fo
pprUserTypeCtxt TypeAppCtxt = text "a type argument"
pprUserTypeCtxt (ConArgCtxt c) = text "the type of the constructor" <+> quotes (ppr c)
pprUserTypeCtxt (TySynCtxt c) = text "the RHS of the type synonym" <+> quotes (ppr c)
pprUserTypeCtxt ThBrackCtxt = text "a Template Haskell quotation [t...]"
pprUserTypeCtxt PatSigCtxt = text "a pattern type signature"
pprUserTypeCtxt ResSigCtxt = text "a result type signature"
pprUserTypeCtxt (ForSigCtxt n) = text "the foreign declaration for" <+> quotes (ppr n)
diff git a/compiler/GHC/Tc/Validity.hs b/compiler/GHC/Tc/Validity.hs
index fba45562b7..05dcb28643 100644
 a/compiler/GHC/Tc/Validity.hs
+++ b/compiler/GHC/Tc/Validity.hs
@@ 372,7 +372,6 @@ checkValidType ctxt ty
ForSigCtxt _ > rank1
SpecInstCtxt > rank1
 ThBrackCtxt > rank1
GhciCtxt {} > ArbitraryRank
TyVarBndrKindCtxt _ > rank0
@@ 500,7 +499,6 @@ vdqAllowed :: UserTypeCtxt > Bool
vdqAllowed (KindSigCtxt {}) = True
vdqAllowed (StandaloneKindSigCtxt {}) = True
vdqAllowed (TySynCtxt {}) = True
vdqAllowed (ThBrackCtxt {}) = True
vdqAllowed (GhciCtxt {}) = True
vdqAllowed (TyVarBndrKindCtxt {}) = True
vdqAllowed (DataKindCtxt {}) = True
@@ 1333,7 +1331,6 @@ okIPCtxt ResSigCtxt = True
okIPCtxt GenSigCtxt = True
okIPCtxt (ConArgCtxt {}) = True
okIPCtxt (ForSigCtxt {}) = True  ??
okIPCtxt ThBrackCtxt = True
okIPCtxt (GhciCtxt {}) = True
okIPCtxt SigmaCtxt = True
okIPCtxt (DataTyCtxt {}) = True
```
</details>
Is there a good reason to keep this around?The [`UserTypeCtxt`](https://gitlab.haskell.org/ghc/ghc//blob/a1f34d37b47826e86343e368a5c00f1a4b1f2bce/compiler/GHC/Tc/Types/Origin.hs#L5792) data type defines a context for TH brackets:
```hs
data UserTypeCtxt
= ...
 ThBrackCtxt  Template Haskell type brackets [t ... ]
 ...
```
However, this does not appear to actually be used anywhere and can be removed relatively easily:
<details>
```diff
diff git a/compiler/GHC/Tc/Gen/HsType.hs b/compiler/GHC/Tc/Gen/HsType.hs
index 3a1ab09c9b..e81a87c3a8 100644
 a/compiler/GHC/Tc/Gen/HsType.hs
+++ b/compiler/GHC/Tc/Gen/HsType.hs
@@ 2831,7 +2831,6 @@ expectedKindInCtxt :: UserTypeCtxt > ContextKind
 Depending on the context, we might accept any kind (for instance, in a TH
 splice), or only certain kinds (like in type signatures).
expectedKindInCtxt (TySynCtxt _) = AnyKind
expectedKindInCtxt ThBrackCtxt = AnyKind
expectedKindInCtxt (GhciCtxt {}) = AnyKind
 The types in a 'default' decl can have varying kinds
 See Note [Extended defaults]" in GHC.Tc.Utils.Env
diff git a/compiler/GHC/Tc/Types/Origin.hs b/compiler/GHC/Tc/Types/Origin.hs
index b2fdefa4cd..cc63f7a5c5 100644
 a/compiler/GHC/Tc/Types/Origin.hs
+++ b/compiler/GHC/Tc/Types/Origin.hs
@@ 92,7 +92,6 @@ data UserTypeCtxt
 True: standalone deriving
 False: vanilla instance declaration
 SpecInstCtxt  SPECIALISE instance pragma
  ThBrackCtxt  Template Haskell type brackets [t ... ]
 GenSigCtxt  Higherrank or impredicative situations
 e.g. (f e) where f has a higherrank type
 We might want to elaborate this
@@ 136,7 +135,6 @@ pprUserTypeCtxt (StandaloneKindSigCtxt n) = text "a standalone kind signature fo
pprUserTypeCtxt TypeAppCtxt = text "a type argument"
pprUserTypeCtxt (ConArgCtxt c) = text "the type of the constructor" <+> quotes (ppr c)
pprUserTypeCtxt (TySynCtxt c) = text "the RHS of the type synonym" <+> quotes (ppr c)
pprUserTypeCtxt ThBrackCtxt = text "a Template Haskell quotation [t...]"
pprUserTypeCtxt PatSigCtxt = text "a pattern type signature"
pprUserTypeCtxt ResSigCtxt = text "a result type signature"
pprUserTypeCtxt (ForSigCtxt n) = text "the foreign declaration for" <+> quotes (ppr n)
diff git a/compiler/GHC/Tc/Validity.hs b/compiler/GHC/Tc/Validity.hs
index fba45562b7..05dcb28643 100644
 a/compiler/GHC/Tc/Validity.hs
+++ b/compiler/GHC/Tc/Validity.hs
@@ 372,7 +372,6 @@ checkValidType ctxt ty
ForSigCtxt _ > rank1
SpecInstCtxt > rank1
 ThBrackCtxt > rank1
GhciCtxt {} > ArbitraryRank
TyVarBndrKindCtxt _ > rank0
@@ 500,7 +499,6 @@ vdqAllowed :: UserTypeCtxt > Bool
vdqAllowed (KindSigCtxt {}) = True
vdqAllowed (StandaloneKindSigCtxt {}) = True
vdqAllowed (TySynCtxt {}) = True
vdqAllowed (ThBrackCtxt {}) = True
vdqAllowed (GhciCtxt {}) = True
vdqAllowed (TyVarBndrKindCtxt {}) = True
vdqAllowed (DataKindCtxt {}) = True
@@ 1333,7 +1331,6 @@ okIPCtxt ResSigCtxt = True
okIPCtxt GenSigCtxt = True
okIPCtxt (ConArgCtxt {}) = True
okIPCtxt (ForSigCtxt {}) = True  ??
okIPCtxt ThBrackCtxt = True
okIPCtxt (GhciCtxt {}) = True
okIPCtxt SigmaCtxt = True
okIPCtxt (DataTyCtxt {}) = True
```
</details>
Is there a good reason to keep this around?https://gitlab.haskell.org/ghc/ghc//issues/18753Tighten up the treatment of loose types in the solver20200930T16:21:20ZRichard Eisenbergrae@richarde.devTighten up the treatment of loose types in the solver`GHC.Tc.Solver.Monad` includes
```
Note [Use loose types in inert set]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Say we know (Eq (a > c1)) and we need (Eq (a > c2)). One is clearly
solvable from the other. So, we do lookup in the inert set using
loose types, which omits the kindcheck.
We must be careful when using the result of a lookup because it may
not match the requested info exactly!
```
There are several problems.
* We aren't always careful. For example, `lookupInInerts` tries `lookupSolvedDict` and then `lookupInertDict`, both of which use this "loose" lookup. Yet the result of `lookupInInerts` just uses the result, without any special handling to take the fact that the types might not match exactly.
* The Note doesn't actually make sense. The only difference between `Eq (a > c1)` and `Eq (a > c2)` is the coercion. But I sincerely hope we never care about the contents of a coercion. So even if we use evidence of type `Eq (a > c1)` where GHC is expecting `Eq (a > c2)` (assuming `c1` and `c2` have the same type), all will be well.
* What I think the Note is trying to say will never happen. That is, the actual implementation of the inertset lookup tries to match types while ignoring their kinds. (Normal type matching requires that the kind matches also.) So a better example would be something like comparing `Eq (a :: k1)` with `Eq (a :: k2)`. But that's impossible, even with casts: all type families and classes have *closed* kinds, meaning that any variables that appear in the kinds of arguments must themselves be earlier arguments. In other words, if I have welltyped `T blah1 (... :: kind1)` and `T blah2 (... :: kind2)`, then either `kind1` equals `kind2` or `blah1` and `blah2` must differ. We use this logic elsewhere  in particular, in the pure unifier.
Conclusions:
* Using "loose" matching (that is, ignoring kinds) in the solver is the right thing.
* We should update the Note with my argument above.
* No special care needs to be taken when using loose matching in this way. This means we can drop a few redundant equality checks (e.g. in `lookupFlatCache`).
I'm pretty confident about this all, but I'd like a doublecheck before I commit a fix.`GHC.Tc.Solver.Monad` includes
```
Note [Use loose types in inert set]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Say we know (Eq (a > c1)) and we need (Eq (a > c2)). One is clearly
solvable from the other. So, we do lookup in the inert set using
loose types, which omits the kindcheck.
We must be careful when using the result of a lookup because it may
not match the requested info exactly!
```
There are several problems.
* We aren't always careful. For example, `lookupInInerts` tries `lookupSolvedDict` and then `lookupInertDict`, both of which use this "loose" lookup. Yet the result of `lookupInInerts` just uses the result, without any special handling to take the fact that the types might not match exactly.
* The Note doesn't actually make sense. The only difference between `Eq (a > c1)` and `Eq (a > c2)` is the coercion. But I sincerely hope we never care about the contents of a coercion. So even if we use evidence of type `Eq (a > c1)` where GHC is expecting `Eq (a > c2)` (assuming `c1` and `c2` have the same type), all will be well.
* What I think the Note is trying to say will never happen. That is, the actual implementation of the inertset lookup tries to match types while ignoring their kinds. (Normal type matching requires that the kind matches also.) So a better example would be something like comparing `Eq (a :: k1)` with `Eq (a :: k2)`. But that's impossible, even with casts: all type families and classes have *closed* kinds, meaning that any variables that appear in the kinds of arguments must themselves be earlier arguments. In other words, if I have welltyped `T blah1 (... :: kind1)` and `T blah2 (... :: kind2)`, then either `kind1` equals `kind2` or `blah1` and `blah2` must differ. We use this logic elsewhere  in particular, in the pure unifier.
Conclusions:
* Using "loose" matching (that is, ignoring kinds) in the solver is the right thing.
* We should update the Note with my argument above.
* No special care needs to be taken when using loose matching in this way. This means we can drop a few redundant equality checks (e.g. in `lookupFlatCache`).
I'm pretty confident about this all, but I'd like a doublecheck before I commit a fix.https://gitlab.haskell.org/ghc/ghc//issues/18863Visibility mismatch between data declaration and kind signature, accepted!20201031T11:08:25ZIcelandjackVisibility mismatch between data declaration and kind signature, accepted!```haskell
{# Language PolyKinds #}
{# Language RankNTypes #}
{# Language StandaloneKindSignatures #}
import Data.Kind
type ID :: forall i > i > Type
data ID :: forall i > i > Type
```
This compiles on 8.10.0.20191123, if we change the standalone kind signature `forall>` to `forall.` we get an error. Obviously?
```haskell
 • Couldn't match expected kind ‘forall i1 > i1 > *’
 with actual kind ‘i > *’
 • In the data type declaration for ‘ID’
 
 8  data ID :: forall i > i > Type
  ^^^^^^^
type ID :: forall i. i > Type
data ID :: forall i > i > Type
```
But then why does this compile
```haskell
type ID :: forall i > i > Type
data ID :: forall i. i > Type
``````haskell
{# Language PolyKinds #}
{# Language RankNTypes #}
{# Language StandaloneKindSignatures #}
import Data.Kind
type ID :: forall i > i > Type
data ID :: forall i > i > Type
```
This compiles on 8.10.0.20191123, if we change the standalone kind signature `forall>` to `forall.` we get an error. Obviously?
```haskell
 • Couldn't match expected kind ‘forall i1 > i1 > *’
 with actual kind ‘i > *’
 • In the data type declaration for ‘ID’
 
 8  data ID :: forall i > i > Type
  ^^^^^^^
type ID :: forall i. i > Type
data ID :: forall i > i > Type
```
But then why does this compile
```haskell
type ID :: forall i > i > Type
data ID :: forall i. i > Type
```9.2.1https://gitlab.haskell.org/ghc/ghc//issues/18875Occurschecky Givens rewrite once, but not twice20201204T22:10:52ZRichard Eisenbergrae@richarde.devOccurschecky Givens rewrite once, but not twiceGHC remarkably accepts this program:
```hs
type family UnMaybe a where
UnMaybe (Maybe b) = b
class C c where
meth :: c
instance C (Maybe d) where
meth = Nothing
f :: (e ~ Maybe (UnMaybe e)) => e
f = meth
```
This is remarkable because satisfying the `C e` constraint arising from the use of `meth` requires using the `e ~ Maybe (UnMaybe e)` given, despite the fact that it has an occurscheck failure. That is, GHC must rewrite `e` to `Maybe (UnMaybe e)` to solve the class constraint, yet not fall into a look trying to expand `e` further. This works due to the way GHC currently uses flatteningskolems to deal with type family applications. (The program above does not work on the current tip of !4149, which avoids this flattening mechanism.)
However, GHC rejects this program:
```hs
type family G a b where
G (Maybe c) d = d
h :: (e ~ Maybe (G e f)) => e > f
h (Just x) = x
```
Here, `h` has a similar given with an occurscheck failure. In contrast to the first example, though, we need to use the equation *twice* in order to accept this program. Specifically, we have
```
[G] e ~ Maybe (G e f)
[W] e ~ Maybe f
```
Using the Given for rewriting once gives us
```
[W] Maybe (G e f) ~ Maybe f
```
which decomposes to
```
[W] G e f ~ f
```
But now, we must use the given *again* to get
```
[W] G (Maybe (G e f)) f ~ f
```
so that can reduce to
```
[W] f ~ f
```
and be solved.
I think this will be hard to achieve in practice (rewriting twice). Might we need even more rewrites in pathological scenarios? I don't know.
The purpose of this ticket is more to record the incompleteness than to actively agitate for a solution. This did not arise in a real application and would likely be hard to fix.GHC remarkably accepts this program:
```hs
type family UnMaybe a where
UnMaybe (Maybe b) = b
class C c where
meth :: c
instance C (Maybe d) where
meth = Nothing
f :: (e ~ Maybe (UnMaybe e)) => e
f = meth
```
This is remarkable because satisfying the `C e` constraint arising from the use of `meth` requires using the `e ~ Maybe (UnMaybe e)` given, despite the fact that it has an occurscheck failure. That is, GHC must rewrite `e` to `Maybe (UnMaybe e)` to solve the class constraint, yet not fall into a look trying to expand `e` further. This works due to the way GHC currently uses flatteningskolems to deal with type family applications. (The program above does not work on the current tip of !4149, which avoids this flattening mechanism.)
However, GHC rejects this program:
```hs
type family G a b where
G (Maybe c) d = d
h :: (e ~ Maybe (G e f)) => e > f
h (Just x) = x
```
Here, `h` has a similar given with an occurscheck failure. In contrast to the first example, though, we need to use the equation *twice* in order to accept this program. Specifically, we have
```
[G] e ~ Maybe (G e f)
[W] e ~ Maybe f
```
Using the Given for rewriting once gives us
```
[W] Maybe (G e f) ~ Maybe f
```
which decomposes to
```
[W] G e f ~ f
```
But now, we must use the given *again* to get
```
[W] G (Maybe (G e f)) f ~ f
```
so that can reduce to
```
[W] f ~ f
```
and be solved.
I think this will be hard to achieve in practice (rewriting twice). Might we need even more rewrites in pathological scenarios? I don't know.
The purpose of this ticket is more to record the incompleteness than to actively agitate for a solution. This did not arise in a real application and would likely be hard to fix.https://gitlab.haskell.org/ghc/ghc//issues/18891Kind inference for newtypes in GADT syntax is deeply broken20201208T21:03:16ZRichard Eisenbergrae@richarde.devKind inference for newtypes in GADT syntax is deeply brokenHere are some tales of destruction, all with `XUnliftedNewtypes` and `XNoCUSKs`:
```hs
newtype N :: forall k. TYPE k where
MkN :: N > N
```
gives
```
Scratch.hs:34:3: error:
• Expected a type, but ‘N’ has kind ‘*’
• In the definition of data constructor ‘MkN’
In the newtype declaration for ‘N’
```

```hs
type N :: forall k. TYPE k
newtype N :: forall k. TYPE k where
MkN :: N > N
```
gives
```
Scratch.hs:35:3: error:
• A newtype constructor must have a return type of form T a1 ... an
MkN :: N > N
• In the definition of data constructor ‘MkN’
In the newtype declaration for ‘N’
```

```hs
newtype N :: forall k > TYPE k where
MkN :: N m > N m
```
gives
```
Scratch.hs:35:3: error:
• Expected a type, but ‘N m’ has kind ‘TYPE m’
• In the definition of data constructor ‘MkN’
In the newtype declaration for ‘N’
```

```hs
type N :: forall k > TYPE k
newtype N :: forall k > TYPE k where
MkN :: N m > N m
```
succeeds.
I think all these examples should succeed. All but the last cause a DEBUG build of GHC to panic.
I think the problem is that the `res_kind` passed to `kcConArgTys` has the wrong scope: it mentions variables in the type head, but these are utterly distinct from the variables in the constructor type.Here are some tales of destruction, all with `XUnliftedNewtypes` and `XNoCUSKs`:
```hs
newtype N :: forall k. TYPE k where
MkN :: N > N
```
gives
```
Scratch.hs:34:3: error:
• Expected a type, but ‘N’ has kind ‘*’
• In the definition of data constructor ‘MkN’
In the newtype declaration for ‘N’
```

```hs
type N :: forall k. TYPE k
newtype N :: forall k. TYPE k where
MkN :: N > N
```
gives
```
Scratch.hs:35:3: error:
• A newtype constructor must have a return type of form T a1 ... an
MkN :: N > N
• In the definition of data constructor ‘MkN’
In the newtype declaration for ‘N’
```

```hs
newtype N :: forall k > TYPE k where
MkN :: N m > N m
```
gives
```
Scratch.hs:35:3: error:
• Expected a type, but ‘N m’ has kind ‘TYPE m’
• In the definition of data constructor ‘MkN’
In the newtype declaration for ‘N’
```

```hs
type N :: forall k > TYPE k
newtype N :: forall k > TYPE k where
MkN :: N m > N m
```
succeeds.
I think all these examples should succeed. All but the last cause a DEBUG build of GHC to panic.
I think the problem is that the `res_kind` passed to `kcConArgTys` has the wrong scope: it mentions variables in the type head, but these are utterly distinct from the variables in the constructor type.9.2.1https://gitlab.haskell.org/ghc/ghc//issues/18910Orderdependent type inference due to Note [Instance and Given overlap]20210106T03:39:21ZRichard Eisenbergrae@richarde.devOrderdependent type inference due to Note [Instance and Given overlap]With some effort, I have produced
```hs
{# LANGUAGE ScopedTypeVariables, AllowAmbiguousTypes, TypeApplications,
TypeFamilies, PolyKinds, DataKinds, FlexibleInstances,
MultiParamTypeClasses, FlexibleContexts, PartialTypeSignatures #}
module Bug where
import Data.Proxy
class P a
class Q a
class R a b
newtype Tagged (t :: k) a = Tagged a
type family F a
type instance F (Tagged @Bool t a) = [a]
instance P x => Q [x]
instance (x ~ y) => R y [x]
wob :: forall a b. (Q [b], R b a) => a > Int
wob = undefined
it'sABoolNow :: forall (t :: Bool). Int
it'sABoolNow = undefined
class HasBoolKind t
instance k ~ Bool => HasBoolKind (t :: k)
it'sABoolLater :: forall t. HasBoolKind t => Int
it'sABoolLater = undefined
g :: forall t a. Q (F (Tagged t a)) => Proxy t > [a] > _
g _ x = it'sABoolNow @t + wob x
g2 :: forall t a. Q (F (Tagged t a)) => Proxy t > [a] > _
g2 _ x = wob x + it'sABoolNow @t
g3 :: forall t a. Q (F (Tagged t a)) => Proxy t > [a] > _
g3 _ x = it'sABoolLater @t + wob x
g4 :: forall t a. Q (F (Tagged t a)) => Proxy t > [a] > _
g4 _ x = wob x + it'sABoolLater @t
```
All of `g`, `g2`, and `g3` are accepted. `g4` is rejected. Note that `g4` is identical to `g3` except for changing the order of the summands.
What's going on:
Here is an excerpt from `Note [Instance and Given overlap]`:
```
Example, from the OutsideIn(X) paper:
instance P x => Q [x]
instance (x ~ y) => R y [x]
wob :: forall a b. (Q [b], R b a) => a > Int
g :: forall a. Q [a] => [a] > Int
g x = wob x
From 'g' we get the implication constraint:
forall a. Q [a] => (Q [beta], R beta [a])
If we react (Q [beta]) with its toplevel axiom, we end up with a
(P beta), which we have no way of discharging. On the other hand,
if we react R beta [a] with the toplevel we get (beta ~ a), which
is solvable and can help us rewrite (Q [beta]) to (Q [a]) which is
now solvable by the given Q [a].
```
Here is the scenario in the Note, when typechecking the Note's `g`:
```
[G] Q [a]
[W] Q [beta]
[W] R beta [a]
```
When we process the first Wanted, we might be tempted to use the instance, simplifying the Wanted to `P beta`. Doing this leads to failure. What we'd prefer is to recognize that the Given might be helpful later, and just to leave the Wanted asis. Then, processing the `[W] R beta [a]` tells us that `beta ~ a`, and we go home happy.
The scenario in this ticket is rather more complicated. The instances are unchanged, but now we have a type family `F` in the mix. It all looks like
```
t :: kappa
[G] Q (F (Tagged @kappa t a))
[W] Q [beta]
[W] R beta [a]
```
The question is: when processing the first Wanted, should the Given block GHC from using the global instance? (Sidenote: I've used partial type signatures and polykinds here as a sneaky way of getting a metavariable into a Given. The partial type signature stops GHC from kindgeneralizing the type, and thus `t`'s kind remains as `kappa` when processing the body.) If `kappa` is `Bool`, then the Given will eventually match and should block us from using the instance. If `kappa` is not `Bool`, then the Given will not apply. Yet in all of `g`..`g4`, `kappa` turns out to be `Bool`.
In `g`, we have `it'sABoolNow @t`, and the eager unifier sets `kappa := Bool` before the constraint solver gets a crack. The application of `F` reduces and the Given is recognized as relevant, blocking the use of the global instance.
In `g2`, the same happens.
In `g3`, we get a new `[W] HasBoolKind @kappa t`. This gets processed *before* the `Q [beta]` Wanted, and processing this sets `kappa := Bool`, leading the Given to reduce and block the use of the global instance.
In `g4`, however, the new `[W] HasBoolKind @kappa t` comes *after* the others. So we process `Q [beta]` *before* learning about `kappa`. The global instance is used, and we are left stuck with `[W] P a` that cannot be solved.
This all boils down to the `not (isFskTyVar tv)` check in `GHC.Tc.Solver.Monad.mightMatchLater`, which (effectively) says that type family applications in Givens match only themselves, not any arbitrary type. Removing that check fixes this problem. But it introduces another. The following program is accepted today:
```hs
{# LANGUAGE TypeFamilies, FlexibleInstances, FlexibleContexts #}
module Bug2 where
class C a where
meth :: a > ()
instance C Int where
meth _ = ()
type family F a
foo :: C (F a) => a > Int > ()
foo _ n = meth n
```
If we strike that check from `mightMatchLater`, we get
```
• Overlapping instances for C Int arising from a use of ‘meth’
Matching instances:
instance C Int  Defined at CbvOverlap.hs:10:10
There exists a (perhaps superclass) match:
from the context: C (F a)
bound by the type signature for:
foo :: forall a. C (F a) => a > Int > ()
at CbvOverlap.hs:15:132
(The choice depends on the instantiation of ‘’
To pick the first instance above, use IncoherentInstances
when compiling the other instance declarations)
• In the expression: meth n
In an equation for ‘foo’: foo _ n = meth n
```
The (unrelated) `[G] C (F a)` blocks the useful `instance C Int`. Worse, the error message says that the overlap depends on the instantiation of <<empty list>>.
This new problem is not just theoretical. In my !4149 patch, I essentially made this change unintentionally, and GHC's Parser.hs stopped compiling (in stage 2), due to its `DisambECP` shenanigans. It's easy for me to replicate the current behavior, so my branch can continue, but this bug will remain.
I'm not sure what the solution is. If we allow type family applications in Givens to match any potential type, we will unavoidably cause the second bug. So perhaps the best course of action is to let sleeping dogs lie. Yet I was uncomfortable reinstating the old behavior, because it smelled off... and I wanted to understand it better. Thus this ticket.With some effort, I have produced
```hs
{# LANGUAGE ScopedTypeVariables, AllowAmbiguousTypes, TypeApplications,
TypeFamilies, PolyKinds, DataKinds, FlexibleInstances,
MultiParamTypeClasses, FlexibleContexts, PartialTypeSignatures #}
module Bug where
import Data.Proxy
class P a
class Q a
class R a b
newtype Tagged (t :: k) a = Tagged a
type family F a
type instance F (Tagged @Bool t a) = [a]
instance P x => Q [x]
instance (x ~ y) => R y [x]
wob :: forall a b. (Q [b], R b a) => a > Int
wob = undefined
it'sABoolNow :: forall (t :: Bool). Int
it'sABoolNow = undefined
class HasBoolKind t
instance k ~ Bool => HasBoolKind (t :: k)
it'sABoolLater :: forall t. HasBoolKind t => Int
it'sABoolLater = undefined
g :: forall t a. Q (F (Tagged t a)) => Proxy t > [a] > _
g _ x = it'sABoolNow @t + wob x
g2 :: forall t a. Q (F (Tagged t a)) => Proxy t > [a] > _
g2 _ x = wob x + it'sABoolNow @t
g3 :: forall t a. Q (F (Tagged t a)) => Proxy t > [a] > _
g3 _ x = it'sABoolLater @t + wob x
g4 :: forall t a. Q (F (Tagged t a)) => Proxy t > [a] > _
g4 _ x = wob x + it'sABoolLater @t
```
All of `g`, `g2`, and `g3` are accepted. `g4` is rejected. Note that `g4` is identical to `g3` except for changing the order of the summands.
What's going on:
Here is an excerpt from `Note [Instance and Given overlap]`:
```
Example, from the OutsideIn(X) paper:
instance P x => Q [x]
instance (x ~ y) => R y [x]
wob :: forall a b. (Q [b], R b a) => a > Int
g :: forall a. Q [a] => [a] > Int
g x = wob x
From 'g' we get the implication constraint:
forall a. Q [a] => (Q [beta], R beta [a])
If we react (Q [beta]) with its toplevel axiom, we end up with a
(P beta), which we have no way of discharging. On the other hand,
if we react R beta [a] with the toplevel we get (beta ~ a), which
is solvable and can help us rewrite (Q [beta]) to (Q [a]) which is
now solvable by the given Q [a].
```
Here is the scenario in the Note, when typechecking the Note's `g`:
```
[G] Q [a]
[W] Q [beta]
[W] R beta [a]
```
When we process the first Wanted, we might be tempted to use the instance, simplifying the Wanted to `P beta`. Doing this leads to failure. What we'd prefer is to recognize that the Given might be helpful later, and just to leave the Wanted asis. Then, processing the `[W] R beta [a]` tells us that `beta ~ a`, and we go home happy.
The scenario in this ticket is rather more complicated. The instances are unchanged, but now we have a type family `F` in the mix. It all looks like
```
t :: kappa
[G] Q (F (Tagged @kappa t a))
[W] Q [beta]
[W] R beta [a]
```
The question is: when processing the first Wanted, should the Given block GHC from using the global instance? (Sidenote: I've used partial type signatures and polykinds here as a sneaky way of getting a metavariable into a Given. The partial type signature stops GHC from kindgeneralizing the type, and thus `t`'s kind remains as `kappa` when processing the body.) If `kappa` is `Bool`, then the Given will eventually match and should block us from using the instance. If `kappa` is not `Bool`, then the Given will not apply. Yet in all of `g`..`g4`, `kappa` turns out to be `Bool`.
In `g`, we have `it'sABoolNow @t`, and the eager unifier sets `kappa := Bool` before the constraint solver gets a crack. The application of `F` reduces and the Given is recognized as relevant, blocking the use of the global instance.
In `g2`, the same happens.
In `g3`, we get a new `[W] HasBoolKind @kappa t`. This gets processed *before* the `Q [beta]` Wanted, and processing this sets `kappa := Bool`, leading the Given to reduce and block the use of the global instance.
In `g4`, however, the new `[W] HasBoolKind @kappa t` comes *after* the others. So we process `Q [beta]` *before* learning about `kappa`. The global instance is used, and we are left stuck with `[W] P a` that cannot be solved.
This all boils down to the `not (isFskTyVar tv)` check in `GHC.Tc.Solver.Monad.mightMatchLater`, which (effectively) says that type family applications in Givens match only themselves, not any arbitrary type. Removing that check fixes this problem. But it introduces another. The following program is accepted today:
```hs
{# LANGUAGE TypeFamilies, FlexibleInstances, FlexibleContexts #}
module Bug2 where
class C a where
meth :: a > ()
instance C Int where
meth _ = ()
type family F a
foo :: C (F a) => a > Int > ()
foo _ n = meth n
```
If we strike that check from `mightMatchLater`, we get
```
• Overlapping instances for C Int arising from a use of ‘meth’
Matching instances:
instance C Int  Defined at CbvOverlap.hs:10:10
There exists a (perhaps superclass) match:
from the context: C (F a)
bound by the type signature for:
foo :: forall a. C (F a) => a > Int > ()
at CbvOverlap.hs:15:132
(The choice depends on the instantiation of ‘’
To pick the first instance above, use IncoherentInstances
when compiling the other instance declarations)
• In the expression: meth n
In an equation for ‘foo’: foo _ n = meth n
```
The (unrelated) `[G] C (F a)` blocks the useful `instance C Int`. Worse, the error message says that the overlap depends on the instantiation of <<empty list>>.
This new problem is not just theoretical. In my !4149 patch, I essentially made this change unintentionally, and GHC's Parser.hs stopped compiling (in stage 2), due to its `DisambECP` shenanigans. It's easy for me to replicate the current behavior, so my branch can continue, but this bug will remain.
I'm not sure what the solution is. If we allow type family applications in Givens to match any potential type, we will unavoidably cause the second bug. So perhaps the best course of action is to let sleeping dogs lie. Yet I was uncomfortable reinstating the old behavior, because it smelled off... and I wanted to understand it better. Thus this ticket.https://gitlab.haskell.org/ghc/ghc//issues/18920ghc8.8 does not infer kind20201109T14:13:59Zjwaldmannghc8.8 does not infer kindRejected by ghc8.8.4 with
```
should.hs:27:12: error:
• Expected kind ‘* > *’, but ‘solver’ has kind ‘*’
• In the first argument of ‘Solver’, namely ‘solver’
In the type ‘(Solver solver, Queue q, Transformer t) =>
Int > q > t > EvalState t > solver (Int, [a])’
In the type declaration for ‘ContinueSig’
```
but accepted by 8.6.5, 8.10.2. 9.0.1alpha1.
```
{# LANGUAGE TypeFamilies #}
{# LANGUAGE FlexibleContexts #}
{# LANGUAGE Rank2Types #}
{# LANGUAGE MultiParamTypeClasses #}
{# LANGUAGE GADTs #}
class Monad solver => Solver solver where
type Constraint solver :: *
type Label solver :: *
class Queue q
data Tree s a where
NewVar :: Term s t => (t > Tree s a) > Tree s a
class Solver solver => Term solver term
class Transformer t where
type EvalState t :: *
type TreeState t :: *
type ForSolver t :: (* > *)
type ForResult t :: *
nextT :: SearchSig (ForSolver t) q t (ForResult t)
returnT :: ContinueSig solver q t (ForResult t)
type ContinueSig solver q t a =
( Solver solver, Queue q, Transformer t )
=> Int > q > t > EvalState t
> solver (Int, [a])
type SearchSig solver q t a =
(Solver solver, Queue q, Transformer t )
=> Int > Tree solver a > q > t > EvalState t > TreeState t
> solver (Int,[a])
```
8.8 accepts this after introducing this:
```
type ContinueSig (solver :: * > *) q t a =
...
```Rejected by ghc8.8.4 with
```
should.hs:27:12: error:
• Expected kind ‘* > *’, but ‘solver’ has kind ‘*’
• In the first argument of ‘Solver’, namely ‘solver’
In the type ‘(Solver solver, Queue q, Transformer t) =>
Int > q > t > EvalState t > solver (Int, [a])’
In the type declaration for ‘ContinueSig’
```
but accepted by 8.6.5, 8.10.2. 9.0.1alpha1.
```
{# LANGUAGE TypeFamilies #}
{# LANGUAGE FlexibleContexts #}
{# LANGUAGE Rank2Types #}
{# LANGUAGE MultiParamTypeClasses #}
{# LANGUAGE GADTs #}
class Monad solver => Solver solver where
type Constraint solver :: *
type Label solver :: *
class Queue q
data Tree s a where
NewVar :: Term s t => (t > Tree s a) > Tree s a
class Solver solver => Term solver term
class Transformer t where
type EvalState t :: *
type TreeState t :: *
type ForSolver t :: (* > *)
type ForResult t :: *
nextT :: SearchSig (ForSolver t) q t (ForResult t)
returnT :: ContinueSig solver q t (ForResult t)
type ContinueSig solver q t a =
( Solver solver, Queue q, Transformer t )
=> Int > q > t > EvalState t
> solver (Int, [a])
type SearchSig solver q t a =
(Solver solver, Queue q, Transformer t )
=> Int > Tree solver a > q > t > EvalState t > TreeState t
> solver (Int,[a])
```
8.8 accepts this after introducing this:
```
type ContinueSig (solver :: * > *) q t a =
...
```8.10.1https://gitlab.haskell.org/ghc/ghc//issues/18929Investigate touchable metavariables in Givens20210102T14:14:41ZRichard Eisenbergrae@richarde.devInvestigate touchable metavariables in Givens@simonpj believes it would be disastrous to ever have a touchable metavariable in a Given. I'm not quite as sure what the disaster would be, but I admit such a situation is suspect. But we can concoct such a thing:
```hs
{# LANGUAGE PolyKinds, PartialTypeSignatures #}
module Bug where
import Data.Proxy
class C a where
meth :: Proxy a > ()
f :: C a => Proxy a > _
f p = meth p
```
The partial signature for `f` is not kindgeneralized (the fact that it is partial means that we might want the definition of `f` to inform the kind of `a`) and thus the kind of `a` remains as a metavariable `kappa`. In the body of `f`, we have `[G] C kappa a`. We can see this in this snippet of `ddumptctrace` (with `fprintexplicitkinds` enabled):
```
tclevel = 1
work item = [WD] $dC_aoV {0}:: C @{k_aoT[tau:1]}
a_aoU[tau:1] (CNonCanonical)
inerts = {Dictionaries = [G] $dC_aoX {0}:: C @{k_aoT[tau:1]}
a_aoJ[tyv:1] (CDictCan)
```
The variable `k_aoT[tau:1]` is touchable and is not yet filled in. (It ends up being skolemised and quantified over, quite correctly.)
This ticket is to determine whether this situation is pernicious, and, if it is, figure out a way to rule it out.@simonpj believes it would be disastrous to ever have a touchable metavariable in a Given. I'm not quite as sure what the disaster would be, but I admit such a situation is suspect. But we can concoct such a thing:
```hs
{# LANGUAGE PolyKinds, PartialTypeSignatures #}
module Bug where
import Data.Proxy
class C a where
meth :: Proxy a > ()
f :: C a => Proxy a > _
f p = meth p
```
The partial signature for `f` is not kindgeneralized (the fact that it is partial means that we might want the definition of `f` to inform the kind of `a`) and thus the kind of `a` remains as a metavariable `kappa`. In the body of `f`, we have `[G] C kappa a`. We can see this in this snippet of `ddumptctrace` (with `fprintexplicitkinds` enabled):
```
tclevel = 1
work item = [WD] $dC_aoV {0}:: C @{k_aoT[tau:1]}
a_aoU[tau:1] (CNonCanonical)
inerts = {Dictionaries = [G] $dC_aoX {0}:: C @{k_aoT[tau:1]}
a_aoJ[tyv:1] (CDictCan)
```
The variable `k_aoT[tau:1]` is touchable and is not yet filled in. (It ends up being skolemised and quantified over, quite correctly.)
This ticket is to determine whether this situation is pernicious, and, if it is, figure out a way to rule it out.https://gitlab.haskell.org/ghc/ghc//issues/18987Quick Look does not zonk return types20201221T11:00:00ZRichard Eisenbergrae@richarde.devQuick Look does not zonk return typesTest case `impredicative/T17332`:
```hs
data Dict c where
MkDict :: c => Dict c
aux :: Dict (forall a. a)
aux = MkDict
```
The constraint `c` ends up in the solver as an `IrredPred`, which reveals the polytype `forall a. a`. But zonking to reveal a polytype should never happen outside of Quick Look, as `Note [Quick Look]` in GHC.Tc.Gen.App tells us.
A quick look didn't reveal exactly where to put the zonk, and I don't want to add yet another wrinkle to !4149. But when this bug is fixed, the `ForAllPred` case in `canIrred` should never happen.Test case `impredicative/T17332`:
```hs
data Dict c where
MkDict :: c => Dict c
aux :: Dict (forall a. a)
aux = MkDict
```
The constraint `c` ends up in the solver as an `IrredPred`, which reveals the polytype `forall a. a`. But zonking to reveal a polytype should never happen outside of Quick Look, as `Note [Quick Look]` in GHC.Tc.Gen.App tells us.
A quick look didn't reveal exactly where to put the zonk, and I don't want to add yet another wrinkle to !4149. But when this bug is fixed, the `ForAllPred` case in `canIrred` should never happen.https://gitlab.haskell.org/ghc/ghc//issues/19042Regression: HEAD incurs a reduction stack overflow on program involving type ...20210414T14:55:51ZRyan ScottRegression: HEAD incurs a reduction stack overflow on program involving type equality_Originally observed in a `head.hackage` build [here](https://gitlab.haskell.org/ghc/head.hackage//jobs/519572#L7936)._
The following code, minimized from the `plots0.1.1.2` library, fails to typecheck on GHC HEAD (I tried using commit 62ed6957463a9c0f711ea698d7ed4371e00fb122) but does typecheck with GHC 8.10.2 and 9.0.1alpha1:
```hs
{# LANGUAGE GADTs #}
{# LANGUAGE ScopedTypeVariables #}
{# LANGUAGE TypeFamilies #}
{# LANGUAGE TypeOperators #}
module Plots.Types where
import Data.Functor
import Data.Typeable
type family N a
data StyledPlot n where
StyledPlot :: Typeable p => p > StyledPlot (N p)
styledPlot :: forall p f.
(Typeable p, Applicative f)
=> (p > f p)
> StyledPlot (N p) > f (StyledPlot (N p))
styledPlot f s@(StyledPlot p) =
case eq p of
Just Refl > f p <&> \p' > StyledPlot p'
Nothing > pure s
where eq :: Typeable a => a > Maybe (a :~: p)
eq _ = eqT
```
On HEAD, this produces the following error:
```
$ ~/Software/ghc2/inplace/bin/ghcstage2 Bug.hs
[1 of 1] Compiling Plots.Types ( Bug.hs, Bug.o )
Bug.hs:21:33: error:
• Reduction stack overflow; size = 201
When simplifying the following type: N p1
Use freductiondepth=0 to disable this check
(any upper bound you could choose might fail unpredictably with
minor updates to GHC, so disabling the check is recommended if
you're sure that type checking should terminate)
• In the expression: StyledPlot p'
In the second argument of ‘(<&>)’, namely ‘\ p' > StyledPlot p'’
In the expression: f p <&> \ p' > StyledPlot p'

21  Just Refl > f p <&> \p' > StyledPlot p'
 ^^^^^^^^^^^^^
```_Originally observed in a `head.hackage` build [here](https://gitlab.haskell.org/ghc/head.hackage//jobs/519572#L7936)._
The following code, minimized from the `plots0.1.1.2` library, fails to typecheck on GHC HEAD (I tried using commit 62ed6957463a9c0f711ea698d7ed4371e00fb122) but does typecheck with GHC 8.10.2 and 9.0.1alpha1:
```hs
{# LANGUAGE GADTs #}
{# LANGUAGE ScopedTypeVariables #}
{# LANGUAGE TypeFamilies #}
{# LANGUAGE TypeOperators #}
module Plots.Types where
import Data.Functor
import Data.Typeable
type family N a
data StyledPlot n where
StyledPlot :: Typeable p => p > StyledPlot (N p)
styledPlot :: forall p f.
(Typeable p, Applicative f)
=> (p > f p)
> StyledPlot (N p) > f (StyledPlot (N p))
styledPlot f s@(StyledPlot p) =
case eq p of
Just Refl > f p <&> \p' > StyledPlot p'
Nothing > pure s
where eq :: Typeable a => a > Maybe (a :~: p)
eq _ = eqT
```
On HEAD, this produces the following error:
```
$ ~/Software/ghc2/inplace/bin/ghcstage2 Bug.hs
[1 of 1] Compiling Plots.Types ( Bug.hs, Bug.o )
Bug.hs:21:33: error:
• Reduction stack overflow; size = 201
When simplifying the following type: N p1
Use freductiondepth=0 to disable this check
(any upper bound you could choose might fail unpredictably with
minor updates to GHC, so disabling the check is recommended if
you're sure that type checking should terminate)
• In the expression: StyledPlot p'
In the second argument of ‘(<&>)’, namely ‘\ p' > StyledPlot p'’
In the expression: f p <&> \ p' > StyledPlot p'

21  Just Refl > f p <&> \p' > StyledPlot p'
 ^^^^^^^^^^^^^
```9.2.1https://gitlab.haskell.org/ghc/ghc//issues/19044Regression: HEAD requires FlexibleContexts because of inferred, redundant con...20201219T14:16:12ZRyan ScottRegression: HEAD requires FlexibleContexts because of inferred, redundant constraint_Originally observed in a `head.hackage` build [here](https://gitlab.haskell.org/ghc/head.hackage//jobs/519572#L7287)._
The following code, minimized from the `pandoc2.11.2` library, fails to typecheck on GHC HEAD (I tried using commit 62ed6957463a9c0f711ea698d7ed4371e00fb122) but does typecheck with GHC 8.10.2 and 9.0.1alpha1:
```hs
{# LANGUAGE FlexibleInstances #}
{# LANGUAGE MultiParamTypeClasses #}
module Bug where
class C a b where
m :: a > b
instance C a a where
m = id
instance C a (Maybe a) where
m _ = Nothing
f :: a > Maybe a
f = g
where
g x = h (m x) x
h :: Maybe a > a > Maybe a
h = const
```
On HEAD, this produces the following error:
```
$ ~/Software/ghc9.1.0.20201208/bin/ghc Bug.hs
[1 of 1] Compiling Bug ( Bug.hs, Bug.o )
Bug.hs:17:5: error:
• Non typevariable argument in the constraint: C a1 (Maybe a1)
(Use FlexibleContexts to permit this)
• When checking the inferred type
g :: forall {a}. C a (Maybe a) => a > Maybe a
In an equation for ‘f’:
f = g
where
g x = h (m x) x

17  g x = h (m x) x
 ^^^^^^^^^^^^^^^
```
Previous versions of GHC would accept this program because the inferred type of `g` was `forall {a}. a > Maybe a`, not `g :: forall {a}. C a (Maybe a) => a > Maybe a`. The presence of this extra `C a (Maybe a)` constraint (which seems redundant?) is suspicious, so I opted to open an issue about it._Originally observed in a `head.hackage` build [here](https://gitlab.haskell.org/ghc/head.hackage//jobs/519572#L7287)._
The following code, minimized from the `pandoc2.11.2` library, fails to typecheck on GHC HEAD (I tried using commit 62ed6957463a9c0f711ea698d7ed4371e00fb122) but does typecheck with GHC 8.10.2 and 9.0.1alpha1:
```hs
{# LANGUAGE FlexibleInstances #}
{# LANGUAGE MultiParamTypeClasses #}
module Bug where
class C a b where
m :: a > b
instance C a a where
m = id
instance C a (Maybe a) where
m _ = Nothing
f :: a > Maybe a
f = g
where
g x = h (m x) x
h :: Maybe a > a > Maybe a
h = const
```
On HEAD, this produces the following error:
```
$ ~/Software/ghc9.1.0.20201208/bin/ghc Bug.hs
[1 of 1] Compiling Bug ( Bug.hs, Bug.o )
Bug.hs:17:5: error:
• Non typevariable argument in the constraint: C a1 (Maybe a1)
(Use FlexibleContexts to permit this)
• When checking the inferred type
g :: forall {a}. C a (Maybe a) => a > Maybe a
In an equation for ‘f’:
f = g
where
g x = h (m x) x

17  g x = h (m x) x
 ^^^^^^^^^^^^^^^
```
Previous versions of GHC would accept this program because the inferred type of `g` was `forall {a}. a > Maybe a`, not `g :: forall {a}. C a (Maybe a) => a > Maybe a`. The presence of this extra `C a (Maybe a)` constraint (which seems redundant?) is suspicious, so I opted to open an issue about it.9.2.1https://gitlab.haskell.org/ghc/ghc//issues/19106Partial type signature variable confuses instance solving20210125T22:40:41ZRichard Eisenbergrae@richarde.devPartial type signature variable confuses instance solvingWhen I say
```hs
{# LANGUAGE TypeFamilies, GADTs #}
module Bug where
f :: (a ~ [b]) => T a > _ > String
f (MkT x) _ = show x
data T a where
MkT :: G a => a > T a
type family G a where
G [b] = Show b
```
I get
```
Bug.hs:6:1: error:
• Could not deduce (Show b)
from the context: a ~ [b]
bound by the inferred type for ‘f’:
forall a b {w}. (a ~ [b]) => T a > w > String
at Bug.hs:6:120
• When checking that the inferred type
f :: forall {a} {b} {w}. (a ~ [b], Show [b]) => T a > w > String
is as general as its (partial) signature
f :: forall a b {w}. (a ~ [b]) => T a > w > String
```
We end up with
```
[G] Show b[tyv:1]
[W] Show [b[tyv:1]]
```
The check in `matchableGivens` considers `b` a metavariable. This isn't entirely wrong, but `b` is a `TyVarTv`, and should not be considered unifiable in `matchableGivens`. The solution is very easy: just change `matchableGivens` to treat `TyVarTv`s like skolems.When I say
```hs
{# LANGUAGE TypeFamilies, GADTs #}
module Bug where
f :: (a ~ [b]) => T a > _ > String
f (MkT x) _ = show x
data T a where
MkT :: G a => a > T a
type family G a where
G [b] = Show b
```
I get
```
Bug.hs:6:1: error:
• Could not deduce (Show b)
from the context: a ~ [b]
bound by the inferred type for ‘f’:
forall a b {w}. (a ~ [b]) => T a > w > String
at Bug.hs:6:120
• When checking that the inferred type
f :: forall {a} {b} {w}. (a ~ [b], Show [b]) => T a > w > String
is as general as its (partial) signature
f :: forall a b {w}. (a ~ [b]) => T a > w > String
```
We end up with
```
[G] Show b[tyv:1]
[W] Show [b[tyv:1]]
```
The check in `matchableGivens` considers `b` a metavariable. This isn't entirely wrong, but `b` is a `TyVarTv`, and should not be considered unifiable in `matchableGivens`. The solution is very easy: just change `matchableGivens` to treat `TyVarTv`s like skolems.Richard Eisenbergrae@richarde.devRichard Eisenbergrae@richarde.devhttps://gitlab.haskell.org/ghc/ghc//issues/19107GADT pattern match defeats instance solving20210125T22:41:18ZRichard Eisenbergrae@richarde.devGADT pattern match defeats instance solvingWhen I say
```hs
{# LANGUAGE GADTs #}
 NB: NO FlexibleContexts
module Bug where
data T a where
MkT :: Show a => [a] > T a
f (MkT x) = show x
```
GHC says
```
Bug.hs:8:1: error:
• Non typevariable argument in the constraint: Show [a]
(Use FlexibleContexts to permit this)
• When checking the inferred type
f :: forall {a}. Show [a] => T a > String
```
The problem is that GHC wants to infer `f :: Show [a] => T a > String`. Yet the correct type is `f :: Show a => T a > String`, with the simplified `Show a` constraint.
The reason this happens is that the solver ends up in this scenario:
```
at level 2
[G] Show alpha[tau:1]
[W] Show [alpha[tau:1]]
```
Before committing to the toplevel `Show a => Show [a]` instance, GHC checks whether any Givens might fire later. It worries `Show alpha` might apply later. But this would be impossible unless `alpha` becomes an infinitely nested list. There is already logic in `lookupInstEnv'` to usefully ignore such absurdities in instance lookup (see `Note [Infinitary substitution in lookup]` in GHC.Core.InstEnv), and we should extend this logic to `matchableGivens`.When I say
```hs
{# LANGUAGE GADTs #}
 NB: NO FlexibleContexts
module Bug where
data T a where
MkT :: Show a => [a] > T a
f (MkT x) = show x
```
GHC says
```
Bug.hs:8:1: error:
• Non typevariable argument in the constraint: Show [a]
(Use FlexibleContexts to permit this)
• When checking the inferred type
f :: forall {a}. Show [a] => T a > String
```
The problem is that GHC wants to infer `f :: Show [a] => T a > String`. Yet the correct type is `f :: Show a => T a > String`, with the simplified `Show a` constraint.
The reason this happens is that the solver ends up in this scenario:
```
at level 2
[G] Show alpha[tau:1]
[W] Show [alpha[tau:1]]
```
Before committing to the toplevel `Show a => Show [a]` instance, GHC checks whether any Givens might fire later. It worries `Show alpha` might apply later. But this would be impossible unless `alpha` becomes an infinitely nested list. There is already logic in `lookupInstEnv'` to usefully ignore such absurdities in instance lookup (see `Note [Infinitary substitution in lookup]` in GHC.Core.InstEnv), and we should extend this logic to `matchableGivens`.Richard Eisenbergrae@richarde.devRichard Eisenbergrae@richarde.devhttps://gitlab.haskell.org/ghc/ghc//issues/19140panic: No skolem info when trying to use variable with polymorphic kind as Ty...20201231T13:44:07ZJakob Brünkerpanic: No skolem info when trying to use variable with polymorphic kind as Type/Constraint## Summary
In a quantified constraint in the context for an instance declaration, when trying to use a type variable with a polymorphic kind as either a `Type` or a `Constraint`, ghc will panic.
## Steps to reproduce
Each of the following three instances trigger the error
```haskell
{# LANGUAGE ExplicitForAll , PolyKinds #}
instance (forall (a :: k) . a) => Show b
instance (forall (a :: k) . Show a) => Show b
instance (forall (a :: k) . a > a) => Show b
```
Error:
```
ghc: panic! (the 'impossible' happened)
(GHC version 9.0.0.20201227:
No skolem info:
[k_aEZ[sk:1]]
Call stack:
CallStack (from HasCallStack):
callStackDoc, called at compiler/GHC/Utils/Outputable.hs:1230:37 in ghc:GHC.Utils.Outputable
pprPanic, called at compiler/GHC/Tc/Errors.hs:2810:17 in ghc:GHC.Tc.Errors
```
## Expected behavior
8.10 has the expected behavior: show the following type error
```
Bug.hs:3:29: error:
• Expected a constraint, but ‘a’ has kind ‘k’
• In the instance declaration for ‘Show b’

3  instance (forall (a :: k) . a) => Show b
 ^
Bug.hs:4:34: error:
• Expected a type, but ‘a’ has kind ‘k’
• In the first argument of ‘Show’, namely ‘a’
In the instance declaration for ‘Show b’

4  instance (forall (a :: k) . Show a) => Show b
 ^
Bug.hs:5:29: error:
• Expected a constraint, but ‘a > a’ has kind ‘*’
• In the instance declaration for ‘Show b’

5  instance (forall (a :: k) . a > a) => Show b
 ^^^^^^
Failed, no modules loaded.
```
## Environment
* GHC version used: 9.0.0.20201227
Optional:
* Operating System: Ubuntu inside WSL2 inside Windows 10
* System Architecture: x86_64## Summary
In a quantified constraint in the context for an instance declaration, when trying to use a type variable with a polymorphic kind as either a `Type` or a `Constraint`, ghc will panic.
## Steps to reproduce
Each of the following three instances trigger the error
```haskell
{# LANGUAGE ExplicitForAll , PolyKinds #}
instance (forall (a :: k) . a) => Show b
instance (forall (a :: k) . Show a) => Show b
instance (forall (a :: k) . a > a) => Show b
```
Error:
```
ghc: panic! (the 'impossible' happened)
(GHC version 9.0.0.20201227:
No skolem info:
[k_aEZ[sk:1]]
Call stack:
CallStack (from HasCallStack):
callStackDoc, called at compiler/GHC/Utils/Outputable.hs:1230:37 in ghc:GHC.Utils.Outputable
pprPanic, called at compiler/GHC/Tc/Errors.hs:2810:17 in ghc:GHC.Tc.Errors
```
## Expected behavior
8.10 has the expected behavior: show the following type error
```
Bug.hs:3:29: error:
• Expected a constraint, but ‘a’ has kind ‘k’
• In the instance declaration for ‘Show b’

3  instance (forall (a :: k) . a) => Show b
 ^
Bug.hs:4:34: error:
• Expected a type, but ‘a’ has kind ‘k’
• In the first argument of ‘Show’, namely ‘a’
In the instance declaration for ‘Show b’

4  instance (forall (a :: k) . Show a) => Show b
 ^
Bug.hs:5:29: error:
• Expected a constraint, but ‘a > a’ has kind ‘*’
• In the instance declaration for ‘Show b’

5  instance (forall (a :: k) . a > a) => Show b
 ^^^^^^
Failed, no modules loaded.
```
## Environment
* GHC version used: 9.0.0.20201227
Optional:
* Operating System: Ubuntu inside WSL2 inside Windows 10
* System Architecture: x86_649.2.1https://gitlab.haskell.org/ghc/ghc//issues/19142panic lookup_final_id with fdefertypeerrors and kind error in instance def...20210122T21:09:33ZJakob Brünkerpanic lookup_final_id with fdefertypeerrors and kind error in instance definition## Summary
This file
```haskell
{# OPTIONS_GHC fdefertypeerrors #}
{# LANGUAGE ExplicitForAll
, TypeApplications
, KindSignatures
, FlexibleInstances
#}
foo :: forall (f :: * > *) . String
foo = ""
instance Show a where
show _ = foo @Int
```
produces the following error:
```
Bug.hs:12:17: warning: [Wdeferredtypeerrors]
• Expected kind ‘* > *’, but ‘Int’ has kind ‘*’
• In the type ‘Int’
In the expression: foo @Int
In an equation for ‘show’: show _ = foo @Int

12  show _ = foo @Int
 ^^^
ghc: panic! (the 'impossible' happened)
(GHC version 9.0.0.20201227:
lookup_final_id
$fShowa
Call stack:
CallStack (from HasCallStack):
callStackDoc, called at compiler/GHC/Utils/Outputable.hs:1230:37 in ghc:GHC.Utils.Outputable
pprPanic, called at compiler/GHC/Iface/Tidy.hs:200:12 in ghc:GHC.Iface.Tidy
```
Without `fdefertypeerrors`, only the kind error would be shown, not the panic.
## Expected behavior
GHC shouldn't panic
## Environment
* GHC version used: 9.0.0.20201227 as well as 8.10.2
Optional:
* Operating System: Ubuntu inside WSL2 inside Windows 10
* System Architecture: x86_64## Summary
This file
```haskell
{# OPTIONS_GHC fdefertypeerrors #}
{# LANGUAGE ExplicitForAll
, TypeApplications
, KindSignatures
, FlexibleInstances
#}
foo :: forall (f :: * > *) . String
foo = ""
instance Show a where
show _ = foo @Int
```
produces the following error:
```
Bug.hs:12:17: warning: [Wdeferredtypeerrors]
• Expected kind ‘* > *’, but ‘Int’ has kind ‘*’
• In the type ‘Int’
In the expression: foo @Int
In an equation for ‘show’: show _ = foo @Int

12  show _ = foo @Int
 ^^^
ghc: panic! (the 'impossible' happened)
(GHC version 9.0.0.20201227:
lookup_final_id
$fShowa
Call stack:
CallStack (from HasCallStack):
callStackDoc, called at compiler/GHC/Utils/Outputable.hs:1230:37 in ghc:GHC.Utils.Outputable
pprPanic, called at compiler/GHC/Iface/Tidy.hs:200:12 in ghc:GHC.Iface.Tidy
```
Without `fdefertypeerrors`, only the kind error would be shown, not the panic.
## Expected behavior
GHC shouldn't panic
## Environment
* GHC version used: 9.0.0.20201227 as well as 8.10.2
Optional:
* Operating System: Ubuntu inside WSL2 inside Windows 10
* System Architecture: x86_64https://gitlab.haskell.org/ghc/ghc//issues/19154GHC 9.0 no longer typechecks a program involving overloaded labels and type a...20210222T09:40:05ZsheafGHC 9.0 no longer typechecks a program involving overloaded labels and type applicationsIn the program that follows, I specify the type of a label by using a visible type application.
```haskell
{# LANGUAGE DataKinds #}
{# LANGUAGE FlexibleInstances #}
{# LANGUAGE FunctionalDependencies #}
{# LANGUAGE OverloadedLabels #}
{# LANGUAGE PolyKinds #}
{# LANGUAGE RebindableSyntax #}
{# LANGUAGE ScopedTypeVariables #}
{# LANGUAGE TypeApplications #}
module Labels where
 base
import Prelude
import Data.Kind
( Type )
import GHC.TypeLits
( Symbol, KnownSymbol )

data Label (k :: Symbol) (a :: Type) = Label
class IsLabel k a v  v > a, v > k where
fromLabel :: v
instance KnownSymbol k => IsLabel k a (Label k a) where
fromLabel = Label @k @a
foo :: Label k a > ()
foo _ = ()
test :: ()
test = foo ( #label @Bool )
```
The point of this program is that the label `#label` is polymorphic:
```haskell
#label :: forall (a :: Type). Label "label" a
```
and I am able to instantiate the type variable `a` with a type application.
<p>
<details>
<summary> Show/hide further context.</summary>
This was boiled down from the overloaded label syntax I provide in my shader library, see [here](https://gitlab.com/sheaf/fir//blob/master/src/FIR/Syntax/Labels.hs).
This added bit of syntax allows users of the library to write shaders in an imperative style, see [here](https://gitlab.com/sheaf/fir//blob/master/firexamples/examples/shaders/FIR/Examples/JuliaSet/Shaders.hs#L117) for an example.
</details>
</p>
This program compiles fine on GHC 8.10 (and previous GHC versions), but fails to compile on GHC 9.0 (rc1) with the following error:
```
Labels.hs:35:14: error:
* Cannot apply expression of type `v0'
to a visible type argument `Bool'
* In the first argument of `foo', namely `(#label @Bool)'
In the expression: foo (#label @Bool)
In an equation for `test': test = foo (#label @Bool)

35  test = foo ( #label @Bool )
 ^^^^^
```
Can someone enlighten me about what's going on? I found it quite useful to be able to pass further arguments to an overloaded label in this way, whereas I now have to write something like
```haskell
test :: ()
test = foo ( #label :: Label _ Bool )
```
to specify `a`, which defeats the purpose of the overloaded labels syntax. At that point I might as well just write:
```haskell
foo ( Label @"label" @Bool )
```In the program that follows, I specify the type of a label by using a visible type application.
```haskell
{# LANGUAGE DataKinds #}
{# LANGUAGE FlexibleInstances #}
{# LANGUAGE FunctionalDependencies #}
{# LANGUAGE OverloadedLabels #}
{# LANGUAGE PolyKinds #}
{# LANGUAGE RebindableSyntax #}
{# LANGUAGE ScopedTypeVariables #}
{# LANGUAGE TypeApplications #}
module Labels where
 base
import Prelude
import Data.Kind
( Type )
import GHC.TypeLits
( Symbol, KnownSymbol )

data Label (k :: Symbol) (a :: Type) = Label
class IsLabel k a v  v > a, v > k where
fromLabel :: v
instance KnownSymbol k => IsLabel k a (Label k a) where
fromLabel = Label @k @a
foo :: Label k a > ()
foo _ = ()
test :: ()
test = foo ( #label @Bool )
```
The point of this program is that the label `#label` is polymorphic:
```haskell
#label :: forall (a :: Type). Label "label" a
```
and I am able to instantiate the type variable `a` with a type application.
<p>
<details>
<summary> Show/hide further context.</summary>
This was boiled down from the overloaded label syntax I provide in my shader library, see [here](https://gitlab.com/sheaf/fir//blob/master/src/FIR/Syntax/Labels.hs).
This added bit of syntax allows users of the library to write shaders in an imperative style, see [here](https://gitlab.com/sheaf/fir//blob/master/firexamples/examples/shaders/FIR/Examples/JuliaSet/Shaders.hs#L117) for an example.
</details>
</p>
This program compiles fine on GHC 8.10 (and previous GHC versions), but fails to compile on GHC 9.0 (rc1) with the following error:
```
Labels.hs:35:14: error:
* Cannot apply expression of type `v0'
to a visible type argument `Bool'
* In the first argument of `foo', namely `(#label @Bool)'
In the expression: foo (#label @Bool)
In an equation for `test': test = foo (#label @Bool)

35  test = foo ( #label @Bool )
 ^^^^^
```
Can someone enlighten me about what's going on? I found it quite useful to be able to pass further arguments to an overloaded label in this way, whereas I now have to write something like
```haskell
test :: ()
test = foo ( #label :: Label _ Bool )
```
to specify `a`, which defeats the purpose of the overloaded labels syntax. At that point I might as well just write:
```haskell
foo ( Label @"label" @Bool )
```9.2.1https://gitlab.haskell.org/ghc/ghc//issues/19167Regression around overloaded literals and type applications20210221T16:41:22ZRichard Eisenbergrae@richarde.devRegression around overloaded literals and type applicationsThe new eager instantiation approach (adopted as a part of Quick Look) does not treat overloaded literals as "heads". This causes trouble when using them with type applications, which can be useful when using `XRebindableSyntax`. Specifically, the following module compiles with released GHCs:
```hs
{# LANGUAGE RebindableSyntax, RankNTypes, TypeApplications, OverloadedStrings,
OverloadedLists, TypeFamilies #}
module Bug where
import qualified Prelude as P
import qualified GHC.Exts as P
import Data.List.NonEmpty ( NonEmpty )
fromInteger :: P.Integer > forall a. P.Num a => a
fromInteger n = P.fromInteger n
shouldBeAnInt = 3 @P.Int
newtype RevString = RevString P.String
deriving P.Show
instance P.IsString RevString where
fromString str = RevString (P.reverse str)
fromString :: P.String > forall a. P.IsString a => a
fromString str = P.fromString str
shouldBeARevString = "hello" @RevString
fromListN :: P.Int > [elt] > forall list. (P.IsList list, elt ~ P.Item list) => list
fromListN n l = P.fromListN n l
shouldBeANonEmpty = ['x', 'y', 'z'] @(NonEmpty P.Char)
```
All three `shouldBe` definitions are rejected with HEAD. But accepted by 8.xThe new eager instantiation approach (adopted as a part of Quick Look) does not treat overloaded literals as "heads". This causes trouble when using them with type applications, which can be useful when using `XRebindableSyntax`. Specifically, the following module compiles with released GHCs:
```hs
{# LANGUAGE RebindableSyntax, RankNTypes, TypeApplications, OverloadedStrings,
OverloadedLists, TypeFamilies #}
module Bug where
import qualified Prelude as P
import qualified GHC.Exts as P
import Data.List.NonEmpty ( NonEmpty )
fromInteger :: P.Integer > forall a. P.Num a => a
fromInteger n = P.fromInteger n
shouldBeAnInt = 3 @P.Int
newtype RevString = RevString P.String
deriving P.Show
instance P.IsString RevString where
fromString str = RevString (P.reverse str)
fromString :: P.String > forall a. P.IsString a => a
fromString str = P.fromString str
shouldBeARevString = "hello" @RevString
fromListN :: P.Int > [elt] > forall list. (P.IsList list, elt ~ P.Item list) => list
fromListN n l = P.fromListN n l
shouldBeANonEmpty = ['x', 'y', 'z'] @(NonEmpty P.Char)
```
All three `shouldBe` definitions are rejected with HEAD. But accepted by 8.x9.2.1https://gitlab.haskell.org/ghc/ghc//issues/19196TypeInType prevents Typeable from being resolved from a given20210111T03:19:52ZSerge KosyrevTypeInType prevents Typeable from being resolved from a givenThe following program is accepted without `TypeInType` by GHC 8.10.2:
```haskell
{# LANGUAGE DataKinds #}
{# LANGUAGE GADTs #}
{# LANGUAGE KindSignatures #}
{# LANGUAGE ScopedTypeVariables #}
{# LANGUAGE UndecidableInstances #}
import Data.Dynamic
import Type.Reflection
data Liveness
= forall t. Live t
data IOA (l :: Liveness) where
IOE :: IOA (Live t)
data LTag (l :: Liveness) where
LLive :: Typeable t => TypeRep t > LTag (Live t)
reconstruct :: Dynamic > LTag l > ()
reconstruct dyn l@LLive{} =
case l of
(LLive tr :: LTag (Live t)) >
undefined $ withTypeable tr $
(fromDynamic dyn :: Maybe (IOA (Live t)))
main :: IO ()
main = undefined
```
It is, however, rejected with `TypeInType`, as follows:
```haskell
common/src/Dom/Pipe/IOA.hs:26:17: error:
• Could not deduce (Typeable t) arising from a use of ‘fromDynamic’
from the context: (l ~ 'Live t1, Typeable t1)
bound by a pattern with constructor:
LLive :: forall t1 (t2 :: t1).
Typeable t2 =>
TypeRep t2 > LTag ('Live t2),
in an equation for ‘reconstruct’
at common/src/Dom/Pipe/IOA.hs:22:1925
or from: ('Live t1 ~ 'Live t3, Typeable t3)
bound by a pattern with constructor:
LLive :: forall t1 (t2 :: t1).
Typeable t2 =>
TypeRep t2 > LTag ('Live t2),
in a case alternative
at common/src/Dom/Pipe/IOA.hs:24:1017
or from: Typeable t3
bound by a type expected by the context:
Typeable t3 => Maybe (IOA ('Live t1))
at common/src/Dom/Pipe/IOA.hs:26:1656
• In the second argument of ‘($)’, namely
‘(fromDynamic dyn :: Maybe (IOA (Live t)))’
In the second argument of ‘($)’, namely
‘withTypeable tr $ (fromDynamic dyn :: Maybe (IOA (Live t)))’
In the expression:
undefined
$ withTypeable tr $ (fromDynamic dyn :: Maybe (IOA (Live t)))

26  (fromDynamic dyn :: Maybe (IOA (Live t)))
 ^^^^^^^^^^^^^^^
```
Potentially related to #16627The following program is accepted without `TypeInType` by GHC 8.10.2:
```haskell
{# LANGUAGE DataKinds #}
{# LANGUAGE GADTs #}
{# LANGUAGE KindSignatures #}
{# LANGUAGE ScopedTypeVariables #}
{# LANGUAGE UndecidableInstances #}
import Data.Dynamic
import Type.Reflection
data Liveness
= forall t. Live t
data IOA (l :: Liveness) where
IOE :: IOA (Live t)
data LTag (l :: Liveness) where
LLive :: Typeable t => TypeRep t > LTag (Live t)
reconstruct :: Dynamic > LTag l > ()
reconstruct dyn l@LLive{} =
case l of
(LLive tr :: LTag (Live t)) >
undefined $ withTypeable tr $
(fromDynamic dyn :: Maybe (IOA (Live t)))
main :: IO ()
main = undefined
```
It is, however, rejected with `TypeInType`, as follows:
```haskell
common/src/Dom/Pipe/IOA.hs:26:17: error:
• Could not deduce (Typeable t) arising from a use of ‘fromDynamic’
from the context: (l ~ 'Live t1, Typeable t1)
bound by a pattern with constructor:
LLive :: forall t1 (t2 :: t1).
Typeable t2 =>
TypeRep t2 > LTag ('Live t2),
in an equation for ‘reconstruct’
at common/src/Dom/Pipe/IOA.hs:22:1925
or from: ('Live t1 ~ 'Live t3, Typeable t3)
bound by a pattern with constructor:
LLive :: forall t1 (t2 :: t1).
Typeable t2 =>
TypeRep t2 > LTag ('Live t2),
in a case alternative
at common/src/Dom/Pipe/IOA.hs:24:1017
or from: Typeable t3
bound by a type expected by the context:
Typeable t3 => Maybe (IOA ('Live t1))
at common/src/Dom/Pipe/IOA.hs:26:1656
• In the second argument of ‘($)’, namely
‘(fromDynamic dyn :: Maybe (IOA (Live t)))’
In the second argument of ‘($)’, namely
‘withTypeable tr $ (fromDynamic dyn :: Maybe (IOA (Live t)))’
In the expression:
undefined
$ withTypeable tr $ (fromDynamic dyn :: Maybe (IOA (Live t)))

26  (fromDynamic dyn :: Maybe (IOA (Live t)))
 ^^^^^^^^^^^^^^^
```
Potentially related to #16627https://gitlab.haskell.org/ghc/ghc//issues/19197‘:kind () :: '()’ doesn't give any output20210118T17:11:59ZIcelandjack‘:kind () :: '()’ doesn't give any output```
$ ./ghc/_build/stage1/bin/ghc ignoredotghci interactive
GHCi, version 9.1.0.20201202: https://www.haskell.org/ghc/ :? for help
ghci> :set XKindSignatures XDataKinds
ghci> :k () :: '()
ghci>
ghci> :set XPartialTypeSignatures Wnopartialtypesignatures
ghci> :k (_, _) :: '(_, _)
ghci>
ghci> import Data.Functor.Identity
ghci> :k Identity _ :: 'Identity _
ghci>
```
It should give an error```
$ ./ghc/_build/stage1/bin/ghc ignoredotghci interactive
GHCi, version 9.1.0.20201202: https://www.haskell.org/ghc/ :? for help
ghci> :set XKindSignatures XDataKinds
ghci> :k () :: '()
ghci>
ghci> :set XPartialTypeSignatures Wnopartialtypesignatures
ghci> :k (_, _) :: '(_, _)
ghci>
ghci> import Data.Functor.Identity
ghci> :k Identity _ :: 'Identity _
ghci>
```
It should give an errorhttps://gitlab.haskell.org/ghc/ghc//issues/19315GHC 9.0 regression: plots0.1.1.2 fails to build due to ambiguous type variable20210210T21:11:55ZRyan ScottGHC 9.0 regression: plots0.1.1.2 fails to build due to ambiguous type variable_Originally observed in a `head.hackage` CI build [here](https://gitlab.haskell.org/ghc/head.hackage//jobs/568397#L5617)_.
The `plots0.1.1.2` library fails to compile using commit 0789f7a18a78920f50647e2b4aa8082a14ca9e90 of the `ghc9.0` branch. Here is a selfcontained example with no external dependencies:
```hs
{# LANGUAGE ConstraintKinds #}
{# LANGUAGE FlexibleContexts #}
{# LANGUAGE FlexibleInstances #}
{# LANGUAGE FunctionalDependencies #}
{# LANGUAGE RankNTypes #}
{# LANGUAGE RecordWildCards #}
{# LANGUAGE ScopedTypeVariables #}
{# LANGUAGE TypeFamilies #}
{# LANGUAGE TypeOperators #}
module Bug where
import Control.Monad.Reader
import Data.Functor.Const
import Data.Functor.Identity
import Data.Monoid (Any(..))
import Data.Typeable
type TypeableFloat n = (Typeable n, RealFloat n)
type Lens' s a = Lens s s a a
type Lens s t a b = forall f. Functor f => (a > f b) > s > f t
type LensLike' f s a = LensLike f s s a a
type LensLike f s t a b = (a > f b) > s > f t
type Getting r s a = (a > Const r a) > s > Const r s
type ASetter s t a b = (a > Identity b) > s > Identity t
data V2 a = V2 !a !a
flipX_Y :: Num n => V2 n > V2 n
flipX_Y (V2 x y) = V2 (y) (x)
class R1 t where
_x :: Lens' (t a) a
class R1 t => R2 t where
_y :: Lens' (t a) a
instance R1 V2 where
_x f (V2 a b) = (`V2` b) <$> f a
instance R2 V2 where
_y f (V2 a b) = V2 a <$> f b
infixl 8 #
(#) :: a > (a > b) > b
(#) = flip ($)
infixr 4 %~
(%~) :: ASetter s t a b > (a > b) > s > t
(%~) = over
(^.) :: s > Getting a s a > a
s ^. l = getConst (l Const s)
over :: ASetter s t a b > (a > b) > s > t
over l f = runIdentity . l (Identity . f)
view :: MonadReader s m => Getting a s a > m a
view l = asks (getConst . l Const)
lens :: (s > a) > (s > b > t) > Lens s t a b
lens sa sbt afb s = sbt s <$> afb (sa s)
type family V a :: * > *
type family N a :: *
type Vn a = V a (N a)
data Style (v :: * > *) n = Style
class HasStyle a where
applyStyle :: Style (V a) (N a) > a > a
type TextFunction b v n = TextAlignment n > String > QDiagram b v n Any
data TickLabels b (v :: * > *) n = TickLabels
{ tlFun :: [n] > (n,n) > [(n, String)]
, tlTextFun :: TextFunction b v n
, tlStyle :: Style v n
, tlGap :: n
}
type instance V (TickLabels b v n) = v
type instance N (TickLabels b v n) = n
class HasTickLabels f a b  a > b where
tickLabel :: LensLike' f a (TickLabels b (V a) (N a))
tickLabelTextFunction :: Functor f => LensLike' f a (TextFunction b (V a) (N a))
tickLabelTextFunction = tickLabel . lens tlTextFun (\tl f > tl {tlTextFun = f})
tickLabelFunction :: Functor f => LensLike' f a ([N a] > (N a, N a) > [(N a, String)])
tickLabelFunction = tickLabel . lens tlFun (\tl f > tl {tlFun = f})
tickLabelStyle :: Functor f => LensLike' f a (Style (V a) (N a))
tickLabelStyle = tickLabel . lens tlStyle (\tl sty > tl {tlStyle = sty})
tickLabelGap :: Functor f => LensLike' f a (N a)
tickLabelGap = tickLabel . lens tlGap (\tl n > tl {tlGap = n})
instance HasTickLabels f (TickLabels b v n) b where
tickLabel = id
data ColourBar b n = ColourBar
{ cbTickLabels :: TickLabels b V2 n
, cbTicks :: MajorTicks V2 n
, cbWidth :: n
}
type instance V (ColourBar b n) = V2
type instance N (ColourBar b n) = n
data MajorTicks (v :: * > *) n = MajorTicks
{ matFunction :: (n,n) > [n]
}
type instance V (MajorTicks v n) = v
type instance N (MajorTicks v n) = n
class HasMajorTicks f a where
majorTicks :: LensLike' f a (MajorTicks (V a) (N a))
majorTicksFunction :: Functor f => LensLike' f a ((N a, N a) > [N a])
majorTicksFunction = majorTicks . lens matFunction (\mat a > mat {matFunction = a})
instance HasMajorTicks f (MajorTicks v n) where
majorTicks = id
data Path (v :: * > *) n = Path
data (::) u v = (u > v) :: (v > u)
infixr 7 ::
instance Semigroup (a :: a) where
(f :: f') <> (g :: g') = f . g :: g' . f'
instance Monoid (v :: v) where
mempty = id :: id
data Transformation v n = Transformation (v n :: v n) (v n :: v n) (v n)
class Transformable t where
transform :: Transformation (V t) (N t) > t > t
translation :: v n > Transformation v n
translation = Transformation mempty mempty
translate :: (Transformable t) => Vn t > t > t
translate = transform . translation
class Transformable t => Renderable t b where
orient :: HasOrientation o => o > a > a > a
orient o h v =
case view orientation o of
Horizontal > h
Vertical > v
data Orientation = Horizontal  Vertical
class HasOrientation a where
orientation :: Lens' a Orientation
instance HasPlacement (ColourBar b n) where
placement = undefined
instance HasOrientation (ColourBar b n) where
orientation = undefined
instance Functor f => HasMajorTicks f (ColourBar b n) where
majorTicks = lens cbTicks (\c a > c {cbTicks = a})
data ColourMap = ColourMap
data QDiagram b (v :: * > *) n m = QD
instance Semigroup m  (Metric v, OrderedField n, Semigroup m)
=> HasStyle (QDiagram b v n m) where
applyStyle = undefined
instance Semigroup m  (Metric v, OrderedField n, Semigroup m)
=> Monoid (QDiagram b v n m) where
mempty = undefined
instance Semigroup m  (Metric v, OrderedField n, Semigroup m)
=> Semigroup (QDiagram b v n m) where
(<>) = undefined
instance Semigroup m  (OrderedField n, Metric v, Semigroup m)
=> Transformable (QDiagram b v n m) where
transform = undefined
type instance V (QDiagram b v n m) = v
type instance N (QDiagram b v n m) = n
data TextAlignment n = BaselineText  BoxAlignedText n n
data Placement = Placement
{ pAt :: V2 Rational
}
class HasPlacement a where
placement :: Lens' a Placement
placementAt :: Lens' a (V2 Rational)
placementAt = placement . lens pAt (\p a > p {pAt = a})
renderColourBar
:: forall n b. (TypeableFloat n, Renderable (Path V2 n) b)
=> ColourBar b n
> ColourMap
> (n,n)
> n
> QDiagram b V2 n Any
renderColourBar cb@ColourBar {..} _cm bnds@(lb,ub) l
= tLbs
where
o, xy :: a > a > a
o = orient cb
xy a b = if let V2 x y = cb^.placementAt in x > y
then a else b
w = cbWidth
f x = (x  (ub + lb)/2) / (ub  lb) * l
inRange x = x >= lb && x <= ub
tickXs = view majorTicksFunction cbTicks bnds
tickXs' :: [n]
tickXs' = filter inRange tickXs
tickLabelXs :: [(n, String)]
tickLabelXs = view tickLabelFunction cbTickLabels tickXs' bnds
tLbs :: QDiagram b V2 n Any
tLbs = foldMap drawTickLabel tickLabelXs
drawTickLabel :: (n, String) > QDiagram b (V (TickLabels b V2 n)) (N (TickLabels b V2 n)) Any
drawTickLabel (x,label) =
view tickLabelTextFunction cbTickLabels tAlign label
# translate v
# applyStyle (cbTickLabels ^. tickLabelStyle)
where v = V2 (f x) ( w/2  view tickLabelGap cbTickLabels)
# xy id (_y %~ negate)
# o id ((_y %~ negate) . flipX_Y)
tAlign = o (xy (BoxAlignedText 0.5 1) (BoxAlignedText 0.5 0))
(xy (BoxAlignedText 0 0.5) (BoxAlignedText 1 0.5))
```
This compiles with GHC 8.10.3 and earlier, but fails to compile with `ghc9.0`:
```
$ ~/Software/ghc9.0.0.20210130/bin/ghc Bug.hs
[1 of 1] Compiling Bug ( Bug.hs, Bug.o )
Bug.hs:229:22: error:
• Could not deduce (HasTickLabels
(Const ([n] > (n, n) > [(n, String)])) (TickLabels b V2 n) b0)
arising from a use of ‘tickLabelFunction’
from the context: (TypeableFloat n, Renderable (Path V2 n) b)
bound by the type signature for:
renderColourBar :: forall n b.
(TypeableFloat n, Renderable (Path V2 n) b) =>
ColourBar b n
> ColourMap > (n, n) > n > QDiagram b V2 n Any
at Bug.hs:(204,1)(210,24)
The type variable ‘b0’ is ambiguous
Relevant bindings include
tickLabelXs :: [(n, String)] (bound at Bug.hs:229:3)
tickXs' :: [n] (bound at Bug.hs:226:3)
inRange :: n > Bool (bound at Bug.hs:222:3)
tickXs :: [n] (bound at Bug.hs:224:3)
l :: n (bound at Bug.hs:211:52)
ub :: n (bound at Bug.hs:211:48)
cbTickLabels :: TickLabels b V2 n (bound at Bug.hs:211:31)
(Some bindings suppressed; use fmaxrelevantbinds=N or fnomaxrelevantbinds)
These potential instance exist:
instance HasTickLabels f (TickLabels b v n) b
 Defined at Bug.hs:100:10
• In the first argument of ‘view’, namely ‘tickLabelFunction’
In the expression: view tickLabelFunction cbTickLabels tickXs' bnds
In an equation for ‘tickLabelXs’:
tickLabelXs = view tickLabelFunction cbTickLabels tickXs' bnds

229  tickLabelXs = view tickLabelFunction cbTickLabels tickXs' bnds
 ^^^^^^^^^^^^^^^^^
```
Moreover, this compiles with GHC 9.0.1rc1. This regression was introduced at some point between the following commits:
* 9183f5a537df159e37c26d9d385cf497bcfaae30 (`gitlabci: Don't run LLVM tests on Debian 9`). This commit has an artifact associated with it, and I can confirm that the bug is not present here.
* 0789f7a18a78920f50647e2b4aa8082a14ca9e90 (`Hadrian: show default ghcbignum backend (fix #18912)`)_Originally observed in a `head.hackage` CI build [here](https://gitlab.haskell.org/ghc/head.hackage//jobs/568397#L5617)_.
The `plots0.1.1.2` library fails to compile using commit 0789f7a18a78920f50647e2b4aa8082a14ca9e90 of the `ghc9.0` branch. Here is a selfcontained example with no external dependencies:
```hs
{# LANGUAGE ConstraintKinds #}
{# LANGUAGE FlexibleContexts #}
{# LANGUAGE FlexibleInstances #}
{# LANGUAGE FunctionalDependencies #}
{# LANGUAGE RankNTypes #}
{# LANGUAGE RecordWildCards #}
{# LANGUAGE ScopedTypeVariables #}
{# LANGUAGE TypeFamilies #}
{# LANGUAGE TypeOperators #}
module Bug where
import Control.Monad.Reader
import Data.Functor.Const
import Data.Functor.Identity
import Data.Monoid (Any(..))
import Data.Typeable
type TypeableFloat n = (Typeable n, RealFloat n)
type Lens' s a = Lens s s a a
type Lens s t a b = forall f. Functor f => (a > f b) > s > f t
type LensLike' f s a = LensLike f s s a a
type LensLike f s t a b = (a > f b) > s > f t
type Getting r s a = (a > Const r a) > s > Const r s
type ASetter s t a b = (a > Identity b) > s > Identity t
data V2 a = V2 !a !a
flipX_Y :: Num n => V2 n > V2 n
flipX_Y (V2 x y) = V2 (y) (x)
class R1 t where
_x :: Lens' (t a) a
class R1 t => R2 t where
_y :: Lens' (t a) a
instance R1 V2 where
_x f (V2 a b) = (`V2` b) <$> f a
instance R2 V2 where
_y f (V2 a b) = V2 a <$> f b
infixl 8 #
(#) :: a > (a > b) > b
(#) = flip ($)
infixr 4 %~
(%~) :: ASetter s t a b > (a > b) > s > t
(%~) = over
(^.) :: s > Getting a s a > a
s ^. l = getConst (l Const s)
over :: ASetter s t a b > (a > b) > s > t
over l f = runIdentity . l (Identity . f)
view :: MonadReader s m => Getting a s a > m a
view l = asks (getConst . l Const)
lens :: (s > a) > (s > b > t) > Lens s t a b
lens sa sbt afb s = sbt s <$> afb (sa s)
type family V a :: * > *
type family N a :: *
type Vn a = V a (N a)
data Style (v :: * > *) n = Style
class HasStyle a where
applyStyle :: Style (V a) (N a) > a > a
type TextFunction b v n = TextAlignment n > String > QDiagram b v n Any
data TickLabels b (v :: * > *) n = TickLabels
{ tlFun :: [n] > (n,n) > [(n, String)]
, tlTextFun :: TextFunction b v n
, tlStyle :: Style v n
, tlGap :: n
}
type instance V (TickLabels b v n) = v
type instance N (TickLabels b v n) = n
class HasTickLabels f a b  a > b where
tickLabel :: LensLike' f a (TickLabels b (V a) (N a))
tickLabelTextFunction :: Functor f => LensLike' f a (TextFunction b (V a) (N a))
tickLabelTextFunction = tickLabel . lens tlTextFun (\tl f > tl {tlTextFun = f})
tickLabelFunction :: Functor f => LensLike' f a ([N a] > (N a, N a) > [(N a, String)])
tickLabelFunction = tickLabel . lens tlFun (\tl f > tl {tlFun = f})
tickLabelStyle :: Functor f => LensLike' f a (Style (V a) (N a))
tickLabelStyle = tickLabel . lens tlStyle (\tl sty > tl {tlStyle = sty})
tickLabelGap :: Functor f => LensLike' f a (N a)
tickLabelGap = tickLabel . lens tlGap (\tl n > tl {tlGap = n})
instance HasTickLabels f (TickLabels b v n) b where
tickLabel = id
data ColourBar b n = ColourBar
{ cbTickLabels :: TickLabels b V2 n
, cbTicks :: MajorTicks V2 n
, cbWidth :: n
}
type instance V (ColourBar b n) = V2
type instance N (ColourBar b n) = n
data MajorTicks (v :: * > *) n = MajorTicks
{ matFunction :: (n,n) > [n]
}
type instance V (MajorTicks v n) = v
type instance N (MajorTicks v n) = n
class HasMajorTicks f a where
majorTicks :: LensLike' f a (MajorTicks (V a) (N a))
majorTicksFunction :: Functor f => LensLike' f a ((N a, N a) > [N a])
majorTicksFunction = majorTicks . lens matFunction (\mat a > mat {matFunction = a})
instance HasMajorTicks f (MajorTicks v n) where
majorTicks = id
data Path (v :: * > *) n = Path
data (::) u v = (u > v) :: (v > u)
infixr 7 ::
instance Semigroup (a :: a) where
(f :: f') <> (g :: g') = f . g :: g' . f'
instance Monoid (v :: v) where
mempty = id :: id
data Transformation v n = Transformation (v n :: v n) (v n :: v n) (v n)
class Transformable t where
transform :: Transformation (V t) (N t) > t > t
translation :: v n > Transformation v n
translation = Transformation mempty mempty
translate :: (Transformable t) => Vn t > t > t
translate = transform . translation
class Transformable t => Renderable t b where
orient :: HasOrientation o => o > a > a > a
orient o h v =
case view orientation o of
Horizontal > h
Vertical > v
data Orientation = Horizontal  Vertical
class HasOrientation a where
orientation :: Lens' a Orientation
instance HasPlacement (ColourBar b n) where
placement = undefined
instance HasOrientation (ColourBar b n) where
orientation = undefined
instance Functor f => HasMajorTicks f (ColourBar b n) where
majorTicks = lens cbTicks (\c a > c {cbTicks = a})
data ColourMap = ColourMap
data QDiagram b (v :: * > *) n m = QD
instance Semigroup m  (Metric v, OrderedField n, Semigroup m)
=> HasStyle (QDiagram b v n m) where
applyStyle = undefined
instance Semigroup m  (Metric v, OrderedField n, Semigroup m)
=> Monoid (QDiagram b v n m) where
mempty = undefined
instance Semigroup m  (Metric v, OrderedField n, Semigroup m)
=> Semigroup (QDiagram b v n m) where
(<>) = undefined
instance Semigroup m  (OrderedField n, Metric v, Semigroup m)
=> Transformable (QDiagram b v n m) where
transform = undefined
type instance V (QDiagram b v n m) = v
type instance N (QDiagram b v n m) = n
data TextAlignment n = BaselineText  BoxAlignedText n n
data Placement = Placement
{ pAt :: V2 Rational
}
class HasPlacement a where
placement :: Lens' a Placement
placementAt :: Lens' a (V2 Rational)
placementAt = placement . lens pAt (\p a > p {pAt = a})
renderColourBar
:: forall n b. (TypeableFloat n, Renderable (Path V2 n) b)
=> ColourBar b n
> ColourMap
> (n,n)
> n
> QDiagram b V2 n Any
renderColourBar cb@ColourBar {..} _cm bnds@(lb,ub) l
= tLbs
where
o, xy :: a > a > a
o = orient cb
xy a b = if let V2 x y = cb^.placementAt in x > y
then a else b
w = cbWidth
f x = (x  (ub + lb)/2) / (ub  lb) * l
inRange x = x >= lb && x <= ub
tickXs = view majorTicksFunction cbTicks bnds
tickXs' :: [n]
tickXs' = filter inRange tickXs
tickLabelXs :: [(n, String)]
tickLabelXs = view tickLabelFunction cbTickLabels tickXs' bnds
tLbs :: QDiagram b V2 n Any
tLbs = foldMap drawTickLabel tickLabelXs
drawTickLabel :: (n, String) > QDiagram b (V (TickLabels b V2 n)) (N (TickLabels b V2 n)) Any
drawTickLabel (x,label) =
view tickLabelTextFunction cbTickLabels tAlign label
# translate v
# applyStyle (cbTickLabels ^. tickLabelStyle)
where v = V2 (f x) ( w/2  view tickLabelGap cbTickLabels)
# xy id (_y %~ negate)
# o id ((_y %~ negate) . flipX_Y)
tAlign = o (xy (BoxAlignedText 0.5 1) (BoxAlignedText 0.5 0))
(xy (BoxAlignedText 0 0.5) (BoxAlignedText 1 0.5))
```
This compiles with GHC 8.10.3 and earlier, but fails to compile with `ghc9.0`:
```
$ ~/Software/ghc9.0.0.20210130/bin/ghc Bug.hs
[1 of 1] Compiling Bug ( Bug.hs, Bug.o )
Bug.hs:229:22: error:
• Could not deduce (HasTickLabels
(Const ([n] > (n, n) > [(n, String)])) (TickLabels b V2 n) b0)
arising from a use of ‘tickLabelFunction’
from the context: (TypeableFloat n, Renderable (Path V2 n) b)
bound by the type signature for:
renderColourBar :: forall n b.
(TypeableFloat n, Renderable (Path V2 n) b) =>
ColourBar b n
> ColourMap > (n, n) > n > QDiagram b V2 n Any
at Bug.hs:(204,1)(210,24)
The type variable ‘b0’ is ambiguous
Relevant bindings include
tickLabelXs :: [(n, String)] (bound at Bug.hs:229:3)
tickXs' :: [n] (bound at Bug.hs:226:3)
inRange :: n > Bool (bound at Bug.hs:222:3)
tickXs :: [n] (bound at Bug.hs:224:3)
l :: n (bound at Bug.hs:211:52)
ub :: n (bound at Bug.hs:211:48)
cbTickLabels :: TickLabels b V2 n (bound at Bug.hs:211:31)
(Some bindings suppressed; use fmaxrelevantbinds=N or fnomaxrelevantbinds)
These potential instance exist:
instance HasTickLabels f (TickLabels b v n) b
 Defined at Bug.hs:100:10
• In the first argument of ‘view’, namely ‘tickLabelFunction’
In the expression: view tickLabelFunction cbTickLabels tickXs' bnds
In an equation for ‘tickLabelXs’:
tickLabelXs = view tickLabelFunction cbTickLabels tickXs' bnds

229  tickLabelXs = view tickLabelFunction cbTickLabels tickXs' bnds
 ^^^^^^^^^^^^^^^^^
```
Moreover, this compiles with GHC 9.0.1rc1. This regression was introduced at some point between the following commits:
* 9183f5a537df159e37c26d9d385cf497bcfaae30 (`gitlabci: Don't run LLVM tests on Debian 9`). This commit has an artifact associated with it, and I can confirm that the bug is not present here.
* 0789f7a18a78920f50647e2b4aa8082a14ca9e90 (`Hadrian: show default ghcbignum backend (fix #18912)`)9.0.2https://gitlab.haskell.org/ghc/ghc//issues/19364oversized source range in type error message20210304T10:42:13Zjwaldmannoversized source range in type error messageFor this code
```
type Foo = Bool
type Bar = String
data Pair a b = Pair a b
baz :: Pair Foo Bar
baz = Pair "yes" "no"
```
ghc says
```
B.hs:7:721: error:
• Couldn't match type ‘[Char]’ with ‘Bool’
Expected type: Pair Foo Bar
Actual type: Pair [Char] [Char]
• In the expression: Pair "yes" "no"
In an equation for ‘baz’: baz = Pair "yes" "no"

7  baz = Pair "yes" "no"
 ^^^^^^^^^^^^^^^
```
So, which argument is wrong?
In fact, how many are?
```
baz :: Pair Foo Bar
baz = Pair "yes" ()
B.hs:7:719: error:
• Couldn't match type ‘[Char]’ with ‘Bool’
Expected type: Pair Foo Bar
Actual type: Pair [Char] ()
• In the expression: Pair "yes" ()
In an equation for ‘baz’: baz = Pair "yes" ()

7  baz = Pair "yes" ()
 ^^^^^^^^^^^^^
```
The following case works better (it shows that the first argument is the problem). What's the difference?
```
foo :: (Foo,Bar)
foo = ("yes", "no")
B.hs:11:812: error:
• Couldn't match type ‘[Char]’ with ‘Bool’
Expected type: Foo
Actual type: [Char]
• In the expression: "yes"
In the expression: ("yes", "no")
In an equation for ‘foo’: foo = ("yes", "no")

11  foo = ("yes", "no")
 ^^^^^
```For this code
```
type Foo = Bool
type Bar = String
data Pair a b = Pair a b
baz :: Pair Foo Bar
baz = Pair "yes" "no"
```
ghc says
```
B.hs:7:721: error:
• Couldn't match type ‘[Char]’ with ‘Bool’
Expected type: Pair Foo Bar
Actual type: Pair [Char] [Char]
• In the expression: Pair "yes" "no"
In an equation for ‘baz’: baz = Pair "yes" "no"

7  baz = Pair "yes" "no"
 ^^^^^^^^^^^^^^^
```
So, which argument is wrong?
In fact, how many are?
```
baz :: Pair Foo Bar
baz = Pair "yes" ()
B.hs:7:719: error:
• Couldn't match type ‘[Char]’ with ‘Bool’
Expected type: Pair Foo Bar
Actual type: Pair [Char] ()
• In the expression: Pair "yes" ()
In an equation for ‘baz’: baz = Pair "yes" ()

7  baz = Pair "yes" ()
 ^^^^^^^^^^^^^
```
The following case works better (it shows that the first argument is the problem). What's the difference?
```
foo :: (Foo,Bar)
foo = ("yes", "no")
B.hs:11:812: error:
• Couldn't match type ‘[Char]’ with ‘Bool’
Expected type: Foo
Actual type: [Char]
• In the expression: "yes"
In the expression: ("yes", "no")
In an equation for ‘foo’: foo = ("yes", "no")

11  foo = ("yes", "no")
 ^^^^^
```https://gitlab.haskell.org/ghc/ghc//issues/19396Surprising lack of generalisation using MonoLocalBinds20210306T10:06:16ZTom EllisSurprising lack of generalisation using MonoLocalBinds## Motivation
It seems to me that `MonoLocalBinds` is too aggressive in avoiding generalisation. Please observe the example below. In `pFG1`, `pBD` is not generalised. The reason is roughly because `pBArg` does not have a monomorphic type signature, and indeed providing one, as in `pFG2`, leads to a generalised definition.
But this seems too aggressive to me. In `pFG1` the type of `pBArg` *is* known and monomorphic. Its type occurs in the type signature of `pFG1`! Could we generalise `pBD` in this case?
This is a simplified and anonymised version of real word code. This really does happen. The cause puzzled me and I'm an experienced Haskell user. I feel bad for a less experienced colleague who might try something similar but would receive a type error for code which seems like it really ought to type check.
## Proposal
Extend [the definition of "closed"](https://downloads.haskell.org/ghc/latest/docs/html/users_guide/exts/let_generalisation.html) to encompass lambda bound variables whose type, from the explicit type signature of the lambda, is known and contains no free type variables.
## Notes
This issue was [discussed between @tomjaguarpaw1 and @rae on HaskellCafe](https://mail.haskell.org/pipermail/haskellcafe/2021February/133381.html).
I have included `pFG3` for *information only* in case anyone is curious what happens in the polymorphic case. They don't work even with an explicit type signature.
## Example
```haskell
{# LANGUAGE MonoLocalBinds #}
{# LANGUAGE ScopedTypeVariables #}
 This code came up in the context of writing a parser, but that's
 not terribly important
import Prelude hiding ((<$>))
data B = B
data D f = GF AP f
 DF AM f
data AM = AM
data AP = AP
pB :: Parser B
pB = Parser
 Does not type check
pFG1 :: Parser B > Parser (D B)
pFG1 pBArg = pBD GF AP <> pBD DF AM
where pBD f p = f p <$> pBArg
 Does type check
pFG2 :: Parser B > Parser (D B)
pFG2 pBArg = pBD GF AP <> pBD DF AM
where pBArg' :: Parser B
pBArg' = pBArg
pBD f p = f p <$> pBArg'
 Does not type check
pFG3 :: forall b. Parser b > Parser (D b)
pFG3 pBArg = pBD GF AP <> pBD DF AM
where pBArg' :: Parser b
pBArg' = pBArg
pBD f p = f p <$> pBArg'
 The specifics of the parser don't matter
data Parser a = Parser
(<>) :: Parser a > Parser a > Parser a
(<>) _ _ = Parser
(<$>) :: (a > b) > Parser a > Parser b
(<$>) _ _ = Parser
```## Motivation
It seems to me that `MonoLocalBinds` is too aggressive in avoiding generalisation. Please observe the example below. In `pFG1`, `pBD` is not generalised. The reason is roughly because `pBArg` does not have a monomorphic type signature, and indeed providing one, as in `pFG2`, leads to a generalised definition.
But this seems too aggressive to me. In `pFG1` the type of `pBArg` *is* known and monomorphic. Its type occurs in the type signature of `pFG1`! Could we generalise `pBD` in this case?
This is a simplified and anonymised version of real word code. This really does happen. The cause puzzled me and I'm an experienced Haskell user. I feel bad for a less experienced colleague who might try something similar but would receive a type error for code which seems like it really ought to type check.
## Proposal
Extend [the definition of "closed"](https://downloads.haskell.org/ghc/latest/docs/html/users_guide/exts/let_generalisation.html) to encompass lambda bound variables whose type, from the explicit type signature of the lambda, is known and contains no free type variables.
## Notes
This issue was [discussed between @tomjaguarpaw1 and @rae on HaskellCafe](https://mail.haskell.org/pipermail/haskellcafe/2021February/133381.html).
I have included `pFG3` for *information only* in case anyone is curious what happens in the polymorphic case. They don't work even with an explicit type signature.
## Example
```haskell
{# LANGUAGE MonoLocalBinds #}
{# LANGUAGE ScopedTypeVariables #}
 This code came up in the context of writing a parser, but that's
 not terribly important
import Prelude hiding ((<$>))
data B = B
data D f = GF AP f
 DF AM f
data AM = AM
data AP = AP
pB :: Parser B
pB = Parser
 Does not type check
pFG1 :: Parser B > Parser (D B)
pFG1 pBArg = pBD GF AP <> pBD DF AM
where pBD f p = f p <$> pBArg
 Does type check
pFG2 :: Parser B > Parser (D B)
pFG2 pBArg = pBD GF AP <> pBD DF AM
where pBArg' :: Parser B
pBArg' = pBArg
pBD f p = f p <$> pBArg'
 Does not type check
pFG3 :: forall b. Parser b > Parser (D b)
pFG3 pBArg = pBD GF AP <> pBD DF AM
where pBArg' :: Parser b
pBArg' = pBArg
pBD f p = f p <$> pBArg'
 The specifics of the parser don't matter
data Parser a = Parser
(<>) :: Parser a > Parser a > Parser a
(<>) _ _ = Parser
(<$>) :: (a > b) > Parser a > Parser b
(<$>) _ _ = Parser
```https://gitlab.haskell.org/ghc/ghc//issues/19419GHC 9.0 unable to deduce that instance signature is at least as general as cl...20210225T03:14:03ZsheafGHC 9.0 unable to deduce that instance signature is at least as general as class signatureThe following program compiles OK on GHC 8.10 but not on GHC 9.0:
```haskell
{# LANGUAGE DataKinds #}
{# LANGUAGE InstanceSigs #}
{# LANGUAGE PolyKinds #}
{# LANGUAGE RankNTypes #}
{# LANGUAGE TypeFamilies #}
module Bug where
 base
import Data.Kind
( Constraint )

data SplineType = Open  Closed
data Curve ( clo :: SplineType ) = Curve { ... }
data Spline ( clo :: SplineType ) = Spline { ... }
class KnownSplineType ( clo :: SplineType ) where
type TraversalCt clo ( clo' :: SplineType ) :: Constraint
biwitherSpline
:: ( forall clo'. ( TraversalCt clo clo' )
=> Curve clo' > Maybe ( Curve clo' )
)
> Spline clo
> Maybe ( Spline clo )
instance KnownSplineType Open where
type TraversalCt Open clo' = clo' ~ Open
biwitherSpline
:: ( Curve Open > Maybe ( Curve Open ) )
> Spline Open
> Maybe ( Spline Open )
biwitherSpline _ _ = undefined
```
With GHC 9.0, I get the following error:
```
Bug.hs:37:8: error:
* Couldn't match type: Curve 'Open > Maybe (Curve 'Open)
with: forall (clo' :: SplineType).
TraversalCt 'Open clo' =>
Curve clo' > Maybe (Curve clo')
Expected: (forall (clo' :: SplineType).
TraversalCt 'Open clo' =>
Curve clo' > Maybe (Curve clo'))
> Spline 'Open > Maybe (Spline 'Open)
Actual: (Curve 'Open > Maybe (Curve 'Open))
> Spline 'Open > Maybe (Spline 'Open)
* When checking that instance signature for `biwitherSpline'
is more general than its signature in the class
Instance sig: (Curve 'Open > Maybe (Curve 'Open))
> Spline 'Open > Maybe (Spline 'Open)
Class sig: (forall (clo' :: SplineType).
TraversalCt 'Open clo' =>
Curve clo' > Maybe (Curve clo'))
> Spline 'Open > Maybe (Spline 'Open)
In the instance declaration for `KnownSplineType 'Open'

37  :: ( Curve Open > Maybe ( Curve Open ) )
 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^...
```
It seems that GHC 9.0 is unable to use the associated type family instance `TraversalCt Open clo' = clo' ~ Open` in checking that the instance signature is at least as general as the class signature. Is this expected, or an oversight?
Of course, changing the instance signature to the obviously correct
```haskell
biwitherSpline
:: ( forall clo'. ( TraversalCt Open clo' )
=> Curve clo' > Maybe ( Curve clo' )
)
> Spline Open
> Maybe ( Spline Open )
```
makes the program compile again, but I think the other instance signature should also be accepted.The following program compiles OK on GHC 8.10 but not on GHC 9.0:
```haskell
{# LANGUAGE DataKinds #}
{# LANGUAGE InstanceSigs #}
{# LANGUAGE PolyKinds #}
{# LANGUAGE RankNTypes #}
{# LANGUAGE TypeFamilies #}
module Bug where
 base
import Data.Kind
( Constraint )

data SplineType = Open  Closed
data Curve ( clo :: SplineType ) = Curve { ... }
data Spline ( clo :: SplineType ) = Spline { ... }
class KnownSplineType ( clo :: SplineType ) where
type TraversalCt clo ( clo' :: SplineType ) :: Constraint
biwitherSpline
:: ( forall clo'. ( TraversalCt clo clo' )
=> Curve clo' > Maybe ( Curve clo' )
)
> Spline clo
> Maybe ( Spline clo )
instance KnownSplineType Open where
type TraversalCt Open clo' = clo' ~ Open
biwitherSpline
:: ( Curve Open > Maybe ( Curve Open ) )
> Spline Open
> Maybe ( Spline Open )
biwitherSpline _ _ = undefined
```
With GHC 9.0, I get the following error:
```
Bug.hs:37:8: error:
* Couldn't match type: Curve 'Open > Maybe (Curve 'Open)
with: forall (clo' :: SplineType).
TraversalCt 'Open clo' =>
Curve clo' > Maybe (Curve clo')
Expected: (forall (clo' :: SplineType).
TraversalCt 'Open clo' =>
Curve clo' > Maybe (Curve clo'))
> Spline 'Open > Maybe (Spline 'Open)
Actual: (Curve 'Open > Maybe (Curve 'Open))
> Spline 'Open > Maybe (Spline 'Open)
* When checking that instance signature for `biwitherSpline'
is more general than its signature in the class
Instance sig: (Curve 'Open > Maybe (Curve 'Open))
> Spline 'Open > Maybe (Spline 'Open)
Class sig: (forall (clo' :: SplineType).
TraversalCt 'Open clo' =>
Curve clo' > Maybe (Curve clo'))
> Spline 'Open > Maybe (Spline 'Open)
In the instance declaration for `KnownSplineType 'Open'

37  :: ( Curve Open > Maybe ( Curve Open ) )
 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^...
```
It seems that GHC 9.0 is unable to use the associated type family instance `TraversalCt Open clo' = clo' ~ Open` in checking that the instance signature is at least as general as the class signature. Is this expected, or an oversight?
Of course, changing the instance signature to the obviously correct
```haskell
biwitherSpline
:: ( forall clo'. ( TraversalCt Open clo' )
=> Curve clo' > Maybe ( Curve clo' )
)
> Spline Open
> Maybe ( Spline Open )
```
makes the program compile again, but I think the other instance signature should also be accepted.https://gitlab.haskell.org/ghc/ghc//issues/19432GHC 9.0 rejects default signature that 8.10 accepts20210303T18:29:53ZRyan ScottGHC 9.0 rejects default signature that 8.10 acceptsI originally noticed this issue in the `barbies2.0.2.0` library on Hackage, which compiles with GHC 8.10.4 but fails to compile on GHC 9.0.1. Here is a minimized version of the code that fails to compile on 9.0.1:
```hs
{# LANGUAGE ConstraintKinds #}
{# LANGUAGE DataKinds #}
{# LANGUAGE DefaultSignatures #}
{# LANGUAGE FlexibleContexts #}
{# LANGUAGE MultiParamTypeClasses #}
{# LANGUAGE PolyKinds #}
{# LANGUAGE RankNTypes #}
{# LANGUAGE TypeApplications #}
{# LANGUAGE TypeFamilies #}
module Bug where
import Data.Coerce
import Data.Kind
import Data.Proxy
import GHC.Generics
import GHC.TypeNats
class FunctorT (t :: (k > Type) > k' > Type) where
tmap :: forall f g
. (forall a . f a > g a)
> (forall x . t f x > t g x)
 Default implementation of 'tmap' based on 'Generic'.
default tmap
:: forall f g
. (forall a . f a > g a)
> (forall x. CanDeriveFunctorT t f g x => t f x > t g x)
tmap f = toP (Proxy @1) . gmap (Proxy @1) f . fromP (Proxy @1)
type CanDeriveFunctorT t f g x
= ( GenericP 1 (t f x)
, GenericP 1 (t g x)
, GFunctor 1 f g (RepP 1 (t f x)) (RepP 1 (t g x))
)

class GFunctor (n :: Nat) f g repbf repbg where
gmap :: Proxy n > (forall a . f a > g a) > repbf x > repbg x
class
( Coercible (Rep a) (RepP n a)
, Generic a
) => GenericP (n :: Nat) (a :: Type) where
type family RepP n a :: Type > Type
toP :: Proxy n > RepP n a x > a
fromP :: Proxy n > a > RepP n a x
```
The important bit is the default signature for `tmap`. With GHC 9.0.1, this is rejected thusly:
```
$ /opt/ghc/9.0.1/bin/ghc Bug.hs
[1 of 1] Compiling Bug ( Bug.hs, Bug.o )
Bug.hs:24:11: error:
• The default type signature for tmap:
forall (f :: k > *) (g :: k > *).
(forall (a :: k). f a > g a)
> forall (x :: k'). CanDeriveFunctorT t f g x => t f x > t g x
does not match its corresponding nondefault type signature
• When checking the class method:
tmap :: forall k k' (t :: (k > *) > k' > *) (f :: k > *)
(g :: k > *).
FunctorT t =>
(forall (a :: k). f a > g a) > forall (x :: k'). t f x > t g x
In the class declaration for ‘FunctorT’

24  default tmap
 ^^^^
```
Why does GHC 9.0.1 reject this? According to the [GHC User's Guide section on `DefaultSignatures`](https://downloads.haskell.org/ghc/9.0.1/docs/html/users_guide/exts/default_signatures.html#defaultmethodsignatures):
> The type signature for a default method of a type class must take on the same form as the corresponding main method’s type signature. Otherwise, the typechecker will reject that class’s definition. By “take on the same form”, we mean that the default type signature should differ from the main type signature only in their contexts.
As far as I can tell, `tmap` meets this criterion, as the only difference between the two signatures is the presence of `CanDeriveFunctorT t f g x =>` in the default signature.I originally noticed this issue in the `barbies2.0.2.0` library on Hackage, which compiles with GHC 8.10.4 but fails to compile on GHC 9.0.1. Here is a minimized version of the code that fails to compile on 9.0.1:
```hs
{# LANGUAGE ConstraintKinds #}
{# LANGUAGE DataKinds #}
{# LANGUAGE DefaultSignatures #}
{# LANGUAGE FlexibleContexts #}
{# LANGUAGE MultiParamTypeClasses #}
{# LANGUAGE PolyKinds #}
{# LANGUAGE RankNTypes #}
{# LANGUAGE TypeApplications #}
{# LANGUAGE TypeFamilies #}
module Bug where
import Data.Coerce
import Data.Kind
import Data.Proxy
import GHC.Generics
import GHC.TypeNats
class FunctorT (t :: (k > Type) > k' > Type) where
tmap :: forall f g
. (forall a . f a > g a)
> (forall x . t f x > t g x)
 Default implementation of 'tmap' based on 'Generic'.
default tmap
:: forall f g
. (forall a . f a > g a)
> (forall x. CanDeriveFunctorT t f g x => t f x > t g x)
tmap f = toP (Proxy @1) . gmap (Proxy @1) f . fromP (Proxy @1)
type CanDeriveFunctorT t f g x
= ( GenericP 1 (t f x)
, GenericP 1 (t g x)
, GFunctor 1 f g (RepP 1 (t f x)) (RepP 1 (t g x))
)

class GFunctor (n :: Nat) f g repbf repbg where
gmap :: Proxy n > (forall a . f a > g a) > repbf x > repbg x
class
( Coercible (Rep a) (RepP n a)
, Generic a
) => GenericP (n :: Nat) (a :: Type) where
type family RepP n a :: Type > Type
toP :: Proxy n > RepP n a x > a
fromP :: Proxy n > a > RepP n a x
```
The important bit is the default signature for `tmap`. With GHC 9.0.1, this is rejected thusly:
```
$ /opt/ghc/9.0.1/bin/ghc Bug.hs
[1 of 1] Compiling Bug ( Bug.hs, Bug.o )
Bug.hs:24:11: error:
• The default type signature for tmap:
forall (f :: k > *) (g :: k > *).
(forall (a :: k). f a > g a)
> forall (x :: k'). CanDeriveFunctorT t f g x => t f x > t g x
does not match its corresponding nondefault type signature
• When checking the class method:
tmap :: forall k k' (t :: (k > *) > k' > *) (f :: k > *)
(g :: k > *).
FunctorT t =>
(forall (a :: k). f a > g a) > forall (x :: k'). t f x > t g x
In the class declaration for ‘FunctorT’

24  default tmap
 ^^^^
```
Why does GHC 9.0.1 reject this? According to the [GHC User's Guide section on `DefaultSignatures`](https://downloads.haskell.org/ghc/9.0.1/docs/html/users_guide/exts/default_signatures.html#defaultmethodsignatures):
> The type signature for a default method of a type class must take on the same form as the corresponding main method’s type signature. Otherwise, the typechecker will reject that class’s definition. By “take on the same form”, we mean that the default type signature should differ from the main type signature only in their contexts.
As far as I can tell, `tmap` meets this criterion, as the only difference between the two signatures is the presence of `CanDeriveFunctorT t f g x =>` in the default signature.https://gitlab.haskell.org/ghc/ghc//issues/19457conduit1.3.4 builds with 9.0.1, but not HEAD, due to regression in typecheck...20210309T09:59:21ZRyan Scottconduit1.3.4 builds with 9.0.1, but not HEAD, due to regression in typechecking sectionsWhile patching `head.hackage` recently, I discovered recently that the `conduit1.3.4` library fails to build on HEAD, despite compiling with 9.0.1. This is due to a typechecker regression introduced in commit 4196969c53c55191e644d9eb258c14c2bc8467da (`Improve handling of overloaded labels, literals, lists etc`). The issue concerns the way that GHC typechecks left and right sections. Here is a minimized example that illustrates the issue with a right section:
```hs
{# LANGUAGE RankNTypes #}
module Bug where
f :: a > forall b. b > a
f x _ = x
g :: a > a
g = (`f` "hello")
```
This compiles on 9.0.1, but fails on HEAD with the following error:
```
$ ~/Software/ghc9.1.20210227/bin/ghc Bug2.hs
[1 of 1] Compiling Bug2 ( Bug2.hs, Bug2.o )
Bug2.hs:8:6: error:
• Couldn't match type: forall c1. c1 > String
with: c > String
Expected: b > c > String
Actual: b > forall c. c > String
• In the expression: "hello" `j`
In an equation for ‘k’: k = ("hello" `j`)
• Relevant bindings include
k :: b > c > String (bound at Bug2.hs:8:1)

8  k = ("hello" `j`)
 ^^^^^^^^^^^
```
It's tempting to say that this should be rejected because of simplified subsumption, but that's not the full story. For one thing, 9.0.1 introduced simplified subsumption, but the code above typechecks under 9.0.1, so this is a HEADspecific phenomenon. Moreover, [Section 3.5 of the Haskell 2010 Report](https://www.haskell.org/onlinereport/haskell2010/haskellch3.html#x8300003.5) specifically requires that the following identities hold for sections:
> Translation: The following identities hold:
>
> ```hs
> (op e) = \ x > x op e
> (e op) = \ x > e op x
> ```
>
> where `op` is a binary operator, `e` is an expression, and `x` is a variable that does not occur free in `e`.
Therefore, the definition of `g` should be equivalent to:
```hs
g :: a > a
g = \x > x `f` "hello"
```
And indeed, that typechecks on both 9.0.1 and HEAD. Therefore, I'm going to deem this a regression, since the Haskell 2010 Report seems to indicate that this ought to work.
The example above uses a right section, but the same issue applies to left sections as well, as shown by this example:
```hs
{# LANGUAGE RankNTypes #}
module Bug2 where
j :: a > b > forall c. c > a
j x _ _ = x
k :: b > c > String
k = ("hello" `j`)
```
Again, this typechecks on 9.0.1 but not on HEAD:
```
$ ~/Software/ghc9.1.20210227/bin/ghc Bug2.hs
[1 of 1] Compiling Bug2 ( Bug2.hs, Bug2.o )
Bug2.hs:8:6: error:
• Couldn't match type: forall c1. c1 > String
with: c > String
Expected: b > c > String
Actual: b > forall c. c > String
• In the expression: "hello" `j`
In an equation for ‘k’: k = ("hello" `j`)
• Relevant bindings include
k :: b > c > String (bound at Bug2.hs:8:1)

8  k = ("hello" `j`)
 ^^^^^^^^^^^
```
However, the equivalent etaexpanded version of `k` typechecks on both 9.0.1 and HEAD:
```hs
k :: b > c > String
k = \x > "hello" `j` x
```
cc @simonpjWhile patching `head.hackage` recently, I discovered recently that the `conduit1.3.4` library fails to build on HEAD, despite compiling with 9.0.1. This is due to a typechecker regression introduced in commit 4196969c53c55191e644d9eb258c14c2bc8467da (`Improve handling of overloaded labels, literals, lists etc`). The issue concerns the way that GHC typechecks left and right sections. Here is a minimized example that illustrates the issue with a right section:
```hs
{# LANGUAGE RankNTypes #}
module Bug where
f :: a > forall b. b > a
f x _ = x
g :: a > a
g = (`f` "hello")
```
This compiles on 9.0.1, but fails on HEAD with the following error:
```
$ ~/Software/ghc9.1.20210227/bin/ghc Bug2.hs
[1 of 1] Compiling Bug2 ( Bug2.hs, Bug2.o )
Bug2.hs:8:6: error:
• Couldn't match type: forall c1. c1 > String
with: c > String
Expected: b > c > String
Actual: b > forall c. c > String
• In the expression: "hello" `j`
In an equation for ‘k’: k = ("hello" `j`)
• Relevant bindings include
k :: b > c > String (bound at Bug2.hs:8:1)

8  k = ("hello" `j`)
 ^^^^^^^^^^^
```
It's tempting to say that this should be rejected because of simplified subsumption, but that's not the full story. For one thing, 9.0.1 introduced simplified subsumption, but the code above typechecks under 9.0.1, so this is a HEADspecific phenomenon. Moreover, [Section 3.5 of the Haskell 2010 Report](https://www.haskell.org/onlinereport/haskell2010/haskellch3.html#x8300003.5) specifically requires that the following identities hold for sections:
> Translation: The following identities hold:
>
> ```hs
> (op e) = \ x > x op e
> (e op) = \ x > e op x
> ```
>
> where `op` is a binary operator, `e` is an expression, and `x` is a variable that does not occur free in `e`.
Therefore, the definition of `g` should be equivalent to:
```hs
g :: a > a
g = \x > x `f` "hello"
```
And indeed, that typechecks on both 9.0.1 and HEAD. Therefore, I'm going to deem this a regression, since the Haskell 2010 Report seems to indicate that this ought to work.
The example above uses a right section, but the same issue applies to left sections as well, as shown by this example:
```hs
{# LANGUAGE RankNTypes #}
module Bug2 where
j :: a > b > forall c. c > a
j x _ _ = x
k :: b > c > String
k = ("hello" `j`)
```
Again, this typechecks on 9.0.1 but not on HEAD:
```
$ ~/Software/ghc9.1.20210227/bin/ghc Bug2.hs
[1 of 1] Compiling Bug2 ( Bug2.hs, Bug2.o )
Bug2.hs:8:6: error:
• Couldn't match type: forall c1. c1 > String
with: c > String
Expected: b > c > String
Actual: b > forall c. c > String
• In the expression: "hello" `j`
In an equation for ‘k’: k = ("hello" `j`)
• Relevant bindings include
k :: b > c > String (bound at Bug2.hs:8:1)

8  k = ("hello" `j`)
 ^^^^^^^^^^^
```
However, the equivalent etaexpanded version of `k` typechecks on both 9.0.1 and HEAD:
```hs
k :: b > c > String
k = \x > "hello" `j` x
```
cc @simonpj9.2.1https://gitlab.haskell.org/ghc/ghc//issues/19495Tc trace of checkValidType panics in tcTypeKind for T16391b20210608T13:56:38ZSebastian GrafTc trace of checkValidType panics in tcTypeKind for T16391bIn https://gitlab.haskell.org/ghc/ghc//merge_requests/2218#note_335959, I triggered a panic in `tcTypeKind`. I thought that my branch was responsible, but then figured out that without `ddumptctrace`, there was no panic. Then I tried `ddumptctrace` on `T16391b`:
```hs
{# LANGUAGE DataKinds #}
{# LANGUAGE PolyKinds #}
{# LANGUAGE TypeFamilies #}
module T16391b where
import GHC.Exts
type family T (r :: RuntimeRep) :: TYPE r
foo :: T r
foo = foo
```
And sure enough, that panics on HEAD:
```
checkValidTypeghc: panic! (the 'impossible' happened)
(GHC version 9.1.20210305:
tcTypeKind
forall (r :: RuntimeRep). T r
[r_aw2[sk:2]]
T r_aw2[sk:2] :: TYPE r_aw2[sk:2]
Call stack:
CallStack (from HasCallStack):
callStackDoc, called at compiler/GHC/Utils/Panic.hs:181:37 in ghc:GHC.Utils.Panic
pprPanic, called at compiler/GHC/Core/Type.hs:2660:18 in ghc:GHC.Core.Type
```
... when `checkValidType` (I think) ultimately would have printed the following expected error:
```
T16391b.hs:10:8: error:
• Quantified type's kind mentions quantified type variable
type: ‘T 'LiftedRep’
where the body of the forall has this kind: ‘TYPE r’
• In the type signature: foo :: T r

10  foo :: T r
 ^^^
```
It's a matter of printing the error message *before* calling `tcTypeKind`:
```hs
checkValidType ctxt ty
= do { traceTc "checkValidType" (ppr ty <+> text "::" <+> ppr (tcTypeKind ty))
; rankn_flag < xoptM LangExt.RankNTypes
...
; checkNoErrs $
do { check_type ve ty
; checkUserTypeError ty
; traceTc "done ct" (ppr ty) }
...
; traceTc "checkValidType done" (ppr ty <+> text "::" <+> ppr (tcTypeKind ty)) }
```
I suggest we simply delete the ` <+> text "::" <+> ppr (tcTypeKind ty)` of the first `traceTc`.In https://gitlab.haskell.org/ghc/ghc//merge_requests/2218#note_335959, I triggered a panic in `tcTypeKind`. I thought that my branch was responsible, but then figured out that without `ddumptctrace`, there was no panic. Then I tried `ddumptctrace` on `T16391b`:
```hs
{# LANGUAGE DataKinds #}
{# LANGUAGE PolyKinds #}
{# LANGUAGE TypeFamilies #}
module T16391b where
import GHC.Exts
type family T (r :: RuntimeRep) :: TYPE r
foo :: T r
foo = foo
```
And sure enough, that panics on HEAD:
```
checkValidTypeghc: panic! (the 'impossible' happened)
(GHC version 9.1.20210305:
tcTypeKind
forall (r :: RuntimeRep). T r
[r_aw2[sk:2]]
T r_aw2[sk:2] :: TYPE r_aw2[sk:2]
Call stack:
CallStack (from HasCallStack):
callStackDoc, called at compiler/GHC/Utils/Panic.hs:181:37 in ghc:GHC.Utils.Panic
pprPanic, called at compiler/GHC/Core/Type.hs:2660:18 in ghc:GHC.Core.Type
```
... when `checkValidType` (I think) ultimately would have printed the following expected error:
```
T16391b.hs:10:8: error:
• Quantified type's kind mentions quantified type variable
type: ‘T 'LiftedRep’
where the body of the forall has this kind: ‘TYPE r’
• In the type signature: foo :: T r

10  foo :: T r
 ^^^
```
It's a matter of printing the error message *before* calling `tcTypeKind`:
```hs
checkValidType ctxt ty
= do { traceTc "checkValidType" (ppr ty <+> text "::" <+> ppr (tcTypeKind ty))
; rankn_flag < xoptM LangExt.RankNTypes
...
; checkNoErrs $
do { check_type ve ty
; checkUserTypeError ty
; traceTc "done ct" (ppr ty) }
...
; traceTc "checkValidType done" (ppr ty <+> text "::" <+> ppr (tcTypeKind ty)) }
```
I suggest we simply delete the ` <+> text "::" <+> ppr (tcTypeKind ty)` of the first `traceTc`.https://gitlab.haskell.org/ghc/ghc//issues/19498Typeclass fails to compile with StandaloneKindSignatures; only compiles with ...20210315T11:00:27ZdanidiazTypeclass fails to compile with StandaloneKindSignatures; only compiles with conventional kind annotations## Summary
A typeclass compiles correctly with conventional kind annotations, but when the kinds are given with a standalone kind signature it ceases to compile.
## Steps to reproduce
Try to compile this module:
```
{# LANGUAGE AllowAmbiguousTypes #}
{# LANGUAGE ConstraintKinds #}
{# LANGUAGE DataKinds #}
{# LANGUAGE DefaultSignatures #}
{# LANGUAGE ExplicitForAll #}
{# LANGUAGE FlexibleContexts #}
{# LANGUAGE FlexibleInstances #}
{# LANGUAGE FunctionalDependencies #}
{# LANGUAGE GADTs #}
{# LANGUAGE LambdaCase #}
{# LANGUAGE MultiParamTypeClasses #}
{# LANGUAGE PolyKinds #}
{# LANGUAGE RankNTypes #}
{# LANGUAGE ScopedTypeVariables #}
{# LANGUAGE StandaloneKindSignatures #}
{# LANGUAGE TypeApplications #}
{# LANGUAGE TypeFamilies #}
{# LANGUAGE TypeOperators #}
{# LANGUAGE UndecidableInstances #}
{# LANGUAGE UndecidableSuperClasses #}
module Main where
import Data.Kind
import Data.Proxy
import GHC.TypeLits
data Color
= R
 B
deriving (Show, Eq)
data Map symbol q
= E
 N Color (Map symbol q) symbol q (Map symbol q)
deriving (Show, Eq)
type Record :: (q > Type) > Map Symbol q > Type
data Record f t where
Empty :: Record f E
Node :: Record f left > f v > Record f right > Record f (N color left k v right)
type CanMakeBlack :: Map Symbol q > Constraint
class CanMakeBlack t where
type MakeBlack t :: Map Symbol q
makeBlackR :: Record f t > Record f (MakeBlack t)
instance CanMakeBlack (N color left k v right) where
type MakeBlack (N color left k v right) = N B left k v right
makeBlackR (Node left fv right) = Node left fv right
instance CanMakeBlack E where
type MakeBlack E = E
makeBlackR Empty = Empty
type Delable :: Symbol > q > Map Symbol q > Constraint
class Delable k v t where
 Using conventional kind annotations, it compiles correctly
class Delable (k :: Symbol) (v :: q) (t :: Map Symbol q) where
type Del k v t :: Map Symbol q
del :: Record f t > Record f (Del k v t)
type Deletable :: Symbol > q > Map Symbol q > Constraint
class Deletable (k :: Symbol) (v :: q) (t :: Map Symbol q) where
type Delete k v t :: Map Symbol q
_delete :: Record f t > Record f (Delete k v t)
instance (Delable k v t, Del k v t ~ deleted, CanMakeBlack deleted) => Deletable k v t where
type Delete k v t = MakeBlack (Del k v t)
_delete r = makeBlackR (del @_ @k @v r)
main :: IO ()
main = pure ()
```
The compilation will fail with the error:
```
Main.hs:70:15: error:
* Could not deduce: MakeBlack (Del k v t) ~ MakeBlack (Del k v t)
from the context: (Delable k v t, Del k v t ~ deleted,
CanMakeBlack deleted)
bound by the instance declaration at Main.hs:68:1086
Expected: Record f (Delete k v t)
Actual: Record f (MakeBlack (Del k v t))
NB: `MakeBlack' is a noninjective type family
```
However, if instead of the line
`class Delable k v t where`
We use the line
`class Delable (k :: Symbol) (v :: q) (t :: Map Symbol q) where`
The code compiles correctly, even if the standalone kind signature remains.
## Expected behavior
The code should compile correctly with the standalone kind signature, without need of explicit kind annotations on the variables.
## Environment
* GHC version used: 9.0.1
Optional:
* Operating System: Windows 10## Summary
A typeclass compiles correctly with conventional kind annotations, but when the kinds are given with a standalone kind signature it ceases to compile.
## Steps to reproduce
Try to compile this module:
```
{# LANGUAGE AllowAmbiguousTypes #}
{# LANGUAGE ConstraintKinds #}
{# LANGUAGE DataKinds #}
{# LANGUAGE DefaultSignatures #}
{# LANGUAGE ExplicitForAll #}
{# LANGUAGE FlexibleContexts #}
{# LANGUAGE FlexibleInstances #}
{# LANGUAGE FunctionalDependencies #}
{# LANGUAGE GADTs #}
{# LANGUAGE LambdaCase #}
{# LANGUAGE MultiParamTypeClasses #}
{# LANGUAGE PolyKinds #}
{# LANGUAGE RankNTypes #}
{# LANGUAGE ScopedTypeVariables #}
{# LANGUAGE StandaloneKindSignatures #}
{# LANGUAGE TypeApplications #}
{# LANGUAGE TypeFamilies #}
{# LANGUAGE TypeOperators #}
{# LANGUAGE UndecidableInstances #}
{# LANGUAGE UndecidableSuperClasses #}
module Main where
import Data.Kind
import Data.Proxy
import GHC.TypeLits
data Color
= R
 B
deriving (Show, Eq)
data Map symbol q
= E
 N Color (Map symbol q) symbol q (Map symbol q)
deriving (Show, Eq)
type Record :: (q > Type) > Map Symbol q > Type
data Record f t where
Empty :: Record f E
Node :: Record f left > f v > Record f right > Record f (N color left k v right)
type CanMakeBlack :: Map Symbol q > Constraint
class CanMakeBlack t where
type MakeBlack t :: Map Symbol q
makeBlackR :: Record f t > Record f (MakeBlack t)
instance CanMakeBlack (N color left k v right) where
type MakeBlack (N color left k v right) = N B left k v right
makeBlackR (Node left fv right) = Node left fv right
instance CanMakeBlack E where
type MakeBlack E = E
makeBlackR Empty = Empty
type Delable :: Symbol > q > Map Symbol q > Constraint
class Delable k v t where
 Using conventional kind annotations, it compiles correctly
class Delable (k :: Symbol) (v :: q) (t :: Map Symbol q) where
type Del k v t :: Map Symbol q
del :: Record f t > Record f (Del k v t)
type Deletable :: Symbol > q > Map Symbol q > Constraint
class Deletable (k :: Symbol) (v :: q) (t :: Map Symbol q) where
type Delete k v t :: Map Symbol q
_delete :: Record f t > Record f (Delete k v t)
instance (Delable k v t, Del k v t ~ deleted, CanMakeBlack deleted) => Deletable k v t where
type Delete k v t = MakeBlack (Del k v t)
_delete r = makeBlackR (del @_ @k @v r)
main :: IO ()
main = pure ()
```
The compilation will fail with the error:
```
Main.hs:70:15: error:
* Could not deduce: MakeBlack (Del k v t) ~ MakeBlack (Del k v t)
from the context: (Delable k v t, Del k v t ~ deleted,
CanMakeBlack deleted)
bound by the instance declaration at Main.hs:68:1086
Expected: Record f (Delete k v t)
Actual: Record f (MakeBlack (Del k v t))
NB: `MakeBlack' is a noninjective type family
```
However, if instead of the line
`class Delable k v t where`
We use the line
`class Delable (k :: Symbol) (v :: q) (t :: Map Symbol q) where`
The code compiles correctly, even if the standalone kind signature remains.
## Expected behavior
The code should compile correctly with the standalone kind signature, without need of explicit kind annotations on the variables.
## Environment
* GHC version used: 9.0.1
Optional:
* Operating System: Windows 10https://gitlab.haskell.org/ghc/ghc//issues/19522Levity monomorphic instantiation of unsafeCoerce# is rejected as being levity...20210410T11:48:54ZRyan ScottLevity monomorphic instantiation of unsafeCoerce# is rejected as being levity polymorphic in 9.0+While experimenting with `unsafeCoerce#` recently, I tried the following:
```hs
{# LANGUAGE DataKinds #}
{# LANGUAGE MagicHash #}
{# LANGUAGE TypeApplications #}
module Bug where
import GHC.Exts
import Unsafe.Coerce
f :: Int > Int
f x = unsafeCoerce# @LiftedRep @LiftedRep @Int @Int x
```
Surprisingly, GHC 9.0 and later reject this:
```
$ /opt/ghc/9.0.1/bin/ghc Bug.hs
[1 of 1] Compiling Bug ( Bug.hs, Bug.o )
Bug.hs:10:7: error:
Cannot use function with levitypolymorphic arguments:
unsafeCoerce# :: forall (q :: RuntimeRep) (r :: RuntimeRep)
(a :: TYPE q) (b :: TYPE r).
a > b
(Note that levitypolymorphic primops such as 'coerce' and unboxed tuples
are etaexpanded internally because they must occur fully saturated.
Use fprinttypecheckerelaboration to display the full expression.)
Levitypolymorphic arguments: a :: TYPE q

10  f x = unsafeCoerce# @LiftedRep @LiftedRep @Int @Int x
 ^^^^^^^^^^^^^
```
The error message confuses me, since nothing about this is levity polymorphic.
Note that this only occurs if visible type applications are used. If I remove them:
```hs
f :: Int > Int
f x = unsafeCoerce# x
```
Then GHC accepts it.While experimenting with `unsafeCoerce#` recently, I tried the following:
```hs
{# LANGUAGE DataKinds #}
{# LANGUAGE MagicHash #}
{# LANGUAGE TypeApplications #}
module Bug where
import GHC.Exts
import Unsafe.Coerce
f :: Int > Int
f x = unsafeCoerce# @LiftedRep @LiftedRep @Int @Int x
```
Surprisingly, GHC 9.0 and later reject this:
```
$ /opt/ghc/9.0.1/bin/ghc Bug.hs
[1 of 1] Compiling Bug ( Bug.hs, Bug.o )
Bug.hs:10:7: error:
Cannot use function with levitypolymorphic arguments:
unsafeCoerce# :: forall (q :: RuntimeRep) (r :: RuntimeRep)
(a :: TYPE q) (b :: TYPE r).
a > b
(Note that levitypolymorphic primops such as 'coerce' and unboxed tuples
are etaexpanded internally because they must occur fully saturated.
Use fprinttypecheckerelaboration to display the full expression.)
Levitypolymorphic arguments: a :: TYPE q

10  f x = unsafeCoerce# @LiftedRep @LiftedRep @Int @Int x
 ^^^^^^^^^^^^^
```
The error message confuses me, since nothing about this is levity polymorphic.
Note that this only occurs if visible type applications are used. If I remove them:
```hs
f :: Int > Int
f x = unsafeCoerce# x
```
Then GHC accepts it.9.0.2https://gitlab.haskell.org/ghc/ghc//issues/19548Kind generalisation without XPolyKinds leading to breakage20210317T08:07:24ZSebastian GrafKind generalisation without XPolyKinds leading to breakageThe following program is reduced from `libraries/Cabal/Cabal/src/Distribution/Utils/Path.hs`, which I didn't manage to compile with @bgamari's [buildcabal.sh script](https://gitlab.haskell.org/bgamari/ghcutils//blob/master/buildcabal.sh) today:
```hs
{# LANGUAGE DeriveDataTypeable #}
module Path where
import Data.Typeable
class Typeable a => C a where
data T a = T deriving Typeable
instance Typeable a => C (T a)
```
If compiled with HEAD (and `fprintexplicitkinds`, this errors
```
Path.hs:9:10: error:
• Could not deduce (Typeable @(*) k)
arising from the superclasses of an instance declaration
from the context: Typeable @k a
bound by the instance declaration at Path.hs:9:1030
• In the instance declaration for ‘C @{*} (T @{k} a)’

9  instance Typeable a => C (T a)
 ^^^^^^^^^^^^^^^^^^^^^
```
Apparently, `T`'s type parameter has been kind generalised. Why? I don't think `XDeriveDataTypeable` implies `XPolyKinds`.
Yet the error message mentions an implicit kind `k` that appears nowhere else in the program.The following program is reduced from `libraries/Cabal/Cabal/src/Distribution/Utils/Path.hs`, which I didn't manage to compile with @bgamari's [buildcabal.sh script](https://gitlab.haskell.org/bgamari/ghcutils//blob/master/buildcabal.sh) today:
```hs
{# LANGUAGE DeriveDataTypeable #}
module Path where
import Data.Typeable
class Typeable a => C a where
data T a = T deriving Typeable
instance Typeable a => C (T a)
```
If compiled with HEAD (and `fprintexplicitkinds`, this errors
```
Path.hs:9:10: error:
• Could not deduce (Typeable @(*) k)
arising from the superclasses of an instance declaration
from the context: Typeable @k a
bound by the instance declaration at Path.hs:9:1030
• In the instance declaration for ‘C @{*} (T @{k} a)’

9  instance Typeable a => C (T a)
 ^^^^^^^^^^^^^^^^^^^^^
```
Apparently, `T`'s type parameter has been kind generalised. Why? I don't think `XDeriveDataTypeable` implies `XPolyKinds`.
Yet the error message mentions an implicit kind `k` that appears nowhere else in the program.https://gitlab.haskell.org/ghc/ghc//issues/19565`plots` fails to typechecking in 9.220210319T23:36:40ZBen Gamari`plots` fails to typechecking in 9.2When updating `head.hackage` for 9.2, I noticed that `plots` now fails to typecheck,
```
src/Plots/Types.hs:697:17: error:
• Reduction stack overflow; size = 201
When simplifying the following type: V p1
Use freductiondepth=0 to disable this check
(any upper bound you could choose might fail unpredictably with
minor updates to GHC, so disabling the check is recommended if
you're sure that type checking should terminate)
• In the pattern: StyledPlot p opts sty
In an equation for ‘styledPlot’:
styledPlot f s@(StyledPlot p opts sty)
= case eq p of
Just Refl > f p <&> \ p' > StyledPlot p' opts sty
Nothing > pure s
where
eq :: Typeable a => a > Maybe (a :~: p)
eq _ = eqT

697  styledPlot f s@(StyledPlot p opts sty) =
 ^^^^^^^^^^^^^^^^^^^^^
```
I haven't tried lifting the reduction depth yet.When updating `head.hackage` for 9.2, I noticed that `plots` now fails to typecheck,
```
src/Plots/Types.hs:697:17: error:
• Reduction stack overflow; size = 201
When simplifying the following type: V p1
Use freductiondepth=0 to disable this check
(any upper bound you could choose might fail unpredictably with
minor updates to GHC, so disabling the check is recommended if
you're sure that type checking should terminate)
• In the pattern: StyledPlot p opts sty
In an equation for ‘styledPlot’:
styledPlot f s@(StyledPlot p opts sty)
= case eq p of
Just Refl > f p <&> \ p' > StyledPlot p' opts sty
Nothing > pure s
where
eq :: Typeable a => a > Maybe (a :~: p)
eq _ = eqT

697  styledPlot f s@(StyledPlot p opts sty) =
 ^^^^^^^^^^^^^^^^^^^^^
```
I haven't tried lifting the reduction depth yet.9.2.1https://gitlab.haskell.org/ghc/ghc//issues/19668Exponential blowup in T9198 (regresssion from 8.10 and 9.0)20210512T22:30:54ZvdukhovniExponential blowup in T9198 (regresssion from 8.10 and 9.0)## Summary
The T9198 test is showing rather unstable metrics in head, but the real issue is not the wobbly numbers but the scale. In GHC 8.10.4 and 9.0.1, adding more continuation terms results in linear cost increases, but with head the cost doubles with every term, as reported in https://gitlab.haskell.org/ghc/ghc//merge_requests/4890#note_343948
## Steps to reproduce
Compile `testsuite/tests/perf/compiler/T9198.hs` with `+RTS s` with varying numbers of additional `a` continuation terms. The GHC runtime and memory allocation grow exponentially. The same is not observed with GHC 8.10.4 for example.
## Expected behavior
Linear cost. With 8.10.4 and the continuation count unmodified I get:
```
$ ghc O fasm testsuite/tests/perf/compiler/T9198.hs +RTS s
116,102,480 bytes allocated in the heap
...
MUT time 0.069s ( 0.572s elapsed)
GC time 0.111s ( 0.111s elapsed)
Total time 0.181s ( 0.689s elapsed)
```
With head I get:
```
514,989,696 bytes allocated in the heap
...
MUT time 0.212s ( 0.604s elapsed)
GC time 0.366s ( 0.366s elapsed)
Total time 0.581s ( 0.979s elapsed)
```
## Environment
* GHC version used: head (9.1.20210402)## Summary
The T9198 test is showing rather unstable metrics in head, but the real issue is not the wobbly numbers but the scale. In GHC 8.10.4 and 9.0.1, adding more continuation terms results in linear cost increases, but with head the cost doubles with every term, as reported in https://gitlab.haskell.org/ghc/ghc//merge_requests/4890#note_343948
## Steps to reproduce
Compile `testsuite/tests/perf/compiler/T9198.hs` with `+RTS s` with varying numbers of additional `a` continuation terms. The GHC runtime and memory allocation grow exponentially. The same is not observed with GHC 8.10.4 for example.
## Expected behavior
Linear cost. With 8.10.4 and the continuation count unmodified I get:
```
$ ghc O fasm testsuite/tests/perf/compiler/T9198.hs +RTS s
116,102,480 bytes allocated in the heap
...
MUT time 0.069s ( 0.572s elapsed)
GC time 0.111s ( 0.111s elapsed)
Total time 0.181s ( 0.689s elapsed)
```
With head I get:
```
514,989,696 bytes allocated in the heap
...
MUT time 0.212s ( 0.604s elapsed)
GC time 0.366s ( 0.366s elapsed)
Total time 0.581s ( 0.979s elapsed)
```
## Environment
* GHC version used: head (9.1.20210402)9.2.1Matthew PickeringMatthew Pickeringhttps://gitlab.haskell.org/ghc/ghc//issues/19728GHC 9.0+ fails to combine levitypolymorphic newtype constructor with TypeApp...20210422T18:08:29ZRyan ScottGHC 9.0+ fails to combine levitypolymorphic newtype constructor with TypeApplicationsGHC 8.10.4 has no problem typechecking this program:
```hs
{# LANGUAGE DataKinds #}
{# LANGUAGE GADTs #}
{# LANGUAGE PolyKinds #}
{# LANGUAGE ScopedTypeVariables #}
{# LANGUAGE StandaloneKindSignatures #}
{# LANGUAGE TypeApplications #}
{# LANGUAGE UnliftedNewtypes #}
module Bug where
import GHC.Exts
type Id :: TYPE r > TYPE r
newtype Id a where
MkId :: forall r (a :: TYPE r). a > Id a
idBool :: Id Bool
idBool = MkId @LiftedRep @Bool True
```
However, GHC 9.0.1 and later fail with:
```
$ /opt/ghc/9.0.1/bin/ghc Bug.hs
[1 of 1] Compiling Bug ( Bug.hs, Bug.o )
Bug.hs:17:10: error:
• Cannot apply expression of type ‘a0 > Id a0’
to a visible type argument ‘LiftedRep’
• In the expression: MkId @LiftedRep @Bool True
In an equation for ‘idBool’: idBool = MkId @LiftedRep @Bool True

17  idBool = MkId @LiftedRep @Bool True
 ^^^^^^^^^^^^^^^^^^^^^^^^^^
```
As far as I can tell, this program should be expected to typecheck, so I believe this is a regression.GHC 8.10.4 has no problem typechecking this program:
```hs
{# LANGUAGE DataKinds #}
{# LANGUAGE GADTs #}
{# LANGUAGE PolyKinds #}
{# LANGUAGE ScopedTypeVariables #}
{# LANGUAGE StandaloneKindSignatures #}
{# LANGUAGE TypeApplications #}
{# LANGUAGE UnliftedNewtypes #}
module Bug where
import GHC.Exts
type Id :: TYPE r > TYPE r
newtype Id a where
MkId :: forall r (a :: TYPE r). a > Id a
idBool :: Id Bool
idBool = MkId @LiftedRep @Bool True
```
However, GHC 9.0.1 and later fail with:
```
$ /opt/ghc/9.0.1/bin/ghc Bug.hs
[1 of 1] Compiling Bug ( Bug.hs, Bug.o )
Bug.hs:17:10: error:
• Cannot apply expression of type ‘a0 > Id a0’
to a visible type argument ‘LiftedRep’
• In the expression: MkId @LiftedRep @Bool True
In an equation for ‘idBool’: idBool = MkId @LiftedRep @Bool True

17  idBool = MkId @LiftedRep @Bool True
 ^^^^^^^^^^^^^^^^^^^^^^^^^^
```
As far as I can tell, this program should be expected to typecheck, so I believe this is a regression.