GHC issueshttps://gitlab.haskell.org/ghc/ghc/-/issues2019-07-07T19:03:42Zhttps://gitlab.haskell.org/ghc/ghc/-/issues/3476Compiler warning about non-exhaustive pattern match with GADT and type-signature2019-07-07T19:03:42ZAshley YakeleyCompiler warning about non-exhaustive pattern match with GADT and type-signatureThis program:
```
{-# OPTIONS -Wall #-}
{-# LANGUAGE GADTs #-}
module Bug where
data T n where
BoolT :: T Bool
IntT :: T Int
f :: T Bool -> Int
f BoolT = 3
```
1. ..gives this warning
```
$ ghc -c Bug.hs...This program:
```
{-# OPTIONS -Wall #-}
{-# LANGUAGE GADTs #-}
module Bug where
data T n where
BoolT :: T Bool
IntT :: T Int
f :: T Bool -> Int
f BoolT = 3
```
1. ..gives this warning
```
$ ghc -c Bug.hs
Bug.hs:10:4:
Warning: Pattern match(es) are non-exhaustive
In the definition of `f': Patterns not matched: IntT
```
The pattern match is, in fact, exhaustive, given the type signature.
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | ----------------------- |
| Version | 6.10.4 |
| 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":"Compiler warning about non-exhaustive pattern match with GADT and type-signature","status":"New","operating_system":"","component":"Compiler (Type checker)","related":[],"milestone":"","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"6.10.4","keywords":[],"differentials":[],"test_case":"","architecture":"","cc":[""],"type":"Bug","description":"This program:\r\n{{{\r\n{-# OPTIONS -Wall #-}\r\n{-# LANGUAGE GADTs #-}\r\nmodule Bug where\r\n\r\n data T n where\r\n BoolT :: T Bool\r\n IntT :: T Int\r\n \r\n f :: T Bool -> Int\r\n f BoolT = 3\r\n}}}\r\n...gives this warning\r\n{{{\r\n$ ghc -c Bug.hs \r\n\r\nBug.hs:10:4:\r\n Warning: Pattern match(es) are non-exhaustive\r\n In the definition of `f': Patterns not matched: IntT\r\n}}}\r\nThe pattern match is, in fact, exhaustive, given the type signature.","type_of_failure":"OtherFailure","blocking":[]} -->https://gitlab.haskell.org/ghc/ghc/-/issues/3383Confluent type family instances confuse the solver2019-07-07T19:04:08ZMiƫtek BakConfluent type family instances confuse the solverWhile attempting to define integer arithmetic using type families, I encountered a problem with the type checker failing to recognize equivalent types:
```
{-# LANGUAGE EmptyDataDecls, TypeFamilies #-}
module WithBug where
data Z
data...While attempting to define integer arithmetic using type families, I encountered a problem with the type checker failing to recognize equivalent types:
```
{-# LANGUAGE EmptyDataDecls, TypeFamilies #-}
module WithBug where
data Z
data S a
data P a b
type family N a
type instance N (P Z a) = P Z a
type instance N (P a Z) = P a Z -- with bug
type instance N (P (S a) (S b)) = N (P a b)
```
```
$ ghci WithBug
*WithBug> :t (undefined :: N (P Z Z)) :: P Z Z
<interactive>:1:1:
Couldn't match expected type `P Z Z'
against inferred type `N (P Z Z)'
In the expression: (undefined :: N (P Z Z)) :: P Z Z
```
Rewriting the problematic instance fixed the problem:
```
{-# LANGUAGE EmptyDataDecls, TypeFamilies #-}
module WithoutBug where
data Z
data S a
data P a b
type family N a
type instance N (P Z a) = P Z a
type instance N (P (S a) Z) = P (S a) Z -- without bug
type instance N (P (S a) (S b)) = N (P a b)
```
```
$ ghci WithoutBug
*WithoutBug> :t (undefined :: N (P Z Z)) :: P Z Z
(undefined :: N (P Z Z)) :: P Z Z :: P Z Z
```
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | ----------------------- |
| Version | 6.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":"Confluent type instances confuse the solver","status":"New","operating_system":"","component":"Compiler (Type checker)","related":[],"milestone":"","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"6.10.3","keywords":["families","family","instance","instances","type"],"differentials":[],"test_case":"","architecture":"","cc":[""],"type":"Bug","description":"While attempting to define integer arithmetic using type families, I encountered a problem with the type checker failing to recognize equivalent types:\r\n\r\n{{{\r\n{-# LANGUAGE EmptyDataDecls, TypeFamilies #-}\r\n\r\nmodule WithBug where\r\n\r\ndata Z\r\ndata S a\r\ndata P a b\r\n\r\ntype family N a\r\n\r\ntype instance N (P Z a) = P Z a\r\ntype instance N (P a Z) = P a Z -- with bug\r\ntype instance N (P (S a) (S b)) = N (P a b)\r\n}}}\r\n\r\n{{{\r\n$ ghci WithBug\r\n*WithBug> :t (undefined :: N (P Z Z)) :: P Z Z\r\n<interactive>:1:1:\r\n Couldn't match expected type `P Z Z'\r\n against inferred type `N (P Z Z)'\r\n In the expression: (undefined :: N (P Z Z)) :: P Z Z\r\n}}}\r\n\r\nRewriting the problematic instance fixed the problem:\r\n\r\n{{{\r\n{-# LANGUAGE EmptyDataDecls, TypeFamilies #-}\r\n\r\nmodule WithoutBug where\r\n\r\ndata Z\r\ndata S a\r\ndata P a b\r\n\r\ntype family N a\r\n\r\ntype instance N (P Z a) = P Z a\r\ntype instance N (P (S a) Z) = P (S a) Z -- without bug\r\ntype instance N (P (S a) (S b)) = N (P a b)\r\n}}}\r\n\r\n{{{\r\n$ ghci WithoutBug\r\n*WithoutBug> :t (undefined :: N (P Z Z)) :: P Z Z\r\n(undefined :: N (P Z Z)) :: P Z Z :: P Z Z\r\n}}}\r\n","type_of_failure":"OtherFailure","blocking":[]} -->https://gitlab.haskell.org/ghc/ghc/-/issues/3330Type checker hangs2019-07-07T19:04:23ZMartijnVanSteenbergenType checker hangsThe following module causes `ghc --make` and `ghci` to hang. `-ddump-tc-trace` produces output indefinitely.
```
{-# LANGUAGE GADTs #-}
{-# LANGUAGE FlexibleContexts #-}
import Generics.MultiRec
import Control.Monad.Writer
data AnyF s...The following module causes `ghc --make` and `ghci` to hang. `-ddump-tc-trace` produces output indefinitely.
```
{-# LANGUAGE GADTs #-}
{-# LANGUAGE FlexibleContexts #-}
import Generics.MultiRec
import Control.Monad.Writer
data AnyF s f where
AnyF :: s ix -> f ix -> AnyF s f
children :: HFunctor s (PF s) => s ix -> (PF s) r ix -> [AnyF s r]
children p x = execWriter (hmapM p collect x) where
collect :: (HFunctor s (PF s)) => s ix -> r ix -> Writer [AnyF s r] (r ix)
collect w x = tell [AnyF w x] >> return x
```
Module `Generics.MultiRec` is from Hackage package `multirec-0.4`.
The code contains a type error: if arguments `p` and `collect` are swapped the code compiles fine.
I haven't tried making this example any smaller.
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | ----------------------- |
| Version | 6.10.1 |
| Type | Bug |
| TypeOfFailure | OtherFailure |
| Priority | normal |
| Resolution | Unresolved |
| Component | Compiler (Type checker) |
| Test case | |
| Differential revisions | |
| BlockedBy | |
| Related | |
| Blocking | |
| CC | |
| Operating system | Unknown/Multiple |
| Architecture | Unknown/Multiple |
</details>
<!-- {"blocked_by":[],"summary":"Type checker hangs","status":"New","operating_system":"Unknown/Multiple","component":"Compiler (Type checker)","related":[],"milestone":"","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"6.10.1","keywords":[],"differentials":[],"test_case":"","architecture":"Unknown/Multiple","cc":[""],"type":"Bug","description":"The following module causes `ghc --make` and `ghci` to hang. `-ddump-tc-trace` produces output indefinitely.\r\n\r\n{{{\r\n{-# LANGUAGE GADTs #-}\r\n{-# LANGUAGE FlexibleContexts #-}\r\n\r\nimport Generics.MultiRec\r\nimport Control.Monad.Writer\r\n\r\ndata AnyF s f where\r\n AnyF :: s ix -> f ix -> AnyF s f\r\n\r\nchildren :: HFunctor s (PF s) => s ix -> (PF s) r ix -> [AnyF s r]\r\nchildren p x = execWriter (hmapM p collect x) where\r\n collect :: (HFunctor s (PF s)) => s ix -> r ix -> Writer [AnyF s r] (r ix)\r\n collect w x = tell [AnyF w x] >> return x\r\n}}}\r\n\r\nModule `Generics.MultiRec` is from Hackage package `multirec-0.4`.\r\n\r\nThe code contains a type error: if arguments `p` and `collect` are swapped the code compiles fine.\r\n\r\nI haven't tried making this example any smaller.\r\n","type_of_failure":"OtherFailure","blocking":[]} -->Manuel M T ChakravartyManuel M T Chakravartyhttps://gitlab.haskell.org/ghc/ghc/-/issues/3323panic: funArgTy2019-07-07T19:04:25ZSimon Marlowpanic: funArgTyThe following module crashes GHC 6.11.20090615:
```
module V where
import GHC.IO.Handle.Types
import GHC.IO.Handle.Internals
f :: Handle -> IO ()
f hdl = withHandle_ "" hdl $ \h -> return h{haDevice=undefined}
```
results:
```
$ ghc...The following module crashes GHC 6.11.20090615:
```
module V where
import GHC.IO.Handle.Types
import GHC.IO.Handle.Internals
f :: Handle -> IO ()
f hdl = withHandle_ "" hdl $ \h -> return h{haDevice=undefined}
```
results:
```
$ ghc-testing2 --make V.hs
[1 of 1] Compiling V ( V.hs, V.o )
ghc-stage2: panic! (the 'impossible' happened)
(GHC version 6.11.20090615 for x86_64-unknown-linux):
funArgTy ghc-prim:GHC.Unit.(){(w) tc 40}
```
It imports some internals of the IO library; I tried to reproduce it with a completely standalone module, but failed. The field `haDevice` of `Handle__` has existential type - normally GHC rejects a record update when the field has existential type, but does not in this case, I'm not sure why.
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | ----------------------- |
| Version | 6.11 |
| Type | Bug |
| TypeOfFailure | OtherFailure |
| Priority | normal |
| Resolution | Unresolved |
| Component | Compiler (Type checker) |
| Test case | |
| Differential revisions | |
| BlockedBy | |
| Related | |
| Blocking | |
| CC | |
| Operating system | |
| Architecture | |
</details>
<!-- {"blocked_by":[],"summary":"panic: funArgTy","status":"New","operating_system":"","component":"Compiler (Type checker)","related":[],"milestone":"6.12.1","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"6.11","keywords":[],"differentials":[],"test_case":"","architecture":"","cc":[""],"type":"Bug","description":"The following module crashes GHC 6.11.20090615:\r\n\r\n{{{\r\nmodule V where\r\n\r\nimport GHC.IO.Handle.Types\r\nimport GHC.IO.Handle.Internals\r\n\r\nf :: Handle -> IO ()\r\nf hdl = withHandle_ \"\" hdl $ \\h -> return h{haDevice=undefined}\r\n}}}\r\n\r\nresults:\r\n\r\n{{{\r\n$ ghc-testing2 --make V.hs\r\n[1 of 1] Compiling V ( V.hs, V.o )\r\nghc-stage2: panic! (the 'impossible' happened)\r\n (GHC version 6.11.20090615 for x86_64-unknown-linux):\r\n funArgTy ghc-prim:GHC.Unit.(){(w) tc 40}\r\n}}}\r\n\r\nIt imports some internals of the IO library; I tried to reproduce it with a completely standalone module, but failed. The field `haDevice` of `Handle__` has existential type - normally GHC rejects a record update when the field has existential type, but does not in this case, I'm not sure why.\r\n","type_of_failure":"OtherFailure","blocking":[]} -->6.12.1Simon Peyton JonesSimon Peyton Joneshttps://gitlab.haskell.org/ghc/ghc/-/issues/3272GHC panics when contexts are put late in function types2019-07-07T19:04:39ZdmwitGHC panics when contexts are put late in function typesHere's a simple transcript from ghci:
```
Prelude> :m + Data.List
Prelude Data.List> :t genericLength :: [a] -> Num b => b
ghc: panic! (the 'impossible' happened)
(GHC version 6.10.3 for x86_64-unknown-linux):
TcTyFuns.flattenType: u...Here's a simple transcript from ghci:
```
Prelude> :m + Data.List
Prelude Data.List> :t genericLength :: [a] -> Num b => b
ghc: panic! (the 'impossible' happened)
(GHC version 6.10.3 for x86_64-unknown-linux):
TcTyFuns.flattenType: unexpected PredType
Please report this as a GHC bug: http://www.haskell.org/ghc/reportabug
```
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | ----------------------- |
| Version | 6.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 panics when contexts are put late in function types","status":"New","operating_system":"","component":"Compiler (Type checker)","related":[],"milestone":"","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"6.10.3","keywords":[],"differentials":[],"test_case":"","architecture":"","cc":[""],"type":"Bug","description":"Here's a simple transcript from ghci:\r\n{{{\r\nPrelude> :m + Data.List\r\nPrelude Data.List> :t genericLength :: [a] -> Num b => b\r\nghc: panic! (the 'impossible' happened)\r\n (GHC version 6.10.3 for x86_64-unknown-linux):\r\n\tTcTyFuns.flattenType: unexpected PredType\r\n\r\nPlease report this as a GHC bug: http://www.haskell.org/ghc/reportabug\r\n}}}","type_of_failure":"OtherFailure","blocking":[]} -->6.12.1https://gitlab.haskell.org/ghc/ghc/-/issues/3244Associated type panic2019-07-07T19:04:45Zred5_2@hotmail.comAssociated type panicGHC panics with the attached use of associated types. Curiously, if I flatten the nested let-clauses in 'foo', the error goes away.
```
ghc: panic! (the 'impossible' happened)
(GHC version 6.10.1 for x86_64-unknown-linux):
ini...GHC panics with the attached use of associated types. Curiously, if I flatten the nested let-clauses in 'foo', the error goes away.
```
ghc: panic! (the 'impossible' happened)
(GHC version 6.10.1 for x86_64-unknown-linux):
initC: srt_lbl
```
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | ----------------------- |
| Version | 6.10.1 |
| Type | Bug |
| TypeOfFailure | OtherFailure |
| Priority | normal |
| Resolution | Unresolved |
| Component | Compiler (Type checker) |
| Test case | |
| Differential revisions | |
| BlockedBy | |
| Related | |
| Blocking | |
| CC | |
| Operating system | |
| Architecture | |
</details>
<!-- {"blocked_by":[],"summary":"Associated type panic","status":"New","operating_system":"","component":"Compiler (Type checker)","related":[],"milestone":"","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"6.10.1","keywords":["family","type"],"differentials":[],"test_case":"","architecture":"","cc":[""],"type":"Bug","description":"GHC panics with the attached use of associated types. Curiously, if I flatten the nested let-clauses in 'foo', the error goes away.\r\n\r\n{{{\r\nghc: panic! (the 'impossible' happened)\r\n (GHC version 6.10.1 for x86_64-unknown-linux):\r\n initC: srt_lbl\r\n}}}","type_of_failure":"OtherFailure","blocking":[]} -->https://gitlab.haskell.org/ghc/ghc/-/issues/3220type variables appearing only in type equality constraints are not generalized2019-07-07T19:04:50Zguesttype variables appearing only in type equality constraints are not generalized```
{-# LANGUAGE TypeFamilies, ScopedTypeVariables#-}
class Foo m where
type Bar m :: *
action :: m -> Bar m -> m
right x m = action m (Right x)
right' :: (Either a b ~ Bar m, Foo m) => b -> m -> m
right' x m = action m (Right...```
{-# LANGUAGE TypeFamilies, ScopedTypeVariables#-}
class Foo m where
type Bar m :: *
action :: m -> Bar m -> m
right x m = action m (Right x)
right' :: (Either a b ~ Bar m, Foo m) => b -> m -> m
right' x m = action m (Right x)
instance Foo Int where
type Bar Int = Either Int Int
action m a = either (*) (+) a m
main = print $ right (1::Int) (3 :: Int)
```
with the above code i get:
```
*Main> :type right
right :: (Either Int b ~ Bar m, Foo m) => b -> m -> m
```
without the main definition i get instead:
```
*Main> :t right
right :: (Either GHC.Prim.Any b ~ Bar m, Foo m) => b -> m -> m
```
while i expect the correct type to be the one of right'.
It looks related to bug #1813
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | ----------------------- |
| Version | 6.10.2 |
| Type | Bug |
| TypeOfFailure | OtherFailure |
| Priority | normal |
| Resolution | Unresolved |
| Component | Compiler (Type checker) |
| Test case | |
| Differential revisions | |
| BlockedBy | |
| Related | |
| Blocking | |
| CC | sanzhiyan@gmail.com |
| Operating system | |
| Architecture | |
</details>
<!-- {"blocked_by":[],"summary":"type variables appearing only in type equality constraints are not generalized","status":"New","operating_system":"","component":"Compiler (Type checker)","related":[],"milestone":"","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"6.10.2","keywords":[],"differentials":[],"test_case":"","architecture":"","cc":["sanzhiyan@gmail.com"],"type":"Bug","description":"{{{\r\n{-# LANGUAGE TypeFamilies, ScopedTypeVariables#-}\r\n\r\nclass Foo m where\r\n type Bar m :: *\r\n action :: m -> Bar m -> m\r\n\r\nright x m = action m (Right x)\r\n\r\nright' :: (Either a b ~ Bar m, Foo m) => b -> m -> m\r\nright' x m = action m (Right x)\r\n\r\ninstance Foo Int where\r\n type Bar Int = Either Int Int\r\n action m a = either (*) (+) a m\r\n\r\nmain = print $ right (1::Int) (3 :: Int)\r\n}}}\r\nwith the above code i get:\r\n{{{\r\n*Main> :type right\r\n \r\nright :: (Either Int b ~ Bar m, Foo m) => b -> m -> m\r\n}}}\r\nwithout the main definition i get instead:\r\n{{{\r\n*Main> :t right\r\nright :: (Either GHC.Prim.Any b ~ Bar m, Foo m) => b -> m -> m\r\n}}}\r\n\r\nwhile i expect the correct type to be the one of right'.\r\nIt looks related to bug #1813\r\n\r\n","type_of_failure":"OtherFailure","blocking":[]} -->6.12.1https://gitlab.haskell.org/ghc/ghc/-/issues/3219functions on records with overloaded names can be given a too-specific type2019-07-07T19:04:50Zdmwitfunctions on records with overloaded names can be given a too-specific typeHere's a reduced test-case showing a discrepancy between the symmetric functions `foo` and `bar`; the inferred type for `foo` is too specific.
```
data T a = A{ m1 :: a } | B{ m1, m2 :: a } | C{ m2 :: a }
-- bar :: (t -> a) -> T t -> T...Here's a reduced test-case showing a discrepancy between the symmetric functions `foo` and `bar`; the inferred type for `foo` is too specific.
```
data T a = A{ m1 :: a } | B{ m1, m2 :: a } | C{ m2 :: a }
-- bar :: (t -> a) -> T t -> T a
bar f x@(A m) = x{m1 = f m}
-- foo :: (a -> a) -> T a -> T a
foo f x@(C m) = x{m2 = f m}
```
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | ----------------------- |
| Version | 6.10.1 |
| Type | Bug |
| TypeOfFailure | OtherFailure |
| Priority | normal |
| Resolution | Unresolved |
| Component | Compiler (Type checker) |
| Test case | |
| Differential revisions | |
| BlockedBy | |
| Related | |
| Blocking | |
| CC | |
| Operating system | |
| Architecture | |
</details>
<!-- {"blocked_by":[],"summary":"functions on records with overloaded names can be given a too-specific type","status":"New","operating_system":"","component":"Compiler (Type checker)","related":[],"milestone":"","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"6.10.1","keywords":[],"differentials":[],"test_case":"","architecture":"","cc":[""],"type":"Bug","description":"Here's a reduced test-case showing a discrepancy between the symmetric functions `foo` and `bar`; the inferred type for `foo` is too specific.\r\n\r\n{{{\r\ndata T a = A{ m1 :: a } | B{ m1, m2 :: a } | C{ m2 :: a }\r\n\r\n-- bar :: (t -> a) -> T t -> T a\r\nbar f x@(A m) = x{m1 = f m}\r\n\r\n-- foo :: (a -> a) -> T a -> T a\r\nfoo f x@(C m) = x{m2 = f m}\r\n}}}","type_of_failure":"OtherFailure","blocking":[]} -->https://gitlab.haskell.org/ghc/ghc/-/issues/3197disambiguating type family instances with qualified names not possible2019-07-07T19:04:56Zclaus.reinke@talk21.comdisambiguating type family instances with qualified names not possibleWhile reading [1](http://www.haskell.org/pipermail/haskell-cafe/2009-April/060665.html), it occured to me that type families could be used to parameterize modules by types. So I modified my example from [2](http://www.haskell.org/piperma...While reading [1](http://www.haskell.org/pipermail/haskell-cafe/2009-April/060665.html), it occured to me that type families could be used to parameterize modules by types. So I modified my example from [2](http://www.haskell.org/pipermail/haskell-cafe/2009-April/060324.html), trying to parameterize two modules `A` and `B` with a shared type `Label` (sharing expressed in `C)`, but ran into a few issues:
```
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE EmptyDataDecls #-}
module LA where
data MyLabel
y = undefined::MyLabel
type family Label a
z = undefined::Label ()
```
```
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE EmptyDataDecls #-}
module LB where
data MyLabel
y = undefined::MyLabel
type family Label a
z = undefined::Label ()
```
```
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE TypeFamilies #-}
module LC where
import LA
import LB
-- fails = [LA.y,LB.y]
-- express type sharing while leaving actual type open
type family Label a
type instance LA.Label a = LC.Label a
type instance LB.Label a = LC.Label a
ok2 = [LA.z,LB.z]
-- for testing only
-- type instance Label a = () -- can't use with or without qualifier:-(
```
Issues:
- is it really necessary for type families to have at least one index? Without that, type constants could be expressed directly
- uncommenting that last line demonstrates a couple of bugs:
- as it stands, the type instance is ambiguous, but the error message has an incorrect source location (`1:0`)
- trying to disambiguate by defining `type instance LC.Label` results in : "Qualified name in binding position: LC.Label" (note that this is permitted a couple of lines up, so it is related to whether the qualifier refers to the current module or an imported one)
\[the bug is not really in the type checker, but specific to type families..\]
Bug aside, it works (`length ok2` gives two, not an error, as `fail` would).
This could be a useful type family programming pattern (it is probably implicit in the comparisons of SML functors vs Haskell type classes/families, I just don't recall it being made so explicit before, just focussing on type parameterization and sharing)!-)
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | ----------------------- |
| Version | 6.11 |
| 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":"disambiguating type family instances with qualified names not possible","status":"New","operating_system":"","component":"Compiler (Type checker)","related":[],"milestone":"","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"6.11","keywords":[],"differentials":[],"test_case":"","architecture":"","cc":[""],"type":"Bug","description":"While reading [http://www.haskell.org/pipermail/haskell-cafe/2009-April/060665.html 1], it occured to me that type families could be used to parameterize modules by types. So I modified my example from [http://www.haskell.org/pipermail/haskell-cafe/2009-April/060324.html 2], trying to parameterize two modules `A` and `B` with a shared type `Label` (sharing expressed in `C)`, but ran into a few issues:\r\n{{{\r\n{-# LANGUAGE TypeFamilies #-}\r\n{-# LANGUAGE EmptyDataDecls #-}\r\nmodule LA where \r\ndata MyLabel\r\ny = undefined::MyLabel\r\n\r\ntype family Label a\r\nz = undefined::Label ()\r\n}}}\r\n{{{\r\n{-# LANGUAGE TypeFamilies #-}\r\n{-# LANGUAGE EmptyDataDecls #-}\r\nmodule LB where \r\ndata MyLabel\r\ny = undefined::MyLabel\r\n\r\ntype family Label a\r\nz = undefined::Label ()\r\n}}}\r\n{{{\r\n{-# LANGUAGE UndecidableInstances #-}\r\n{-# LANGUAGE TypeFamilies #-}\r\nmodule LC where\r\nimport LA\r\nimport LB\r\n\r\n-- fails = [LA.y,LB.y]\r\n\r\n-- express type sharing while leaving actual type open\r\ntype family Label a\r\ntype instance LA.Label a = LC.Label a\r\ntype instance LB.Label a = LC.Label a\r\nok2 = [LA.z,LB.z]\r\n\r\n-- for testing only\r\n-- type instance Label a = () -- can't use with or without qualifier:-(\r\n}}}\r\nIssues:\r\n - is it really necessary for type families to have at least one index? Without that, type constants could be expressed directly\r\n\r\n - uncommenting that last line demonstrates a couple of bugs: \r\n\r\n * as it stands, the type instance is ambiguous, but the error message has an incorrect source location (`1:0`)\r\n\r\n * trying to disambiguate by defining `type instance LC.Label` results in : \"Qualified name in binding position: LC.Label\" (note that this is permitted a couple of lines up, so it is related to whether the qualifier refers to the current module or an imported one)\r\n\r\n[the bug is not really in the type checker, but specific to type families..]\r\n\r\nBug aside, it works (`length ok2` gives two, not an error, as `fail` would). \r\n\r\nThis could be a useful type family programming pattern (it is probably implicit in the comparisons of SML functors vs Haskell type classes/families, I just don't recall it being made so explicit before, just focussing on type parameterization and sharing)!-)","type_of_failure":"OtherFailure","blocking":[]} -->6.12.1https://gitlab.haskell.org/ghc/ghc/-/issues/3190Type checker fails to unify/expand type definitions in certain contexts2019-07-07T19:04:58ZferridderType checker fails to unify/expand type definitions in certain contextsWhen compiling
type TMvar a = TVar (Maybe a)
mynewEmptyMvar :: STM (TMVar a)
mynewEmptyMvar = newTVar Nothing
the type checker complains
Couldn't match expected type `TMVar a'
against inferred type `TVar (Maybe a1)'
Expe...When compiling
type TMvar a = TVar (Maybe a)
mynewEmptyMvar :: STM (TMVar a)
mynewEmptyMvar = newTVar Nothing
the type checker complains
Couldn't match expected type `TMVar a'
against inferred type `TVar (Maybe a1)'
Expected type: STM (TMVar a)
Inferred type: STM (TVar (Maybe a1))
In the expression: newTVar Nothing
In the definition of \`mynewEmptyMvar':
> mynewEmptyMvar = newTVar Nothing
although the definition of TMvar is
type TMvar a = TVar (Maybe a)
This behaviour could not be duplicated in the IO monad.
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | ----------------------- |
| Version | 6.10.2 |
| Type | Bug |
| TypeOfFailure | OtherFailure |
| Priority | normal |
| Resolution | Unresolved |
| Component | Compiler (Type checker) |
| Test case | |
| Differential revisions | |
| BlockedBy | |
| Related | |
| Blocking | |
| CC | |
| Operating system | |
| Architecture | |
</details>
<!-- {"blocked_by":[],"summary":"Type checker fails to unify/expand type definitions in certain contexts","status":"New","operating_system":"","component":"Compiler (Type checker)","related":[],"milestone":"","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"6.10.2","keywords":[],"differentials":[],"test_case":"","architecture":"","cc":[""],"type":"Bug","description":"When compiling \r\n\r\ntype TMvar a = TVar (Maybe a)\r\nmynewEmptyMvar :: STM (TMVar a)\r\nmynewEmptyMvar = newTVar Nothing\r\n\r\nthe type checker complains\r\n\r\n Couldn't match expected type `TMVar a'\r\n against inferred type `TVar (Maybe a1)'\r\n Expected type: STM (TMVar a)\r\n Inferred type: STM (TVar (Maybe a1))\r\n In the expression: newTVar Nothing\r\n In the definition of `mynewEmptyMvar':\r\n mynewEmptyMvar = newTVar Nothing\r\n\r\nalthough the definition of TMvar is\r\ntype TMvar a = TVar (Maybe a)\r\n\r\nThis behaviour could not be duplicated in the IO monad.","type_of_failure":"OtherFailure","blocking":[]} -->https://gitlab.haskell.org/ghc/ghc/-/issues/3163GADTs should not allow polymorphism in return type2019-07-07T19:05:04ZScott TurnerGADTs should not allow polymorphism in return type```
{-# LANGUAGE GADTs, RankNTypes, ImpredicativeTypes #-}
module Report (eval) where
data Taker a where
Unreached :: Taker (forall s. s)
eval :: a -> Taker a -> (forall t. t)
eval x c = case c of
Unreached -> x
```
I wanted t...```
{-# LANGUAGE GADTs, RankNTypes, ImpredicativeTypes #-}
module Report (eval) where
data Taker a where
Unreached :: Taker (forall s. s)
eval :: a -> Taker a -> (forall t. t)
eval x c = case c of
Unreached -> x
```
I wanted the quantified types to match and the code to get past the type-checker, as it would if the forall type annotations were replaced with any ordinary type. However, ghc reported:
```
Couldn't match expected type `t'
against inferred type `forall s. s'
`t' is a rigid type variable bound by
the type signature for `eval' at ghc_report.hs:7:32
In the expression: x
In a case alternative: Unreached -> x
In the expression: case c of { Unreached -> x }
```
I was unable to get around this problem by adding type annotations. However, I did get around it by using a similar type
```
data Z = Z (forall t.t)
```
instead of the bare forall type.
----
```
(yawl:~/programs/cat_type) scott% ghc -v -dcore-lint ghc_report.hs
Glasgow Haskell Compiler, Version 6.10.1, for Haskell 98, stage 2 booted by GHC version 6.10.1
Using package config file: /usr/lib/ghc-6.10.1/./package.conf
hiding package base-3.0.3.0 to avoid conflict with later version base-4.0.0.0
hiding package filepath-1.1.0.1 to avoid conflict with later version filepath-1.1.0.2
hiding package Cabal-1.6.0.1 to avoid conflict with later version Cabal-1.6.0.2
hiding package QuickCheck-1.2.0.0 to avoid conflict with later version QuickCheck-2.1.0.1
hiding package parsec-2.1.0.1 to avoid conflict with later version parsec-3.0.0
wired-in package ghc-prim mapped to ghc-prim-0.1.0.0
wired-in package integer mapped to integer-0.1.0.0
wired-in package base mapped to base-4.0.0.0
wired-in package rts mapped to rts-1.0
wired-in package haskell98 mapped to haskell98-1.0.1.0
wired-in package syb mapped to syb-0.1.0.0
wired-in package template-haskell mapped to template-haskell-2.3.0.0
wired-in package dph-seq[""] not found.
wired-in package dph-par[""] not found.
Hsc static flags: -static
Created temporary directory: /tmp/ghc26608_0
*** Checking old interface for main:Report:
*** Parser:
*** Renamer/typechecker:
ghc_report.hs:9:17:
Couldn't match expected type `t'
against inferred type `forall s. s'
`t' is a rigid type variable bound by
the type signature for `eval' at ghc_report.hs:7:32
In the expression: x
In a case alternative: Unreached -> x
In the expression: case c of { Unreached -> x }
*** Deleting temp files:
Deleting: /tmp/ghc26608_0/ghc26608_0.s
Warning: deleting non-existent /tmp/ghc26608_0/ghc26608_0.s
*** Deleting temp dirs:
Deleting: /tmp/ghc26608_0
```
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | ----------------------- |
| Version | 6.10.1 |
| Type | Bug |
| TypeOfFailure | OtherFailure |
| Priority | normal |
| Resolution | Unresolved |
| Component | Compiler (Type checker) |
| Test case | |
| Differential revisions | |
| BlockedBy | |
| Related | |
| Blocking | |
| CC | |
| Operating system | |
| Architecture | |
</details>
<!-- {"blocked_by":[],"summary":"quantified types fail to match in GADT case","status":"New","operating_system":"","component":"Compiler (Type checker)","related":[],"milestone":"","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"6.10.1","keywords":[],"differentials":[],"test_case":"","architecture":"","cc":[""],"type":"Bug","description":"{{{\r\n{-# LANGUAGE GADTs, RankNTypes, ImpredicativeTypes #-}\r\n\r\nmodule Report (eval) where\r\n\r\ndata Taker a where\r\n Unreached :: Taker (forall s. s)\r\neval :: a -> Taker a -> (forall t. t)\r\neval x c = case c of\r\n Unreached -> x\r\n}}}\r\nI wanted the quantified types to match and the code to get past the type-checker, as it would if the forall type annotations were replaced with any ordinary type. However, ghc reported:\r\n{{{\r\n Couldn't match expected type `t'\r\n against inferred type `forall s. s'\r\n `t' is a rigid type variable bound by\r\n the type signature for `eval' at ghc_report.hs:7:32\r\n In the expression: x\r\n In a case alternative: Unreached -> x\r\n In the expression: case c of { Unreached -> x }\r\n}}}\r\nI was unable to get around this problem by adding type annotations. However, I did get around it by using a similar type\r\n\r\n{{{\r\ndata Z = Z (forall t.t)\r\n}}}\r\ninstead of the bare forall type.\r\n\r\n----\r\n\r\n{{{\r\n(yawl:~/programs/cat_type) scott% ghc -v -dcore-lint ghc_report.hs\r\nGlasgow Haskell Compiler, Version 6.10.1, for Haskell 98, stage 2 booted by GHC version 6.10.1\r\nUsing package config file: /usr/lib/ghc-6.10.1/./package.conf\r\nhiding package base-3.0.3.0 to avoid conflict with later version base-4.0.0.0\r\nhiding package filepath-1.1.0.1 to avoid conflict with later version filepath-1.1.0.2\r\nhiding package Cabal-1.6.0.1 to avoid conflict with later version Cabal-1.6.0.2\r\nhiding package QuickCheck-1.2.0.0 to avoid conflict with later version QuickCheck-2.1.0.1\r\nhiding package parsec-2.1.0.1 to avoid conflict with later version parsec-3.0.0\r\nwired-in package ghc-prim mapped to ghc-prim-0.1.0.0\r\nwired-in package integer mapped to integer-0.1.0.0\r\nwired-in package base mapped to base-4.0.0.0\r\nwired-in package rts mapped to rts-1.0\r\nwired-in package haskell98 mapped to haskell98-1.0.1.0\r\nwired-in package syb mapped to syb-0.1.0.0\r\nwired-in package template-haskell mapped to template-haskell-2.3.0.0\r\nwired-in package dph-seq[\"\"] not found.\r\nwired-in package dph-par[\"\"] not found.\r\nHsc static flags: -static\r\nCreated temporary directory: /tmp/ghc26608_0\r\n*** Checking old interface for main:Report:\r\n*** Parser:\r\n*** Renamer/typechecker:\r\n\r\nghc_report.hs:9:17:\r\n Couldn't match expected type `t'\r\n against inferred type `forall s. s'\r\n `t' is a rigid type variable bound by\r\n the type signature for `eval' at ghc_report.hs:7:32\r\n In the expression: x\r\n In a case alternative: Unreached -> x\r\n In the expression: case c of { Unreached -> x }\r\n*** Deleting temp files:\r\nDeleting: /tmp/ghc26608_0/ghc26608_0.s\r\nWarning: deleting non-existent /tmp/ghc26608_0/ghc26608_0.s\r\n*** Deleting temp dirs:\r\nDeleting: /tmp/ghc26608_0\r\n\r\n}}}\r\n","type_of_failure":"OtherFailure","blocking":[]} -->6.12.1Simon Peyton JonesSimon Peyton Joneshttps://gitlab.haskell.org/ghc/ghc/-/issues/3154Type families bug with data family instances2019-07-07T19:05:07ZtrevorType families bug with data family instancesThis data family definition led to the ability to define a generic cast:
```
{-# LANGUAGE TypeFamilies #-}
data family T a b t
data instance T a b t = L a
data instance T a b () = R b
cast :: a -> b
cast x = let L i = R x in i
get :...This data family definition led to the ability to define a generic cast:
```
{-# LANGUAGE TypeFamilies #-}
data family T a b t
data instance T a b t = L a
data instance T a b () = R b
cast :: a -> b
cast x = let L i = R x in i
get :: IO Char
get = cast ()
```
This bug was observed in ghc version 6.10.1, 6.10.1.20090326 and 6.10.2.
```
% ghci test.hs
GHCi, version 6.10.2: http://www.haskell.org/ghc/ :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer ... linking ... done.
Loading package base ... linking ... done.
[1 of 1] Compiling Main ( test.hs, interpreted )
Ok, modules loaded: Main.
*Main> get
'\4312564'
*Main> get
<interactive>: internal error: stg_ap_v_ret
(GHC version 6.10.2 for x86_64_unknown_linux)
Please report this as a GHC bug: http://www.haskell.org/ghc/reportabug
zsh: abort ghci test.hs
```
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | ----------------------- |
| Version | 6.10.2 |
| Type | Bug |
| TypeOfFailure | OtherFailure |
| Priority | normal |
| Resolution | Unresolved |
| Component | Compiler (Type checker) |
| Test case | |
| Differential revisions | |
| BlockedBy | |
| Related | |
| Blocking | |
| CC | |
| Operating system | |
| Architecture | |
</details>
<!-- {"blocked_by":[],"summary":"Type families bug with data family instances","status":"New","operating_system":"","component":"Compiler (Type checker)","related":[],"milestone":"","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"6.10.2","keywords":["families","type"],"differentials":[],"test_case":"","architecture":"","cc":[""],"type":"Bug","description":"This data family definition led to the ability to define a generic cast:\r\n\r\n{{{\r\n{-# LANGUAGE TypeFamilies #-}\r\n\r\ndata family T a b t\r\ndata instance T a b t = L a\r\ndata instance T a b () = R b\r\n\r\ncast :: a -> b\r\ncast x = let L i = R x in i\r\n\r\nget :: IO Char\r\nget = cast ()\r\n}}}\r\n\r\nThis bug was observed in ghc version 6.10.1, 6.10.1.20090326 and 6.10.2.\r\n\r\n{{{\r\n% ghci test.hs\r\nGHCi, version 6.10.2: http://www.haskell.org/ghc/ :? for help\r\nLoading package ghc-prim ... linking ... done.\r\nLoading package integer ... linking ... done.\r\nLoading package base ... linking ... done.\r\n[1 of 1] Compiling Main ( test.hs, interpreted )\r\nOk, modules loaded: Main.\r\n*Main> get\r\n'\\4312564'\r\n*Main> get\r\n<interactive>: internal error: stg_ap_v_ret\r\n (GHC version 6.10.2 for x86_64_unknown_linux)\r\n Please report this as a GHC bug: http://www.haskell.org/ghc/reportabug\r\nzsh: abort ghci test.hs\r\n}}}","type_of_failure":"OtherFailure","blocking":[]} -->https://gitlab.haskell.org/ghc/ghc/-/issues/3150Overlapping data instances can segfault2019-07-07T19:05:08ZguestOverlapping data instances can segfaultWhen exploring data families for some fast unboxed tuple representation, we came across the following scenario.
```
class Foo a where
data Bar a :: *
instance Foo a where
data Bar a = PBar a
instance Foo () where
data Bar ...When exploring data families for some fast unboxed tuple representation, we came across the following scenario.
```
class Foo a where
data Bar a :: *
instance Foo a where
data Bar a = PBar a
instance Foo () where
data Bar () = PUnit
```
```
GHCi, version 6.10.1: http://www.haskell.org/ghc/ :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer ... linking ... done.
Loading package base ... linking ... done.
[1 of 1] Compiling Main ( Foo.hs, interpreted )
Ok, modules loaded: Main.
*Main> case PUnit of PBar x -> x
Segmentation fault
```
It appears the compiler is allowing the refinement of a into () because they overlap, when it shouldn't.
This is less academic than this example, because it affects doing similar operations to automatically unbox tuples of primitives when possible.
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | ----------------------- |
| Version | 6.10.1 |
| Type | Bug |
| TypeOfFailure | OtherFailure |
| Priority | normal |
| Resolution | Unresolved |
| Component | Compiler (Type checker) |
| Test case | |
| Differential revisions | |
| BlockedBy | |
| Related | |
| Blocking | |
| CC | ekmett@gmail.com |
| Operating system | |
| Architecture | |
</details>
<!-- {"blocked_by":[],"summary":"Overlapping data instances can segfault","status":"New","operating_system":"","component":"Compiler (Type checker)","related":[],"milestone":"","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"6.10.1","keywords":[],"differentials":[],"test_case":"","architecture":"","cc":["ekmett@gmail.com"],"type":"Bug","description":"When exploring data families for some fast unboxed tuple representation, we came across the following scenario.\r\n\r\n{{{\r\nclass Foo a where\r\n data Bar a :: *\r\n\r\ninstance Foo a where\r\n data Bar a = PBar a\r\n\r\ninstance Foo () where\r\n data Bar () = PUnit\r\n}}}\r\n\r\n{{{\r\n\r\nGHCi, version 6.10.1: http://www.haskell.org/ghc/ :? for help\r\nLoading package ghc-prim ... linking ... done.\r\nLoading package integer ... linking ... done.\r\nLoading package base ... linking ... done.\r\n[1 of 1] Compiling Main ( Foo.hs, interpreted )\r\nOk, modules loaded: Main.\r\n*Main> case PUnit of PBar x -> x\r\nSegmentation fault\r\n}}}\r\n\r\nIt appears the compiler is allowing the refinement of a into () because they overlap, when it shouldn't.\r\n\r\nThis is less academic than this example, because it affects doing similar operations to automatically unbox tuples of primitives when possible.","type_of_failure":"OtherFailure","blocking":[]} -->https://gitlab.haskell.org/ghc/ghc/-/issues/3043An unrelated definition monomorphizes a type even without the MR2019-07-07T19:05:41ZDeewiantAn unrelated definition monomorphizes a type even without the MRThe following code:
```
{-# LANGUAGE NoMonomorphismRestriction #-}
{-# LANGUAGE MultiParamTypeClasses, FlexibleInstances, FunctionalDependencies #-}
class Id a b | b -> a where id' :: a -> b
instance Id [Char] [Char] where id' = id
cl...The following code:
```
{-# LANGUAGE NoMonomorphismRestriction #-}
{-# LANGUAGE MultiParamTypeClasses, FlexibleInstances, FunctionalDependencies #-}
class Id a b | b -> a where id' :: a -> b
instance Id [Char] [Char] where id' = id
class Fst a where fst' :: a -> String
instance Fst ([Char],a) where fst' = fst
data Void a = Void
void :: (String,a) -> Void a
void _ = Void
fst'' (a,b) =
let x = (id' a, b)
y = void x :: Void Int -- remove this line and the code compiles
in fst' x
```
Results in:
```
arst.hs:18:6:
No instance for (Fst (b, Int))
arising from a use of `fst'' at arst.hs:18:6-11
Possible fix: add an instance declaration for (Fst (b, Int))
In the expression: fst' x
In the expression:
let
x = (id' a, b)
y = void x :: Void Int
in fst' x
In the definition of `fst''':
fst'' (a, b)
= let
x = ...
y = ...
in fst' x
arst.hs:18:11:
No instance for (Id [Char] b)
arising from a use of `x' at arst.hs:18:11
Possible fix: add an instance declaration for (Id [Char] b)
In the first argument of `fst'', namely `x'
In the expression: fst' x
In the expression:
let
x = (id' a, b)
y = void x :: Void Int
in fst' x
```
It seems that the definition of `y` locks down the type of `x` somewhat even though the monomorphism restriction is disabled. If we remove the definition:
```
*Main> :t fst''
fst'' :: (Id t b, Fst (b, t1)) => (t, t1) -> String
```
To be completely honest I'm not sure whether the code should be accepted or not, since `(Id t b, Fst (b, t1))` can't be satisfied. Only the fully monomorphic signature `([Char], Int) -> String`, which is obtained with the definition of `y` in place and the monomorphism restriction enabled, works.
In any case, I think it's a bug that the results of the type check depend on whether `y` is defined or not: surely that shouldn't matter at all, no matter what the end result is.
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | ----------------------- |
| Version | 6.10.1 |
| Type | Bug |
| TypeOfFailure | OtherFailure |
| Priority | normal |
| Resolution | Unresolved |
| Component | Compiler (Type checker) |
| Test case | |
| Differential revisions | |
| BlockedBy | |
| Related | |
| Blocking | |
| CC | |
| Operating system | |
| Architecture | |
</details>
<!-- {"blocked_by":[],"summary":"An unrelated definition monomorphizes a type even without the MR","status":"New","operating_system":"","component":"Compiler (Type checker)","related":[],"milestone":"","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"6.10.1","keywords":[],"differentials":[],"test_case":"","architecture":"","cc":[""],"type":"Bug","description":"The following code:\r\n{{{\r\n{-# LANGUAGE NoMonomorphismRestriction #-}\r\n{-# LANGUAGE MultiParamTypeClasses, FlexibleInstances, FunctionalDependencies #-}\r\n\r\nclass Id a b | b -> a where id' :: a -> b\r\ninstance Id [Char] [Char] where id' = id\r\n\r\nclass Fst a where fst' :: a -> String\r\ninstance Fst ([Char],a) where fst' = fst\r\n\r\ndata Void a = Void\r\n\r\nvoid :: (String,a) -> Void a\r\nvoid _ = Void\r\n\r\nfst'' (a,b) =\r\n let x = (id' a, b)\r\n y = void x :: Void Int -- remove this line and the code compiles\r\n in fst' x\r\n}}}\r\nResults in:\r\n{{{\r\narst.hs:18:6:\r\n No instance for (Fst (b, Int))\r\n arising from a use of `fst'' at arst.hs:18:6-11\r\n Possible fix: add an instance declaration for (Fst (b, Int))\r\n In the expression: fst' x\r\n In the expression:\r\n let\r\n x = (id' a, b)\r\n y = void x :: Void Int\r\n in fst' x\r\n In the definition of `fst''':\r\n fst'' (a, b)\r\n = let\r\n x = ...\r\n y = ...\r\n in fst' x\r\n\r\narst.hs:18:11:\r\n No instance for (Id [Char] b)\r\n arising from a use of `x' at arst.hs:18:11\r\n Possible fix: add an instance declaration for (Id [Char] b)\r\n In the first argument of `fst'', namely `x'\r\n In the expression: fst' x\r\n In the expression:\r\n let\r\n x = (id' a, b)\r\n y = void x :: Void Int\r\n in fst' x\r\n}}}\r\n\r\nIt seems that the definition of `y` locks down the type of `x` somewhat even though the monomorphism restriction is disabled. If we remove the definition:\r\n{{{\r\n*Main> :t fst''\r\nfst'' :: (Id t b, Fst (b, t1)) => (t, t1) -> String\r\n}}}\r\n\r\nTo be completely honest I'm not sure whether the code should be accepted or not, since `(Id t b, Fst (b, t1))` can't be satisfied. Only the fully monomorphic signature `([Char], Int) -> String`, which is obtained with the definition of `y` in place and the monomorphism restriction enabled, works.\r\n\r\nIn any case, I think it's a bug that the results of the type check depend on whether `y` is defined or not: surely that shouldn't matter at all, no matter what the end result is.","type_of_failure":"OtherFailure","blocking":[]} -->https://gitlab.haskell.org/ghc/ghc/-/issues/3023Wrong inferred type shown2019-07-07T19:05:50ZguestWrong inferred type shownWhen the warning for missing type signatures is turned on the displayed type is sometimes totally bogus.
```
{-# LANGUAGE MultiParamTypeClasses, FunctionalDependencies, UndecidableInstances #-}
module Bug where
class C a b | a -> b, b ...When the warning for missing type signatures is turned on the displayed type is sometimes totally bogus.
```
{-# LANGUAGE MultiParamTypeClasses, FunctionalDependencies, UndecidableInstances #-}
module Bug where
class C a b | a -> b, b -> a where
f :: a -> b
instance C Int Bool where
f = undefined
instance (C a c, C b d) => C (a -> b) (c -> d) where
f = undefined
foo :: Int -> Int
foo = undefined
bar = f foo
```
GHC says:
```
Warning: Definition but no type signature for `bar'
Inferred type: bar :: c -> d
```
The type for bar is, of course, Bool-\>Bool, and nothing else.
> -- Lennart
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | ---------------------- |
| Version | 6.10.1 |
| Type | Bug |
| TypeOfFailure | OtherFailure |
| Priority | normal |
| Resolution | Unresolved |
| Component | Compiler |
| Test case | |
| Differential revisions | |
| BlockedBy | |
| Related | |
| Blocking | |
| CC | lennart@augustsson.net |
| Operating system | |
| Architecture | |
</details>
<!-- {"blocked_by":[],"summary":"Wrong inferred type shown","status":"New","operating_system":"","component":"Compiler","related":[],"milestone":"","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"6.10.1","keywords":[],"differentials":[],"test_case":"","architecture":"","cc":["lennart@augustsson.net"],"type":"Bug","description":"When the warning for missing type signatures is turned on the displayed type is sometimes totally bogus.\r\n\r\n{{{\r\n{-# LANGUAGE MultiParamTypeClasses, FunctionalDependencies, UndecidableInstances #-}\r\nmodule Bug where\r\n\r\nclass C a b | a -> b, b -> a where\r\n f :: a -> b\r\n\r\ninstance C Int Bool where\r\n f = undefined\r\ninstance (C a c, C b d) => C (a -> b) (c -> d) where\r\n f = undefined\r\n\r\nfoo :: Int -> Int\r\nfoo = undefined\r\n\r\nbar = f foo\r\n}}}\r\nGHC says:\r\n{{{\r\n Warning: Definition but no type signature for `bar'\r\n Inferred type: bar :: c -> d\r\n}}}\r\nThe type for bar is, of course, Bool->Bool, and nothing else.\r\n\r\n -- Lennart\r\n\r\n","type_of_failure":"OtherFailure","blocking":[]} -->https://gitlab.haskell.org/ghc/ghc/-/issues/3014Any type being derived in Haskell 98 module2019-07-07T19:05:53Ziampure@gmail.comAny type being derived in Haskell 98 moduleLoad the attached module with ghci -ignore-dot-ghci, do :browse and observe the type of z, z :: GHC.Prim.Any -\> Double
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ----------------...Load the attached module with ghci -ignore-dot-ghci, do :browse and observe the type of z, z :: GHC.Prim.Any -\> Double
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | ----------------------- |
| Version | 6.10.1 |
| Type | Bug |
| TypeOfFailure | OtherFailure |
| Priority | normal |
| Resolution | Unresolved |
| Component | Compiler (Type checker) |
| Test case | |
| Differential revisions | |
| BlockedBy | |
| Related | |
| Blocking | |
| CC | |
| Operating system | |
| Architecture | |
</details>
<!-- {"blocked_by":[],"summary":"Any type being derived in Haskell 98 module","status":"New","operating_system":"","component":"Compiler (Type checker)","related":[],"milestone":"","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"6.10.1","keywords":["any","type"],"differentials":[],"test_case":"","architecture":"","cc":[""],"type":"Bug","description":"Load the attached module with ghci -ignore-dot-ghci, do :browse and observe the type of z, z :: GHC.Prim.Any -> Double\r\n\r\n\r\n\r\n ","type_of_failure":"OtherFailure","blocking":[]} -->https://gitlab.haskell.org/ghc/ghc/-/issues/2999yi darcs crashes ghc 6.11.200902012019-07-07T19:05:57ZIlmari Vacklinyi darcs crashes ghc 6.11.20090201```
Building yi-0.5.3...
[ 1 of 107] Compiling System.FriendlyPath ( System/FriendlyPath.hs, dist/build/System/FriendlyPath.o )
[ 2 of 107] Compiling Shim.ProjectContent ( Shim/ProjectContent.hs, dist/build/Shim/ProjectContent.o )
WARN...```
Building yi-0.5.3...
[ 1 of 107] Compiling System.FriendlyPath ( System/FriendlyPath.hs, dist/build/System/FriendlyPath.o )
[ 2 of 107] Compiling Shim.ProjectContent ( Shim/ProjectContent.hs, dist/build/Shim/ProjectContent.o )
WARNING: file simplCore/SimplCore.lhs line 545
Simplifier still going after 4 iterations; bailing out. Size = 4969
[ 3 of 107] Compiling Parser.Incremental ( Parser/Incremental.hs, dist/build/Parser/Incremental.o )
ghc: panic! (the 'impossible' happened)
(GHC version 6.11.20090201 for x86_64-unknown-linux):
ASSERT failed! file typecheck/TcTyFuns.lhs line 286
[Wanted t_a89i{tv} [tau] :: a{tv a89b} [sk]
~
a{tv a89a} [sk] -> t_a89h{tv} [tau]]
```Manuel M T ChakravartyManuel M T Chakravartyhttps://gitlab.haskell.org/ghc/ghc/-/issues/2905require -XGADTs in order to pattern-match GADTs2023-04-01T12:41:21Zguestrequire -XGADTs in order to pattern-match GADTsWithout -XGADTs, pattern-matching GADTs causes weird typechecking problems (due to the lack of implied -XRelaxedPolyRec), see this thread http://thread.gmane.org/gmane.comp.lang.haskell.glasgow.user/16064 , and some history in bug #2004
...Without -XGADTs, pattern-matching GADTs causes weird typechecking problems (due to the lack of implied -XRelaxedPolyRec), see this thread http://thread.gmane.org/gmane.comp.lang.haskell.glasgow.user/16064 , and some history in bug #2004
I propose that pattern-matching against any constructor that uses sufficient GADT features that it's particularly confused without -XRelaxedPolyRec, should require -XGADTs
(I don't understand the issue well enough to know if what I'm saying makes sense. I guess ordinary data and mere existentials don't need it, even when defined with GADT syntax...?)
Alternately we could just require -XRelaxedPolyRec, but that seems even more confusing (and it wouldn't help make code portable to other compilers, as GADTs are definitely being used). Or if Haskell-prime ever comes around and makes -XRelaxedPolyRec default (is it planning to?), then the issue might be moot. I don't think the argument (against requiring -XGADTs) by parallel to -XOverlappingInstances is particularly strong... -XOverlappingInstances has an implicit effect on a module's class definitions... also I don't necessarily agree with that we made that decision for existing flags either :-)
--Isaac Dupree
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | ------------------------------ |
| Version | 6.10.1 |
| Type | Bug |
| TypeOfFailure | OtherFailure |
| Priority | normal |
| Resolution | Unresolved |
| Component | Compiler (Type checker) |
| Test case | |
| Differential revisions | |
| BlockedBy | |
| Related | |
| Blocking | |
| CC | id@isaac.cedarswampstudios.org |
| Operating system | |
| Architecture | |
</details>
<!-- {"blocked_by":[],"summary":"require -XGADTs in order to pattern-match GADTs","status":"New","operating_system":"","component":"Compiler (Type checker)","related":[],"milestone":"","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"6.10.1","keywords":[],"differentials":[],"test_case":"","architecture":"","cc":["id@isaac.cedarswampstudios.org"],"type":"Bug","description":"Without -XGADTs, pattern-matching GADTs causes weird typechecking problems (due to the lack of implied -XRelaxedPolyRec), see this thread http://thread.gmane.org/gmane.comp.lang.haskell.glasgow.user/16064 , and some history in bug #2004\r\n\r\nI propose that pattern-matching against any constructor that uses sufficient GADT features that it's particularly confused without -XRelaxedPolyRec, should require -XGADTs\r\n\r\n(I don't understand the issue well enough to know if what I'm saying makes sense. I guess ordinary data and mere existentials don't need it, even when defined with GADT syntax...?)\r\n\r\nAlternately we could just require -XRelaxedPolyRec, but that seems even more confusing (and it wouldn't help make code portable to other compilers, as GADTs are definitely being used). Or if Haskell-prime ever comes around and makes -XRelaxedPolyRec default (is it planning to?), then the issue might be moot. I don't think the argument (against requiring -XGADTs) by parallel to -XOverlappingInstances is particularly strong... -XOverlappingInstances has an implicit effect on a module's class definitions... also I don't necessarily agree with that we made that decision for existing flags either :-)\r\n\r\n\r\n--Isaac Dupree\r\n","type_of_failure":"OtherFailure","blocking":[]} -->https://gitlab.haskell.org/ghc/ghc/-/issues/2900Confusing error message for monadic function with wrong number of arguments2019-07-07T19:06:21Zchevalier@alum.wellesley.eduConfusing error message for monadic function with wrong number of argumentsIf I compile the following code:
```
import Control.Monad.State
foo :: MonadIO m => Int -> m ()
foo x y = return ()
```
I get the error message:
```
bug.hs:6:10:
Couldn't match expected type `()' against inferred type `m ()'
...If I compile the following code:
```
import Control.Monad.State
foo :: MonadIO m => Int -> m ()
foo x y = return ()
```
I get the error message:
```
bug.hs:6:10:
Couldn't match expected type `()' against inferred type `m ()'
In the expression: return ()
In the definition of `foo': foo x y = return ()
```
On the other hand, if I change foo's type signature to:
```
foo :: Int -> IO ()
```
I get the more helpful:
```
bug.hs:6:0:
The equation(s) for `foo' have two arguments,
but its type `Int -> IO ()' has only one
```
It would be good if the second error message appeared in the first case as well.
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | ----------------------- |
| Version | 6.10.1 |
| Type | Bug |
| TypeOfFailure | OtherFailure |
| Priority | normal |
| Resolution | Unresolved |
| Component | Compiler (Type checker) |
| Test case | |
| Differential revisions | |
| BlockedBy | |
| Related | |
| Blocking | |
| CC | |
| Operating system | |
| Architecture | |
</details>
<!-- {"blocked_by":[],"summary":"Confusing error message for monadic function with wrong number of arguments","status":"New","operating_system":"","component":"Compiler (Type checker)","related":[],"milestone":"","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"6.10.1","keywords":[],"differentials":[],"test_case":"","architecture":"","cc":[""],"type":"Bug","description":"If I compile the following code:\r\n\r\n{{{\r\nimport Control.Monad.State\r\n\r\nfoo :: MonadIO m => Int -> m ()\r\nfoo x y = return ()\r\n}}}\r\n\r\nI get the error message:\r\n\r\n{{{\r\nbug.hs:6:10:\r\n Couldn't match expected type `()' against inferred type `m ()'\r\n In the expression: return ()\r\n In the definition of `foo': foo x y = return ()\r\n}}}\r\n\r\nOn the other hand, if I change foo's type signature to:\r\n{{{\r\nfoo :: Int -> IO ()\r\n}}}\r\nI get the more helpful:\r\n{{{\r\nbug.hs:6:0:\r\n The equation(s) for `foo' have two arguments,\r\n but its type `Int -> IO ()' has only one\r\n}}}\r\n\r\nIt would be good if the second error message appeared in the first case as well.","type_of_failure":"OtherFailure","blocking":[]} -->https://gitlab.haskell.org/ghc/ghc/-/issues/2899GADT type inference with existentials2019-07-07T19:06:22ZjochembGADT type inference with existentialsThe following code works in GHC 6.8.2:
```
{-# OPTIONS -fglasgow-exts #-}
module Test where
data Existential = forall a. Ex (GADT a)
data GADT :: * -> * where
GCon :: Int -> GADT ()
-- g :: Existential -> Int
g (Ex (GCon x)) ...The following code works in GHC 6.8.2:
```
{-# OPTIONS -fglasgow-exts #-}
module Test where
data Existential = forall a. Ex (GADT a)
data GADT :: * -> * where
GCon :: Int -> GADT ()
-- g :: Existential -> Int
g (Ex (GCon x)) = x
```
The compiler correctly infers the type of x in the definition of g, and correctly infers the type of g.
In GHC 6.10.1, however, this fails with:
```
Test.hs:10:12:
GADT pattern match with non-rigid result type `t'
Solution: add a type signature
In the definition of `g': g (Ex (GCon x)) = x
Failed, modules loaded: none.
```
The solution, to include the type signature of g (that I have commented out), works, but why can't GHC figure out the type of g? GHC 6.8.2 could!
An equivalent version with a non-GADT instead, works correctly:
```
data GADT a = GCon Int
```
Ticket #2206 might be related.
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | ----------------------- |
| Version | 6.10.1 |
| Type | Bug |
| TypeOfFailure | OtherFailure |
| Priority | normal |
| Resolution | Unresolved |
| Component | Compiler (Type checker) |
| Test case | |
| Differential revisions | |
| BlockedBy | |
| Related | |
| Blocking | |
| CC | |
| Operating system | |
| Architecture | |
</details>
<!-- {"blocked_by":[],"summary":"GADT type inference with existentials","status":"New","operating_system":"","component":"Compiler (Type checker)","related":[],"milestone":"","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"6.10.1","keywords":["GADT,","existential","types"],"differentials":[],"test_case":"","architecture":"","cc":[""],"type":"Bug","description":"\r\nThe following code works in GHC 6.8.2:\r\n\r\n{{{\r\n{-# OPTIONS -fglasgow-exts #-}\r\nmodule Test where\r\n\r\ndata Existential = forall a. Ex (GADT a)\r\n\r\ndata GADT :: * -> * where\r\n GCon :: Int -> GADT ()\r\n\r\n-- g :: Existential -> Int\r\ng (Ex (GCon x)) = x\r\n}}}\r\n\r\nThe compiler correctly infers the type of x in the definition of g, and correctly infers the type of g.\r\n\r\nIn GHC 6.10.1, however, this fails with:\r\n{{{\r\nTest.hs:10:12:\r\n GADT pattern match with non-rigid result type `t'\r\n Solution: add a type signature\r\n In the definition of `g': g (Ex (GCon x)) = x\r\nFailed, modules loaded: none.\r\n}}}\r\n\r\nThe solution, to include the type signature of g (that I have commented out), works, but why can't GHC figure out the type of g? GHC 6.8.2 could!\r\n\r\nAn equivalent version with a non-GADT instead, works correctly:\r\n{{{\r\ndata GADT a = GCon Int\r\n}}}\r\n\r\nTicket #2206 might be related.","type_of_failure":"OtherFailure","blocking":[]} -->