GHC issueshttps://gitlab.haskell.org/ghc/ghc/-/issues2019-07-07T19:14:04Zhttps://gitlab.haskell.org/ghc/ghc/-/issues/1332overloaded strings cause core lint failure2019-07-07T19:14:04ZIan Lynagh <igloo@earth.li>overloaded strings cause core lint failureThe overloaded strings extension isn't getting past core lint in the HEAD, e.g. test tc224:
```
*** Core Lint Errors: in result of Desugar ***
<no location info>:
In the expression: T.greet1 (GHC.Base.unpackCString# "hello")
Arg...The overloaded strings extension isn't getting past core lint in the HEAD, e.g. test tc224:
```
*** Core Lint Errors: in result of Desugar ***
<no location info>:
In the expression: T.greet1 (GHC.Base.unpackCString# "hello")
Argument value doesn't match argument type:
Fun type: T.MyString -> T.MyString
Arg type: [GHC.Base.Char]
Arg: GHC.Base.unpackCString# "hello"
*** Offending Program ***
[...]
```
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | ----------------------- |
| Version | 6.7 |
| Type | Bug |
| TypeOfFailure | OtherFailure |
| Priority | normal |
| Resolution | Unresolved |
| Component | Compiler (Type checker) |
| Test case | |
| Differential revisions | |
| BlockedBy | |
| Related | |
| Blocking | |
| CC | |
| Operating system | Unknown |
| Architecture | Unknown |
</details>
<!-- {"blocked_by":[],"summary":"overloaded strings cause core lint failure","status":"New","operating_system":"Unknown","component":"Compiler (Type checker)","related":[],"milestone":"6.8 branch","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"6.7","keywords":[],"differentials":[],"test_case":"","architecture":"Unknown","cc":[""],"type":"Bug","description":"The overloaded strings extension isn't getting past core lint in the HEAD, e.g. test tc224:\r\n{{{\r\n*** Core Lint Errors: in result of Desugar ***\r\n<no location info>:\r\n In the expression: T.greet1 (GHC.Base.unpackCString# \"hello\")\r\n Argument value doesn't match argument type:\r\n Fun type: T.MyString -> T.MyString\r\n Arg type: [GHC.Base.Char]\r\n Arg: GHC.Base.unpackCString# \"hello\"\r\n*** Offending Program ***\r\n[...]\r\n}}}","type_of_failure":"OtherFailure","blocking":[]} -->6.8.1https://gitlab.haskell.org/ghc/ghc/-/issues/1382Monad GHC.Prim.Any1 gets derived in a context2019-07-07T19:13:47Ziampure@gmail.comMonad GHC.Prim.Any1 gets derived in a contextBecause Monad GHC.Prim.Any1 gets derived in the type of the function test in the attached file, I cannot write an instance for it (obviously) and I cannot continue writing the code where I use the test function. I.e. I have this problem ...Because Monad GHC.Prim.Any1 gets derived in the type of the function test in the attached file, I cannot write an instance for it (obviously) and I cannot continue writing the code where I use the test function. I.e. I have this problem in a real project and it's blocking progress, until I find a work-around (which I didn't find after about an hour). I hope this gets fixed soon.
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | ----------------------- |
| Version | 6.6.1 |
| Type | Bug |
| TypeOfFailure | OtherFailure |
| Priority | high |
| Resolution | Unresolved |
| Component | Compiler (Type checker) |
| Test case | |
| Differential revisions | |
| BlockedBy | |
| Related | |
| Blocking | |
| CC | |
| Operating system | Unknown |
| Architecture | Unknown |
</details>
<!-- {"blocked_by":[],"summary":"Monad GHC.Prim.Any1 gets derived in a context","status":"New","operating_system":"Unknown","component":"Compiler (Type checker)","related":[],"milestone":"","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"6.6.1","keywords":["Any1","context","type-inference"],"differentials":[],"test_case":"","architecture":"Unknown","cc":[""],"type":"Bug","description":"Because Monad GHC.Prim.Any1 gets derived in the type of the function test in the attached file, I cannot write an instance for it (obviously) and I cannot continue writing the code where I use the test function. I.e. I have this problem in a real project and it's blocking progress, until I find a work-around (which I didn't find after about an hour). I hope this gets fixed soon.","type_of_failure":"OtherFailure","blocking":[]} -->Simon Peyton JonesSimon Peyton Joneshttps://gitlab.haskell.org/ghc/ghc/-/issues/1385(1,True) == (2,False) doesn't compile2019-07-07T19:13:46ZIan Lynagh <igloo@earth.li>(1,True) == (2,False) doesn't compileThis module:
```
module Foo where
foo = (1,True) == (2,False)
```
currently fails to compile:
```
No instance for (Eq (t, Bool))
arising from a use of `==' at q.hs:4:6-26
Possible fix: add an instance declaration for (E...This module:
```
module Foo where
foo = (1,True) == (2,False)
```
currently fails to compile:
```
No instance for (Eq (t, Bool))
arising from a use of `==' at q.hs:4:6-26
Possible fix: add an instance declaration for (Eq (t, Bool))
In the expression: (1, True) == (2, False)
In the definition of `foo': foo = (1, True) == (2, False)
```
but this does compile:
```
module Foo where
foo = 1 == 2
```6.8.1Simon Peyton JonesSimon Peyton Joneshttps://gitlab.haskell.org/ghc/ghc/-/issues/1404allow more type signatures2019-07-07T19:13:41ZIsaac Dupreeallow more type signatures(idea triggered by #393)
Allow multiple copies of a type-signature in a module, such that it is an error if they're not equivalent, but they don't have to be syntactically equal (
`f :: ShowS`
`f :: String -> String`
is okay).
It would...(idea triggered by #393)
Allow multiple copies of a type-signature in a module, such that it is an error if they're not equivalent, but they don't have to be syntactically equal (
`f :: ShowS`
`f :: String -> String`
is okay).
It would also be nice to allow any name in scope at top-level (even if imported) to be given a type signature. But that raises a question: can these type signatures give a more specific type than that of the raw imported function, the way normal function type signatures can with regards to their implementation?
Use cases: (1. making sure multiple implementations give the same interface, generally varying by \#ifdef) (2. asserting that something's type can be specified in two different weird ways). I don't really want to abandon having a type-signature right above every function definition even if it is a duplicate.
(1.) would be fixed by allowing type signatures in export lists instead. I suppose these could be more restrictive than in the module and not affect the module, e.g.
```
module X (idN :: Int -> Int, true) where
idN n = n
true :: Bool
true = idN True
```
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | -------------- |
| Version | 6.6.1 |
| Type | FeatureRequest |
| TypeOfFailure | OtherFailure |
| Priority | normal |
| Resolution | Unresolved |
| Component | Compiler |
| Test case | |
| Differential revisions | |
| BlockedBy | |
| Related | |
| Blocking | |
| CC | |
| Operating system | Unknown |
| Architecture | Unknown |
</details>
<!-- {"blocked_by":[],"summary":"allow more type signatures","status":"New","operating_system":"Unknown","component":"Compiler","related":[],"milestone":"","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"6.6.1","keywords":[],"differentials":[],"test_case":"","architecture":"Unknown","cc":[""],"type":"FeatureRequest","description":"(idea triggered by #393)\r\n\r\nAllow multiple copies of a type-signature in a module, such that it is an error if they're not equivalent, but they don't have to be syntactically equal (\r\n{{{f :: ShowS}}}\r\n{{{f :: String -> String}}}\r\nis okay).\r\n\r\nIt would also be nice to allow any name in scope at top-level (even if imported) to be given a type signature. But that raises a question: can these type signatures give a more specific type than that of the raw imported function, the way normal function type signatures can with regards to their implementation?\r\n\r\nUse cases: (1. making sure multiple implementations give the same interface, generally varying by #ifdef) (2. asserting that something's type can be specified in two different weird ways). I don't really want to abandon having a type-signature right above every function definition even if it is a duplicate.\r\n\r\n(1.) would be fixed by allowing type signatures in export lists instead. I suppose these could be more restrictive than in the module and not affect the module, e.g. \r\n{{{\r\nmodule X (idN :: Int -> Int, true) where\r\nidN n = n\r\ntrue :: Bool\r\ntrue = idN True\r\n}}}","type_of_failure":"OtherFailure","blocking":[]} -->https://gitlab.haskell.org/ghc/ghc/-/issues/1406Constraint doesn't reduce in the presence of quantified type variables2019-07-07T19:13:41ZccshanConstraint doesn't reduce in the presence of quantified type variables```
{-# OPTIONS -fglasgow-exts #-}
{-# OPTIONS -fallow-undecidable-instances #-}
module Problem where
data Z
data S a
class HPrefix l
instance (NSub (S Z) ndiff, HDrop ndiff l l) => HPrefix l
class NSub n1 n3 | n1 -> n3
instance NSub...```
{-# OPTIONS -fglasgow-exts #-}
{-# OPTIONS -fallow-undecidable-instances #-}
module Problem where
data Z
data S a
class HPrefix l
instance (NSub (S Z) ndiff, HDrop ndiff l l) => HPrefix l
class NSub n1 n3 | n1 -> n3
instance NSub Z Z
instance NSub n1 n3 => NSub (S n1) n3
class HDrop n l1 l2 | n l1 -> l2
instance HDrop Z l l
t_hPrefix :: HPrefix l => l -> ()
t_hPrefix = undefined
-- This works...
thr' :: (forall r. l -> a) -> a
thr' f = f undefined
thP4' = thr' t_hPrefix
-- ... but this doesn't work...?
thr :: (forall r. r -> a) -> a
thr f = f undefined
thP4 = thr t_hPrefix
```
```
$ ghci GHCProblem.hs
___ ___ _
/ _ \ /\ /\/ __(_)
/ /_\// /_/ / / | | GHC Interactive, version 6.6.1, for Haskell 98.
/ /_\\/ __ / /___| | http://www.haskell.org/ghc/
\____/\/ /_/\____/|_| Type :? for help.
Loading package base ... linking ... done.
[1 of 1] Compiling Problem ( GHCProblem.hs, interpreted )
GHCProblem.hs:30:11:
No instance for (HDrop ndiff r r)
arising from use of `t_hPrefix' at GHCProblem.hs:30:11-19
Possible fix:
add (HDrop ndiff r r) to the expected type of an expression
In the first argument of `thr', namely `t_hPrefix'
In the expression: thr t_hPrefix
In the definition of `thP4': thP4 = thr t_hPrefix
Failed, modules loaded: none.
```
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | ----------------------- |
| Version | 6.6.1 |
| Type | Bug |
| TypeOfFailure | OtherFailure |
| Priority | normal |
| Resolution | Unresolved |
| Component | Compiler (Type checker) |
| Test case | |
| Differential revisions | |
| BlockedBy | |
| Related | |
| Blocking | |
| CC | |
| Operating system | Unknown |
| Architecture | |
</details>
<!-- {"blocked_by":[],"summary":"Constraint doesn't reduce in the presence of quantified type variables","status":"New","operating_system":"Unknown","component":"Compiler (Type checker)","related":[],"milestone":"","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"6.6.1","keywords":[],"differentials":[],"test_case":"","architecture":"","cc":[""],"type":"Bug","description":"{{{\r\n{-# OPTIONS -fglasgow-exts #-}\r\n{-# OPTIONS -fallow-undecidable-instances #-}\r\n\r\nmodule Problem where\r\n\r\ndata Z\r\ndata S a\r\n\r\nclass HPrefix l\r\ninstance (NSub (S Z) ndiff, HDrop ndiff l l) => HPrefix l\r\n\r\nclass NSub n1 n3 | n1 -> n3\r\ninstance NSub Z Z\r\ninstance NSub n1 n3 => NSub (S n1) n3\r\n\r\nclass HDrop n l1 l2 | n l1 -> l2\r\ninstance HDrop Z l l\r\n\r\nt_hPrefix :: HPrefix l => l -> ()\r\nt_hPrefix = undefined\r\n\r\n-- This works...\r\nthr' :: (forall r. l -> a) -> a\r\nthr' f = f undefined\r\nthP4' = thr' t_hPrefix\r\n\r\n-- ... but this doesn't work...?\r\nthr :: (forall r. r -> a) -> a\r\nthr f = f undefined\r\nthP4 = thr t_hPrefix\r\n}}}\r\n{{{\r\n$ ghci GHCProblem.hs \r\n ___ ___ _\r\n / _ \\ /\\ /\\/ __(_)\r\n / /_\\// /_/ / / | | GHC Interactive, version 6.6.1, for Haskell 98.\r\n/ /_\\\\/ __ / /___| | http://www.haskell.org/ghc/\r\n\\____/\\/ /_/\\____/|_| Type :? for help.\r\n\r\nLoading package base ... linking ... done.\r\n[1 of 1] Compiling Problem ( GHCProblem.hs, interpreted )\r\n\r\nGHCProblem.hs:30:11:\r\n No instance for (HDrop ndiff r r)\r\n arising from use of `t_hPrefix' at GHCProblem.hs:30:11-19\r\n Possible fix:\r\n add (HDrop ndiff r r) to the expected type of an expression\r\n In the first argument of `thr', namely `t_hPrefix'\r\n In the expression: thr t_hPrefix\r\n In the definition of `thP4': thP4 = thr t_hPrefix\r\nFailed, modules loaded: none.\r\n}}}","type_of_failure":"OtherFailure","blocking":[]} -->https://gitlab.haskell.org/ghc/ghc/-/issues/1411Typo in type error for lazy patterns2019-07-07T19:13:39ZguestTypo in type error for lazy patternsThere's a small typo in one of the type-error messages for lazy patterns. I've attached a patch that fixes it.
\[Corrected typo in compiler/typecheck/TcPat.lhs:
stefan\@cs.uu.nl\*\*20070601054931
- connot ===\> cannot
\] {
hunk ./comp...There's a small typo in one of the type-error messages for lazy patterns. I've attached a patch that fixes it.
\[Corrected typo in compiler/typecheck/TcPat.lhs:
stefan\@cs.uu.nl\*\*20070601054931
- connot ===\> cannot
\] {
hunk ./compiler/typecheck/TcPat.lhs 958
- hang (ptext SLIT("A lazy (\~) pattern connot bind existential type variables
"))
+ hang (ptext SLIT("A lazy (\~) pattern cannot bind existential type variables
"))
}
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | ----------------------- |
| Version | 6.7 |
| Type | Bug |
| TypeOfFailure | OtherFailure |
| Priority | low |
| Resolution | Unresolved |
| Component | Compiler (Type checker) |
| Test case | |
| Differential revisions | |
| BlockedBy | |
| Related | |
| Blocking | |
| CC | |
| Operating system | Multiple |
| Architecture | Multiple |
</details>
<!-- {"blocked_by":[],"summary":"Typo in type error for lazy patterns","status":"New","operating_system":"Multiple","component":"Compiler (Type checker)","related":[],"milestone":"","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"6.7","keywords":["typo"],"differentials":[],"test_case":"","architecture":"Multiple","cc":[""],"type":"Bug","description":"There's a small typo in one of the type-error messages for lazy patterns. I've attached a patch that fixes it.\r\n\r\n[Corrected typo in compiler/typecheck/TcPat.lhs:\r\nstefan@cs.uu.nl**20070601054931\r\n * connot ===> cannot\r\n] {\r\nhunk ./compiler/typecheck/TcPat.lhs 958\r\n- hang (ptext SLIT(\"A lazy (~) pattern connot bind existential type variables\r\n\"))\r\n+ hang (ptext SLIT(\"A lazy (~) pattern cannot bind existential type variables\r\n\"))\r\n}","type_of_failure":"OtherFailure","blocking":[]} -->https://gitlab.haskell.org/ghc/ghc/-/issues/1412Typo in type error for lazy patterns2019-07-07T19:13:39Zstefan@cs.uu.nlTypo in type error for lazy patternsThere's a small typo in one of the type-error messages for lazy patterns. I've attached a patch that fixes it.
\[Corrected typo in compiler/typecheck/TcPat.lhs:
stefan\@cs.uu.nl\*\*20070601054931
- connot ===\> cannot
\] {
hunk ./comp...There's a small typo in one of the type-error messages for lazy patterns. I've attached a patch that fixes it.
\[Corrected typo in compiler/typecheck/TcPat.lhs:
stefan\@cs.uu.nl\*\*20070601054931
- connot ===\> cannot
\] {
hunk ./compiler/typecheck/TcPat.lhs 958
- hang (ptext SLIT("A lazy (\~) pattern connot bind existential type variables
"))
+ hang (ptext SLIT("A lazy (\~) pattern cannot bind existential type variables
"))
}
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | ----------------------- |
| Version | 6.7 |
| Type | Bug |
| TypeOfFailure | OtherFailure |
| Priority | low |
| Resolution | Unresolved |
| Component | Compiler (Type checker) |
| Test case | |
| Differential revisions | |
| BlockedBy | |
| Related | |
| Blocking | |
| CC | |
| Operating system | Multiple |
| Architecture | Multiple |
</details>
<!-- {"blocked_by":[],"summary":"Typo in type error for lazy patterns","status":"New","operating_system":"Multiple","component":"Compiler (Type checker)","related":[],"milestone":"","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"6.7","keywords":["typo"],"differentials":[],"test_case":"","architecture":"Multiple","cc":[""],"type":"Bug","description":"There's a small typo in one of the type-error messages for lazy patterns. I've attached a patch that fixes it.\r\n\r\n[Corrected typo in compiler/typecheck/TcPat.lhs:\r\nstefan@cs.uu.nl**20070601054931\r\n * connot ===> cannot\r\n] {\r\nhunk ./compiler/typecheck/TcPat.lhs 958\r\n- hang (ptext SLIT(\"A lazy (~) pattern connot bind existential type variables\r\n\"))\r\n+ hang (ptext SLIT(\"A lazy (~) pattern cannot bind existential type variables\r\n\"))\r\n}","type_of_failure":"OtherFailure","blocking":[]} -->https://gitlab.haskell.org/ghc/ghc/-/issues/1430getC: Type signature needed when existential types are used but not in the ty...2019-07-07T19:13:35ZIan Lynagh <igloo@earth.li>getC: Type signature needed when existential types are used but not in the type signatureThis module:
```
{-# OPTIONS -fglasgow-exts #-}
module Q where
import Data.Typeable
data ExTypeable = forall a. Typeable a => ExTypeable a
-- unExTypeable :: Typeable h => ExTypeable -> Maybe h
unExTypeable (ExTypeable a) = cast a
``...This module:
```
{-# OPTIONS -fglasgow-exts #-}
module Q where
import Data.Typeable
data ExTypeable = forall a. Typeable a => ExTypeable a
-- unExTypeable :: Typeable h => ExTypeable -> Maybe h
unExTypeable (ExTypeable a) = cast a
```
with the type signature commented out gives this in the HEAD:
```
q.hs:10:30:
Could not deduce (Typeable b) from the context (Typeable a)
arising from a use of `cast' at q.hs:10:30-35
Possible fix:
add (Typeable b) to the context of the constructor `ExTypeable'
In the expression: cast a
In the definition of `unExTypeable':
unExTypeable (ExTypeable a) = cast a
```
It works in 6.6.
It's part of the getC test.
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | ----------------------- |
| Version | 6.6.1 |
| Type | Bug |
| TypeOfFailure | OtherFailure |
| Priority | high |
| Resolution | Unresolved |
| Component | Compiler (Type checker) |
| Test case | getC |
| Differential revisions | |
| BlockedBy | |
| Related | |
| Blocking | |
| CC | |
| Operating system | Unknown |
| Architecture | Unknown |
</details>
<!-- {"blocked_by":[],"summary":"getC: Type signature needed when existential types are used but not in the type signature","status":"New","operating_system":"Unknown","component":"Compiler (Type checker)","related":[],"milestone":"6.8 branch","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"6.6.1","keywords":[],"differentials":[],"test_case":"getC","architecture":"Unknown","cc":[""],"type":"Bug","description":"This module:\r\n{{{\r\n{-# OPTIONS -fglasgow-exts #-}\r\nmodule Q where\r\n\r\nimport Data.Typeable\r\n\r\ndata ExTypeable = forall a. Typeable a => ExTypeable a\r\n\r\n-- unExTypeable :: Typeable h => ExTypeable -> Maybe h\r\nunExTypeable (ExTypeable a) = cast a\r\n}}}\r\nwith the type signature commented out gives this in the HEAD:\r\n{{{\r\nq.hs:10:30:\r\n Could not deduce (Typeable b) from the context (Typeable a)\r\n arising from a use of `cast' at q.hs:10:30-35\r\n Possible fix:\r\n add (Typeable b) to the context of the constructor `ExTypeable'\r\n In the expression: cast a\r\n In the definition of `unExTypeable':\r\n unExTypeable (ExTypeable a) = cast a\r\n}}}\r\nIt works in 6.6.\r\n\r\nIt's part of the getC test.","type_of_failure":"OtherFailure","blocking":[]} -->6.8.1https://gitlab.haskell.org/ghc/ghc/-/issues/1432Poor type error messages (refer to generated code rather than the higher leve...2019-07-07T19:13:35ZIan Lynagh <igloo@earth.li>Poor type error messages (refer to generated code rather than the higher level problem)With this module:
```
module Foo where
data Foo a = Foo
data Bar a = Bar (Foo a)
deriving Eq
```
the HEAD says:
```
q.hs:5:0:
Non type-variable argument in the constraint: Eq (Foo a)
(Use -fglasgow-exts to permit this)
...With this module:
```
module Foo where
data Foo a = Foo
data Bar a = Bar (Foo a)
deriving Eq
```
the HEAD says:
```
q.hs:5:0:
Non type-variable argument in the constraint: Eq (Foo a)
(Use -fglasgow-exts to permit this)
In the context: (Eq (Foo a))
While checking the context of an instance declaration
In the derived instance: (Eq (Foo a)) => Eq (Bar a)
```
which isn't really the error message that we want, as it's refering to the
generated instance.
1. 6 gives the much better:
```
q.hs:5:5:
No instance for (Eq (Foo a))
arising from the 'deriving' clause of a data type declaration
at q.hs:5:5
Possible fix: add an instance declaration for (Eq (Foo a))
When deriving the instance for `Eq (Bar a)'
```
This example is from tcfail046; tcfail169 is similar and tcfail118 is also a related issue.
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | ----------------------- |
| Version | 6.6.1 |
| Type | Bug |
| TypeOfFailure | OtherFailure |
| Priority | high |
| Resolution | Unresolved |
| Component | Compiler (Type checker) |
| Test case | |
| Differential revisions | |
| BlockedBy | |
| Related | |
| Blocking | |
| CC | |
| Operating system | Unknown |
| Architecture | Unknown |
</details>
<!-- {"blocked_by":[],"summary":"Poor type error messages (refer to generated code rather than the higher level problem)","status":"New","operating_system":"Unknown","component":"Compiler (Type checker)","related":[],"milestone":"6.8 branch","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"6.6.1","keywords":[],"differentials":[],"test_case":"","architecture":"Unknown","cc":[""],"type":"Bug","description":"With this module:\r\n{{{\r\nmodule Foo where\r\n\r\ndata Foo a = Foo\r\ndata Bar a = Bar (Foo a)\r\n deriving Eq\r\n}}}\r\nthe HEAD says:\r\n{{{\r\nq.hs:5:0:\r\n Non type-variable argument in the constraint: Eq (Foo a)\r\n (Use -fglasgow-exts to permit this)\r\n In the context: (Eq (Foo a))\r\n While checking the context of an instance declaration\r\n In the derived instance: (Eq (Foo a)) => Eq (Bar a)\r\n}}}\r\nwhich isn't really the error message that we want, as it's refering to the\r\ngenerated instance.\r\n\r\n6.6 gives the much better:\r\n{{{\r\nq.hs:5:5:\r\n No instance for (Eq (Foo a))\r\n arising from the 'deriving' clause of a data type declaration\r\n at q.hs:5:5\r\n Possible fix: add an instance declaration for (Eq (Foo a))\r\n When deriving the instance for `Eq (Bar a)'\r\n}}}\r\n\r\nThis example is from tcfail046; tcfail169 is similar and tcfail118 is also a related issue.","type_of_failure":"OtherFailure","blocking":[]} -->6.8.1https://gitlab.haskell.org/ghc/ghc/-/issues/1451Provide way to show the origin of a constraint2023-11-08T06:22:30Ziampure@gmail.comProvide way to show the origin of a constraintFor a complex type (A b, C d, E e) =\> Something a b e -\> Int, provide a way to given the query:
where does A b come from? Respond with the line number of a function that causes that constraint. This should of course also work for non-H...For a complex type (A b, C d, E e) =\> Something a b e -\> Int, provide a way to given the query:
where does A b come from? Respond with the line number of a function that causes that constraint. This should of course also work for non-Haskell 98 constraints.
This issue comes up when one by accident calls a function in the wrong layer of a monadic transformer stack.
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | -------------- |
| Version | 6.6.1 |
| Type | FeatureRequest |
| TypeOfFailure | OtherFailure |
| Priority | normal |
| Resolution | Unresolved |
| Component | Compiler |
| Test case | |
| Differential revisions | |
| BlockedBy | |
| Related | |
| Blocking | |
| CC | |
| Operating system | Unknown |
| Architecture | Unknown |
</details>
<!-- {"blocked_by":[],"summary":"Provide way to show the origin of a constraint","status":"New","operating_system":"Unknown","component":"Compiler","related":[],"milestone":"","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"6.6.1","keywords":[],"differentials":[],"test_case":"","architecture":"Unknown","cc":[""],"type":"FeatureRequest","description":"For a complex type (A b, C d, E e) => Something a b e -> Int, provide a way to given the query:\r\nwhere does A b come from? Respond with the line number of a function that causes that constraint. This should of course also work for non-Haskell 98 constraints. \r\n\r\nThis issue comes up when one by accident calls a function in the wrong layer of a monadic transformer stack.","type_of_failure":"OtherFailure","blocking":[]} -->https://gitlab.haskell.org/ghc/ghc/-/issues/1465Type errors due to different package versions are a bit cryptic2019-07-07T19:13:26ZguestType errors due to different package versions are a bit crypticUsers of xmonad who've compiled one dependent library against X11 1.2, and then update X11, and attempt to recompile xmonad against the new X11 1.2.2, get a cryptic type error:
```
Couldn't match expected type `Graphics.X11.Xlib.Typ...Users of xmonad who've compiled one dependent library against X11 1.2, and then update X11, and attempt to recompile xmonad against the new X11 1.2.2, get a cryptic type error:
```
Couldn't match expected type `Graphics.X11.Xlib.Types.Display'
against inferred type `Display'
```
Perhaps non-local types should be printed with their package name and version, which would clarify this error. Something like:
```
Couldn't match expected type `X11-1.2: Graphics.X11.Xlib.Types.Display'
against inferred type `X11-1.2.2: Display'
```
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | ----------------------- |
| Version | 6.6.1 |
| Type | FeatureRequest |
| TypeOfFailure | OtherFailure |
| Priority | normal |
| Resolution | Unresolved |
| Component | Compiler (Type checker) |
| Test case | |
| Differential revisions | |
| BlockedBy | |
| Related | |
| Blocking | |
| CC | |
| Operating system | Unknown |
| Architecture | Unknown |
</details>
<!-- {"blocked_by":[],"summary":"Type errors due to different package versions are a bit cryptic","status":"New","operating_system":"Unknown","component":"Compiler (Type checker)","related":[],"milestone":"","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"6.6.1","keywords":[],"differentials":[],"test_case":"","architecture":"Unknown","cc":[""],"type":"FeatureRequest","description":"Users of xmonad who've compiled one dependent library against X11 1.2, and then update X11, and attempt to recompile xmonad against the new X11 1.2.2, get a cryptic type error:\r\n\r\n{{{\r\n Couldn't match expected type `Graphics.X11.Xlib.Types.Display'\r\n against inferred type `Display'\r\n}}}\r\n\r\nPerhaps non-local types should be printed with their package name and version, which would clarify this error. Something like:\r\n\r\n{{{\r\n Couldn't match expected type `X11-1.2: Graphics.X11.Xlib.Types.Display'\r\n against inferred type `X11-1.2.2: Display'\r\n}}}","type_of_failure":"OtherFailure","blocking":[]} -->6.8.1https://gitlab.haskell.org/ghc/ghc/-/issues/1470Overlapping (etc) instances2019-07-07T19:13:25ZIan Lynagh <igloo@earth.li>Overlapping (etc) instancesThis self-contained module:
```
{-# LANGUAGE FlexibleInstances, OverlappingInstances, UndecidableInstances #-}
module Foo where
class Sat a
class Data ctx a
instance Sat (ctx Char) => Data ctx Char
instance (Sat (ctx [a])...This self-contained module:
```
{-# LANGUAGE FlexibleInstances, OverlappingInstances, UndecidableInstances #-}
module Foo where
class Sat a
class Data ctx a
instance Sat (ctx Char) => Data ctx Char
instance (Sat (ctx [a]), Data ctx a) => Data ctx [a]
class Data FooD a => Foo a
data FooD a = FooD
instance Foo t => Sat (FooD t)
instance Data FooD a => Foo a
instance Foo a => Foo [a]
instance Foo [Char]
```
gives this error in the HEAD (and a similar, but less helpful, error in 6.6):
```
$ ghc -c Foo.hs
Foo.hs:18:0:
Overlapping instances for Foo [a]
arising from the superclasses of an instance declaration
at Foo.hs:18:0
Matching instances:
instance [overlap ok] (Foo a) => Foo [a]
-- Defined at Foo.hs:18:0-30
instance [overlap ok] Foo [Char] -- Defined at Foo.hs:19:0-33
(The choice depends on the instantiation of `a'
Use -fallow-incoherent-instances to use the first choice above)
In the instance declaration for `Foo [a]'
```
Simon writes:
```
The reason is this:
In the instance for Foo [a]
we need a superclass (Data FooD [a])
using the instance for Data, we therefore need
(Sat (FooD [a], Data FooD a)
But we are given Foo a, and hence its superclass Data FooD a
So that leaves (Sat (FooD [a]))
Using the instance for Sat means
we need (Foo [a])
At that point GHC says there are two instances that match Foo [a], and which one
to choose depends on how you instantiate a.
What we wanted was to "tie the knot" and use Foo [a] recursively, the very one
we are constructing. GHC does that when solving Foo [a], but not when
constructing it.
This is a good point, I will think about it. It's a bit delicate. Meanwhile,
can you Trac it? It's a nice example.
```
A larger module showing how the instances above can be desirable in a real program is this (requires the syb-with-class package from hackage):
```
{-# LANGUAGE TemplateHaskell, FlexibleInstances, CPP,
OverlappingInstances, UndecidableInstances #-}
module Main where
import Data.Generics.SYB.WithClass.Basics
import Data.Generics.SYB.WithClass.Instances ()
data Element = Elem String [Element]
| CData String
deriving Show
class Data XmlD a => Xml a where
toXml :: a -> [Element]
toXml = defaultToXml
data XmlD a = XmlD { toXmlD :: a -> [Element] }
xmlProxy :: Proxy XmlD
xmlProxy = error "xmlProxy"
instance Xml t => Sat (XmlD t) where
dict = XmlD { toXmlD = toXml }
defaultToXml :: Xml t => t -> [Element]
defaultToXml x = [Elem (constring $ toConstr xmlProxy x)
(concat $ gmapQ xmlProxy (toXmlD dict) x)]
-----
instance Data XmlD t => Xml t
#ifdef STRING
instance Xml String where
toXml x = [Elem "string" [CData x]]
#endif
#ifdef LIST
instance Xml a => Xml [a] where
toXml = concatMap toXml
#endif
main :: IO ()
main = do print $ toXml (Just True)
print $ toXml [True, False]
print $ toXml "foo"
```
which allows us to specialise XML marshalling for either lists (ignoring all the (:) and \[\] constructors) or strings (turn them into CData), but not both:
```
$ ghci -v0 -DLIST z.hs
*Main> main
[Elem "Just" [Elem "True" []]]
[Elem "True" [],Elem "False" []]
[Elem "f" [],Elem "o" [],Elem "o" []]
*Main>
$ ghci -v0 -DSTRING z.hs
*Main> main
[Elem "Just" [Elem "True" []]]
[Elem "(:)" [Elem "True" [],Elem "(:)" [Elem "False" [],Elem "[]" []]]]
[Elem "string" [CData "foo"]]
*Main>
$ ghci -v0 -DLIST -DSTRING z.hs
[overlapping instances error]
```
If we replace the
```
instance Xml a => Xml [a] where
```
line with
```
instance (Xml a, Xml [a]) => Xml [a] where
```
then everything seems to work out, but this feels a little dodgy.
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | ----------------------- |
| Version | 6.6.1 |
| Type | Bug |
| TypeOfFailure | OtherFailure |
| Priority | normal |
| Resolution | Unresolved |
| Component | Compiler (Type checker) |
| Test case | |
| Differential revisions | |
| BlockedBy | |
| Related | |
| Blocking | |
| CC | |
| Operating system | Unknown |
| Architecture | Unknown |
</details>
<!-- {"blocked_by":[],"summary":"Overlapping (etc) instances","status":"New","operating_system":"Unknown","component":"Compiler (Type checker)","related":[],"milestone":"","resolution":"Unresolved","owner":{"tag":"OwnedBy","contents":"simonpj"},"version":"6.6.1","keywords":[],"differentials":[],"test_case":"","architecture":"Unknown","cc":[""],"type":"Bug","description":"This self-contained module:\r\n{{{\r\n{-# LANGUAGE FlexibleInstances, OverlappingInstances, UndecidableInstances #-}\r\n\r\nmodule Foo where\r\n\r\nclass Sat a\r\nclass Data ctx a\r\ninstance Sat (ctx Char) => Data ctx Char\r\ninstance (Sat (ctx [a]), Data ctx a) => Data ctx [a]\r\n\r\nclass Data FooD a => Foo a\r\n\r\ndata FooD a = FooD\r\n\r\ninstance Foo t => Sat (FooD t)\r\n\r\ninstance Data FooD a => Foo a\r\ninstance Foo a => Foo [a]\r\ninstance Foo [Char]\r\n}}}\r\ngives this error in the HEAD (and a similar, but less helpful, error in 6.6):\r\n{{{\r\n$ ghc -c Foo.hs\r\n\r\nFoo.hs:18:0:\r\n Overlapping instances for Foo [a]\r\n arising from the superclasses of an instance declaration\r\n at Foo.hs:18:0\r\n Matching instances:\r\n instance [overlap ok] (Foo a) => Foo [a]\r\n -- Defined at Foo.hs:18:0-30\r\n instance [overlap ok] Foo [Char] -- Defined at Foo.hs:19:0-33\r\n (The choice depends on the instantiation of `a'\r\n Use -fallow-incoherent-instances to use the first choice above)\r\n In the instance declaration for `Foo [a]'\r\n}}}\r\nSimon writes:\r\n{{{\r\nThe reason is this:\r\n\r\nIn the instance for Foo [a]\r\nwe need a superclass (Data FooD [a])\r\nusing the instance for Data, we therefore need\r\n (Sat (FooD [a], Data FooD a)\r\nBut we are given Foo a, and hence its superclass Data FooD a\r\nSo that leaves (Sat (FooD [a]))\r\nUsing the instance for Sat means\r\nwe need (Foo [a])\r\n\r\nAt that point GHC says there are two instances that match Foo [a], and which one\r\nto choose depends on how you instantiate a.\r\n\r\nWhat we wanted was to \"tie the knot\" and use Foo [a] recursively, the very one\r\nwe are constructing. GHC does that when solving Foo [a], but not when\r\nconstructing it.\r\n\r\nThis is a good point, I will think about it. It's a bit delicate. Meanwhile,\r\ncan you Trac it? It's a nice example.\r\n}}}\r\n\r\nA larger module showing how the instances above can be desirable in a real program is this (requires the syb-with-class package from hackage):\r\n{{{\r\n{-# LANGUAGE TemplateHaskell, FlexibleInstances, CPP,\r\n OverlappingInstances, UndecidableInstances #-}\r\n\r\nmodule Main where\r\n\r\nimport Data.Generics.SYB.WithClass.Basics\r\nimport Data.Generics.SYB.WithClass.Instances ()\r\n\r\ndata Element = Elem String [Element]\r\n | CData String\r\n deriving Show\r\n\r\nclass Data XmlD a => Xml a where\r\n toXml :: a -> [Element]\r\n toXml = defaultToXml\r\n\r\ndata XmlD a = XmlD { toXmlD :: a -> [Element] }\r\n\r\nxmlProxy :: Proxy XmlD\r\nxmlProxy = error \"xmlProxy\"\r\n\r\ninstance Xml t => Sat (XmlD t) where\r\n dict = XmlD { toXmlD = toXml }\r\n\r\ndefaultToXml :: Xml t => t -> [Element]\r\ndefaultToXml x = [Elem (constring $ toConstr xmlProxy x)\r\n (concat $ gmapQ xmlProxy (toXmlD dict) x)]\r\n\r\n-----\r\n\r\ninstance Data XmlD t => Xml t\r\n\r\n#ifdef STRING\r\ninstance Xml String where\r\n toXml x = [Elem \"string\" [CData x]]\r\n#endif\r\n\r\n#ifdef LIST\r\ninstance Xml a => Xml [a] where\r\n toXml = concatMap toXml\r\n#endif\r\n\r\nmain :: IO ()\r\nmain = do print $ toXml (Just True)\r\n print $ toXml [True, False]\r\n print $ toXml \"foo\"\r\n}}}\r\nwhich allows us to specialise XML marshalling for either lists (ignoring all the (:) and [] constructors) or strings (turn them into CData), but not both:\r\n{{{\r\n$ ghci -v0 -DLIST z.hs\r\n*Main> main\r\n[Elem \"Just\" [Elem \"True\" []]]\r\n[Elem \"True\" [],Elem \"False\" []]\r\n[Elem \"f\" [],Elem \"o\" [],Elem \"o\" []]\r\n*Main>\r\n$ ghci -v0 -DSTRING z.hs\r\n*Main> main\r\n[Elem \"Just\" [Elem \"True\" []]]\r\n[Elem \"(:)\" [Elem \"True\" [],Elem \"(:)\" [Elem \"False\" [],Elem \"[]\" []]]]\r\n[Elem \"string\" [CData \"foo\"]]\r\n*Main>\r\n$ ghci -v0 -DLIST -DSTRING z.hs\r\n[overlapping instances error]\r\n}}}\r\nIf we replace the\r\n{{{\r\ninstance Xml a => Xml [a] where\r\n}}}\r\nline with\r\n{{{\r\ninstance (Xml a, Xml [a]) => Xml [a] where\r\n}}}\r\nthen everything seems to work out, but this feels a little dodgy.","type_of_failure":"OtherFailure","blocking":[]} -->Simon Peyton JonesSimon Peyton Joneshttps://gitlab.haskell.org/ghc/ghc/-/issues/1481standalone deriving2019-07-07T19:13:19ZIan Lynagh <igloo@earth.li>standalone derivingSimon Peyton Jones, in http://www.haskell.org/pipermail/haskell-cafe/2007-June/026492.html, wrote:
```
Incidentally, for those interested in 'deriving', there's an open question about
what the syntax of standalone deriving should be
...Simon Peyton Jones, in http://www.haskell.org/pipermail/haskell-cafe/2007-June/026492.html, wrote:
```
Incidentally, for those interested in 'deriving', there's an open question about
what the syntax of standalone deriving should be
http://haskell.org/haskellwiki/GHC/StandAloneDeriving
I'd like to get this settled for 6.8.
```
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | ----------------------- |
| Version | 6.6.1 |
| Type | FeatureRequest |
| TypeOfFailure | OtherFailure |
| Priority | high |
| Resolution | Unresolved |
| Component | Compiler (Type checker) |
| Test case | |
| Differential revisions | |
| BlockedBy | |
| Related | |
| Blocking | |
| CC | |
| Operating system | Unknown |
| Architecture | Unknown |
</details>
<!-- {"blocked_by":[],"summary":"standalone deriving","status":"New","operating_system":"Unknown","component":"Compiler (Type checker)","related":[],"milestone":"6.8 branch","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"6.6.1","keywords":[],"differentials":[],"test_case":"","architecture":"Unknown","cc":[""],"type":"FeatureRequest","description":"Simon Peyton Jones, in http://www.haskell.org/pipermail/haskell-cafe/2007-June/026492.html, wrote:\r\n\r\n{{{\r\nIncidentally, for those interested in 'deriving', there's an open question about\r\nwhat the syntax of standalone deriving should be\r\n http://haskell.org/haskellwiki/GHC/StandAloneDeriving\r\nI'd like to get this settled for 6.8.\r\n}}}","type_of_failure":"OtherFailure","blocking":[]} -->6.8.1https://gitlab.haskell.org/ghc/ghc/-/issues/1482unsafeCoerce# doesn't always fully coerce2019-07-07T19:13:19Zyeoh@cs.wisc.eduunsafeCoerce# doesn't always fully coerce```
{-# OPTIONS_GHC -fglasgow-exts #-}
import GHC.Prim( unsafeCoerce# )
e1 = unsafeCoerce# (+)
e2 = unsafeCoerce# shows
```
`e1` coerces fine, even with the `Num` constraint, but `e2` does not. The error for e2 is
```
Ambiguous t...```
{-# OPTIONS_GHC -fglasgow-exts #-}
import GHC.Prim( unsafeCoerce# )
e1 = unsafeCoerce# (+)
e2 = unsafeCoerce# shows
```
`e1` coerces fine, even with the `Num` constraint, but `e2` does not. The error for e2 is
```
Ambiguous type variable `a' in the constraint:
`Show a' arising from use of `shows' at T.lhs:7:20-24
Probable fix: add a type signature that fixes these type variable(s)
```
Weirder still, ghci coerces `shows` fine:
```
*Main> :t unsafeCoerce# shows
unsafeCoerce# shows :: forall b. b
```
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | ----------------------- |
| Version | 6.6.1 |
| Type | Bug |
| TypeOfFailure | OtherFailure |
| Priority | normal |
| Resolution | Unresolved |
| Component | Compiler (Type checker) |
| Test case | |
| Differential revisions | |
| BlockedBy | |
| Related | |
| Blocking | |
| CC | |
| Operating system | |
| Architecture | |
</details>
<!-- {"blocked_by":[],"summary":"unsafeCoerce# doesn't always fully coerce","status":"New","operating_system":"","component":"Compiler (Type checker)","related":[],"milestone":"","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"6.6.1","keywords":["unsafeCoerce#"],"differentials":[],"test_case":"","architecture":"","cc":[""],"type":"Bug","description":"{{{\r\n{-# OPTIONS_GHC -fglasgow-exts #-}\r\n\r\nimport GHC.Prim( unsafeCoerce# )\r\n\r\ne1 = unsafeCoerce# (+)\r\ne2 = unsafeCoerce# shows\r\n}}}\r\n\r\n{{{e1}}} coerces fine, even with the {{{Num}}} constraint, but {{{e2}}} does not. The error for e2 is\r\n{{{\r\n Ambiguous type variable `a' in the constraint:\r\n `Show a' arising from use of `shows' at T.lhs:7:20-24\r\n Probable fix: add a type signature that fixes these type variable(s)\r\n}}}\r\n\r\nWeirder still, ghci coerces {{{shows}}} fine:\r\n{{{\r\n*Main> :t unsafeCoerce# shows\r\nunsafeCoerce# shows :: forall b. b\r\n}}}","type_of_failure":"OtherFailure","blocking":[]} -->https://gitlab.haskell.org/ghc/ghc/-/issues/1496Newtypes and type families combine to produce inconsistent FC(X) axiom sets2019-07-07T19:13:13ZStefan O'Rear <stefanor@cox.net>Newtypes and type families combine to produce inconsistent FC(X) axiom setsGiven:
```
{-# OPTIONS_GHC -ftype-families #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
data family Z :: * -> *
newtype Moo = Moo Int
newtype instance Z Int = ZI Double
newtype instance Z Moo = ZM (Int,Int)
```
We generate the axi...Given:
```
{-# OPTIONS_GHC -ftype-families #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
data family Z :: * -> *
newtype Moo = Moo Int
newtype instance Z Int = ZI Double
newtype instance Z Moo = ZM (Int,Int)
```
We generate the axioms:
```
(from the instances)
Z Int ~ Double
Z Moo ~ (Int,Int)
(from the newtype)
Moo ~ Int
```
And can prove:
```
(production REFL in the FC(X) paper)
Z ~ Z
(production COMP)
Z Moo ~ Z Int
(production TRANS)
Z Moo ~ Double
(production SYM)
Double ~ Z Moo
(production TRANS)
Double ~ (Int,Int)
```
Tickling this seems to require the newtype cheat, but the inconsistant axioms
allow code to pass Core Lint and still crash:
```
newtype Moo = Moo Int deriving(IsInt)
class IsInt t where
isInt :: c Int -> c t
instance IsInt Int where isInt = id
main = case isInt (ZI 4.0) of ZM tu -> print tu
```
```
stefan@stefans:/tmp$ ghc -dcore-lint Z.hs
stefan@stefans:/tmp$ ./a.out
Segmentation fault
stefan@stefans:/tmp$ ghc -V
The Glorious Glasgow Haskell Compilation System, version 6.7.20070612
stefan@stefans:/tmp$
```7.6.2Simon Peyton JonesSimon Peyton Joneshttps://gitlab.haskell.org/ghc/ghc/-/issues/1608Newtype deriving error messages coming out too late2019-07-07T19:12:38ZSimon Peyton JonesNewtype deriving error messages coming out too lateConsider this
```
newtype Ego a = Ego a deriving (Ord)
f :: Ord a => Ego a -> Ego a -> Bool
f e1 e2 = e1 < e2
```
GHC 6.7 reports an error like this:
```
Could not deduce (Eq (Ego a)) from the context (Ord a)
arising from a...Consider this
```
newtype Ego a = Ego a deriving (Ord)
f :: Ord a => Ego a -> Ego a -> Bool
f e1 e2 = e1 < e2
```
GHC 6.7 reports an error like this:
```
Could not deduce (Eq (Ego a)) from the context (Ord a)
arising from a use of `<' at Foo10.hs:6:10-16
In the expression: e1 < e2
In the definition of `f': f e1 e2 = e1 < e2
```
This error should have come when you gave the instance decl. The reason is that GHC's newtype deriving is generating an instance like
```
instance Eq (Ego a) => Ord (Ego a)
```
It would make more sense to report the missing instance for Eq right there, rather than abstracting over it.
Thanks to Dougal Stanton for pointing this out: http://www.haskell.org/pipermail/haskell-cafe/2007-August/030224.html
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | ----------------------- |
| Version | 6.6.1 |
| Type | Bug |
| TypeOfFailure | OtherFailure |
| Priority | normal |
| Resolution | Unresolved |
| Component | Compiler (Type checker) |
| Test case | |
| Differential revisions | |
| BlockedBy | |
| Related | |
| Blocking | |
| CC | |
| Operating system | Unknown |
| Architecture | Unknown |
</details>
<!-- {"blocked_by":[],"summary":"Newtype deriving error messages coming out too late","status":"New","operating_system":"Unknown","component":"Compiler (Type checker)","related":[],"milestone":"6.10 branch","resolution":"Unresolved","owner":{"tag":"OwnedBy","contents":"simonpj"},"version":"6.6.1","keywords":[],"differentials":[],"test_case":"","architecture":"Unknown","cc":[""],"type":"Bug","description":"Consider this\r\n{{{\r\nnewtype Ego a = Ego a deriving (Ord)\r\n\r\nf :: Ord a => Ego a -> Ego a -> Bool\r\nf e1 e2 = e1 < e2\r\n}}}\r\nGHC 6.7 reports an error like this:\r\n{{{\r\n Could not deduce (Eq (Ego a)) from the context (Ord a)\r\n arising from a use of `<' at Foo10.hs:6:10-16\r\n In the expression: e1 < e2\r\n In the definition of `f': f e1 e2 = e1 < e2\r\n}}}\r\nThis error should have come when you gave the instance decl. The reason is that GHC's newtype deriving is generating an instance like\r\n{{{\r\ninstance Eq (Ego a) => Ord (Ego a)\r\n}}}\r\nIt would make more sense to report the missing instance for Eq right there, rather than abstracting over it.\r\n\r\nThanks to Dougal Stanton for pointing this out: http://www.haskell.org/pipermail/haskell-cafe/2007-August/030224.html","type_of_failure":"OtherFailure","blocking":[]} -->6.10 branchSimon Peyton JonesSimon Peyton Joneshttps://gitlab.haskell.org/ghc/ghc/-/issues/1614Type checker does not use functional dependency to avoid ambiguity2019-07-07T19:12:36ZguestType checker does not use functional dependency to avoid ambiguityCompiling the following module gives an error
```
module X where
class C a | -> a
instance C Int
unC :: (C a) => a -> Int
unC i = undefined
test :: Int
test = unC undefined
```
Error message:
```
X.hs:13:7:
Ambiguous type varia...Compiling the following module gives an error
```
module X where
class C a | -> a
instance C Int
unC :: (C a) => a -> Int
unC i = undefined
test :: Int
test = unC undefined
```
Error message:
```
X.hs:13:7:
Ambiguous type variable `a' in the constraint:
`C a' arising from a use of `unC' at X.hs:13:7-19
Probable fix: add a type signature that fixes these type variable(s)
```
But that is just plain wrong. The functional dependency in the definition of C forces a to be Int. No other type is possible. So what's ambiguous about that?
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | ----------------------- |
| Version | 6.7 |
| Type | Bug |
| TypeOfFailure | OtherFailure |
| Priority | normal |
| Resolution | Unresolved |
| Component | Compiler (Type checker) |
| Test case | |
| Differential revisions | |
| BlockedBy | |
| Related | |
| Blocking | |
| CC | lennart@augustsson.net |
| Operating system | MacOS X |
| Architecture | x86 |
</details>
<!-- {"blocked_by":[],"summary":"Type checker does not use fundep to avoid ambiguity","status":"New","operating_system":"MacOS X","component":"Compiler (Type checker)","related":[],"milestone":"","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"6.7","keywords":[],"differentials":[],"test_case":"","architecture":"x86","cc":["lennart@augustsson.net"],"type":"Bug","description":"Compiling the following module gives an error\r\n{{{\r\nmodule X where\r\n\r\nclass C a | -> a\r\ninstance C Int\r\n\r\nunC :: (C a) => a -> Int\r\nunC i = undefined\r\n\r\ntest :: Int\r\ntest = unC undefined\r\n}}}\r\nError message:\r\n{{{\r\nX.hs:13:7:\r\n Ambiguous type variable `a' in the constraint:\r\n `C a' arising from a use of `unC' at X.hs:13:7-19\r\n Probable fix: add a type signature that fixes these type variable(s)\r\n}}}\r\n\r\nBut that is just plain wrong. The functional dependency in the definition of C forces a to be Int. No other type is possible. So what's ambiguous about that?","type_of_failure":"OtherFailure","blocking":[]} -->https://gitlab.haskell.org/ghc/ghc/-/issues/1624internal error caused by adding an instance to a type class with a functional...2019-07-07T19:12:33ZBertram Felgenhauerinternal error caused by adding an instance to a type class with a functional dependency and a default methodI've got trouble with the following program:
```
{-# LANGUAGE MultiParamTypeClasses, FunctionalDependencies #-}
class Foo a b | a -> b where
foo :: a -> b
foo = undefined
instance Foo a (Maybe a)
```
This results in a type che...I've got trouble with the following program:
```
{-# LANGUAGE MultiParamTypeClasses, FunctionalDependencies #-}
class Foo a b | a -> b where
foo :: a -> b
foo = undefined
instance Foo a (Maybe a)
```
This results in a type checking error, and an internal error:
```
xx.hs:2:0:
Couldn't match expected type `b' (a rigid variable)
against inferred type `Maybe a'
`b' is bound by the class declaration for `Foo'
When using functional dependencies to combine
Foo a (Maybe a), arising from the instance declaration at x.hs:8:0
Foo a b,
arising from is bound by the class declaration for `Foo'
at x.hs:(2,0)-(4,18)
[snip]
x.hs:6:0:
GHC internal error: `Main.$dmfoo' is not in scope
In the expression: Main.$dmfoo
In the definition of `foo': foo = Main.$dmfoo
In the definition for method `foo'
```
Slightly less convincing variations on the scheme are
```
class Foo a b | a -> b
instance Foo a (Maybe a)
foo :: Foo a b => a -> b
foo = undefined
class Bar a b c
instance (Foo a b, Foo b c) => Bar a b c
```
Both the definition of `foo` and the instance declaration of `Bar` give a type checking error "when combining functional dependencies".
Apparently `ghc` doesn't use functional dependencies to simplify the contexts of user supplied type signatures; I think the above examples indicate that it should.
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | ----------------------- |
| Version | 6.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":"internal error caused by adding an instance to a type class with a functional dependency and a default method","status":"New","operating_system":"","component":"Compiler (Type checker)","related":[],"milestone":"","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"6.7","keywords":[],"differentials":[],"test_case":"","architecture":"","cc":[""],"type":"Bug","description":"I've got trouble with the following program:\r\n{{{\r\n{-# LANGUAGE MultiParamTypeClasses, FunctionalDependencies #-}\r\nclass Foo a b | a -> b where\r\n foo :: a -> b\r\n foo = undefined\r\n\r\ninstance Foo a (Maybe a)\r\n}}}\r\nThis results in a type checking error, and an internal error:\r\n{{{\r\nxx.hs:2:0:\r\n Couldn't match expected type `b' (a rigid variable)\r\n against inferred type `Maybe a'\r\n `b' is bound by the class declaration for `Foo'\r\n When using functional dependencies to combine\r\n Foo a (Maybe a), arising from the instance declaration at x.hs:8:0\r\n Foo a b,\r\n arising from is bound by the class declaration for `Foo'\r\n at x.hs:(2,0)-(4,18)\r\n[snip]\r\nx.hs:6:0:\r\n GHC internal error: `Main.$dmfoo' is not in scope\r\n In the expression: Main.$dmfoo\r\n In the definition of `foo': foo = Main.$dmfoo\r\n In the definition for method `foo'\r\n}}}\r\nSlightly less convincing variations on the scheme are\r\n{{{\r\nclass Foo a b | a -> b\r\ninstance Foo a (Maybe a)\r\n\r\nfoo :: Foo a b => a -> b\r\nfoo = undefined\r\n\r\nclass Bar a b c\r\n\r\ninstance (Foo a b, Foo b c) => Bar a b c\r\n}}}\r\nBoth the definition of {{{foo}}} and the instance declaration of {{{Bar}}} give a type checking error \"when combining functional dependencies\".\r\n\r\nApparently {{{ghc}}} doesn't use functional dependencies to simplify the contexts of user supplied type signatures; I think the above examples indicate that it should.","type_of_failure":"OtherFailure","blocking":[]} -->Simon Peyton JonesSimon Peyton Joneshttps://gitlab.haskell.org/ghc/ghc/-/issues/1634Type signature normalization2019-07-07T19:12:29Zkfrdbs@gmail.comType signature normalization```
t1 :: a->(forall b. b->(a,b))
-- isn't this the same as forall a b. a->b->(a,b)
t1 = (,)
```
causes
```
Inferred type is less polymorphic than expected
Quantified type variable `b' escapes
Probable cause: `(,)' is ap...```
t1 :: a->(forall b. b->(a,b))
-- isn't this the same as forall a b. a->b->(a,b)
t1 = (,)
```
causes
```
Inferred type is less polymorphic than expected
Quantified type variable `b' escapes
Probable cause: `(,)' is applied to too few arguments
In the expression: (,)
In the definition of `t1': t1 = (,)
```
The problem goes away without the explicit signature.
-- KeferIan Lynagh <igloo@earth.li>Ian Lynagh <igloo@earth.li>https://gitlab.haskell.org/ghc/ghc/-/issues/1651panic when interactively evaluating expression with a family type2019-07-07T19:12:23ZManuel M T Chakravartypanic when interactively evaluating expression with a family type```
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE EmptyDataDecls #-}
newtype Succ a = Succ a deriving Show
data Zero = Zero
instance Show Zero where show _ = "Zero"
type family Add a b
type instance Add Zero a = a
type instance A...```
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE EmptyDataDecls #-}
newtype Succ a = Succ a deriving Show
data Zero = Zero
instance Show Zero where show _ = "Zero"
type family Add a b
type instance Add Zero a = a
type instance Add (Succ n) m = Succ (Add n m)
add :: a -> b -> Add a b
add = undefined
okay = show $ add Zero Zero
bad = add Zero Zero
{- ghci transcript:
*Main> okay
"Zero"
*Main> bad
ghc-6.7.20070828: panic! (the 'impossible' happened)
(GHC version 6.7.20070828 for i386-unknown-linux):
readFilledBox t_a1D9{tv} [box]
Please report this as a GHC bug: http://www.haskell.org/ghc/reportabug
*Main> show bad
<interactive>:1:0:
No instance for (Show (Add Zero Zero))
arising from a use of `show' at <interactive>:1:0-7
Possible fix:
add an instance declaration for (Show (Add Zero Zero))
In the expression: show bad
In the definition of `it': it = show bad
-}
```
The panic arises as follows: `tcGhciStmts` calls `TcMatches.tcDoStmt` to type check `it <- bad`, which in turn evaluates
```
withBox liftedTypeKind $ \ pat_ty ->
tcMonoExpr rhs (mkAppTy m_ty pat_ty)
```
The `withBox` executes the `readfilledBox` that causes the panic, as `tcMonoExpr` promises to fill the boxes in its second argument. This promise is not fulfilled, as `tcMonoBox` defers the match `Add Zero Zero ~ IO t_ayP`.
Further up the call chain `tcGhciStmts` will eventually simplify the LIE and would discover the type mismatch (and hence abandon "Plan A", of which all this is part). Unfortunately, we never get there due to `withBox`s attempt to read `t_avP`.
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | ----------------------- |
| Version | 6.7 |
| Type | Bug |
| TypeOfFailure | OtherFailure |
| Priority | normal |
| Resolution | Unresolved |
| Component | Compiler (Type checker) |
| Test case | |
| Differential revisions | |
| BlockedBy | |
| Related | |
| Blocking | |
| CC | chak@cse.unsw.edu.au |
| Operating system | Unknown |
| Architecture | Unknown |
</details>
<!-- {"blocked_by":[],"summary":"panic when interactively evaluating expression with a family type","status":"New","operating_system":"Unknown","component":"Compiler (Type checker)","related":[],"milestone":"","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"6.7","keywords":[],"differentials":[],"test_case":"","architecture":"Unknown","cc":["chak@cse.unsw.edu.au"],"type":"Bug","description":"{{{\r\n{-# LANGUAGE TypeFamilies #-}\r\n{-# LANGUAGE EmptyDataDecls #-}\r\n\r\nnewtype Succ a = Succ a deriving Show\r\ndata Zero = Zero\r\ninstance Show Zero where show _ = \"Zero\"\r\n\r\ntype family Add a b\r\ntype instance Add Zero a = a\r\ntype instance Add (Succ n) m = Succ (Add n m)\r\n\r\nadd :: a -> b -> Add a b\r\nadd = undefined\r\n\r\nokay = show $ add Zero Zero\r\nbad = add Zero Zero\r\n\r\n{- ghci transcript:\r\n\r\n*Main> okay\r\n\"Zero\"\r\n*Main> bad\r\nghc-6.7.20070828: panic! (the 'impossible' happened)\r\n (GHC version 6.7.20070828 for i386-unknown-linux):\r\n readFilledBox t_a1D9{tv} [box]\r\n\r\nPlease report this as a GHC bug: http://www.haskell.org/ghc/reportabug\r\n\r\n*Main> show bad\r\n\r\n<interactive>:1:0:\r\n No instance for (Show (Add Zero Zero))\r\n arising from a use of `show' at <interactive>:1:0-7\r\n Possible fix:\r\n add an instance declaration for (Show (Add Zero Zero))\r\n In the expression: show bad\r\n In the definition of `it': it = show bad\r\n-}\r\n}}}\r\nThe panic arises as follows: `tcGhciStmts` calls `TcMatches.tcDoStmt` to type check `it <- bad`, which in turn evaluates\r\n{{{\r\n withBox liftedTypeKind $ \\ pat_ty -> \r\n tcMonoExpr rhs (mkAppTy m_ty pat_ty)\r\n}}}\r\nThe `withBox` executes the `readfilledBox` that causes the panic, as `tcMonoExpr` promises to fill the boxes in its second argument. This promise is not fulfilled, as `tcMonoBox` defers the match `Add Zero Zero ~ IO t_ayP`.\r\n\r\nFurther up the call chain `tcGhciStmts` will eventually simplify the LIE and would discover the type mismatch (and hence abandon \"Plan A\", of which all this is part). Unfortunately, we never get there due to `withBox`s attempt to read `t_avP`.","type_of_failure":"OtherFailure","blocking":[]} -->