GHC issueshttps://gitlab.haskell.org/ghc/ghc/-/issues2019-07-07T19:11:58Zhttps://gitlab.haskell.org/ghc/ghc/-/issues/1729panic on type family2019-07-07T19:11:58Zjpbernardypanic on type familyGhc panics on this module:
```
{-# LANGUAGE TypeFamilies #-}
type family Element c :: *
f :: Element x
f = undefined
------
ghc-6.8.0.20070921: panic! (the 'impossible' happened)
(GHC version 6.8.0.20070921 for i386-unknown-linux):...Ghc panics on this module:
```
{-# LANGUAGE TypeFamilies #-}
type family Element c :: *
f :: Element x
f = undefined
------
ghc-6.8.0.20070921: panic! (the 'impossible' happened)
(GHC version 6.8.0.20070921 for i386-unknown-linux):
check_tau_type main:Main.Element{tc r5C} x{tv a5F} [tv]
Please report this as a GHC bug: http://www.haskell.org/ghc/reportabug
```Manuel M T ChakravartyManuel M T Chakravartyhttps://gitlab.haskell.org/ghc/ghc/-/issues/1723type unsafety with type family + GADT2019-07-07T19:12:00Zzunino@di.unipi.ittype unsafety with type family + GADTHere's *unsafeCoerce*:
```
type family Const a
type instance Const a = ()
data T a where T :: a -> T (Const a)
coerce :: forall a b . a -> b
coerce x = case T x :: T (Const b) of
T y -> y
```
Tested with GHC 6.9.20070918
...Here's *unsafeCoerce*:
```
type family Const a
type instance Const a = ()
data T a where T :: a -> T (Const a)
coerce :: forall a b . a -> b
coerce x = case T x :: T (Const b) of
T y -> y
```
Tested with GHC 6.9.20070918
Maybe, see also #345
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | ----------------------- |
| Version | 6.8 |
| 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":"type unsafety with type family + GADT","status":"New","operating_system":"Unknown","component":"Compiler (Type checker)","related":[],"milestone":"","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"6.8","keywords":[],"differentials":[],"test_case":"","architecture":"Unknown","cc":[""],"type":"Bug","description":"Here's ''unsafeCoerce'':\r\n{{{\r\ntype family Const a\r\ntype instance Const a = ()\r\n\r\ndata T a where T :: a -> T (Const a)\r\n\r\ncoerce :: forall a b . a -> b\r\ncoerce x = case T x :: T (Const b) of\r\n T y -> y\r\n}}}\r\nTested with GHC 6.9.20070918\r\n\r\nMaybe, see also #345","type_of_failure":"OtherFailure","blocking":[]} -->6.10 branchManuel M T ChakravartyManuel M T Chakravartyhttps://gitlab.haskell.org/ghc/ghc/-/issues/1722Code using type synonym families requires workarounds to compile2019-07-07T19:12:01Ztomasz.zielonka@gmail.comCode using type synonym families requires workarounds to compileI am trying to use type synonym families to create GADTs that can be used interchangably as both typed and untyped ASTs for a small programming language. Here are the (cut down & simplified) definitions:
```
data Typed
data Untyped
typ...I am trying to use type synonym families to create GADTs that can be used interchangably as both typed and untyped ASTs for a small programming language. Here are the (cut down & simplified) definitions:
```
data Typed
data Untyped
type family TU a b :: *
type instance TU Typed b = b
type instance TU Untyped b = ()
-- A type witness type, use eg. for pattern-matching on types
data Type a where
TypeInt :: Type Int
TypeBool :: Type Bool
TypeString :: Type String
TypeList :: Type t -> Type [t]
data Expr :: * -> * -> * {- tu a -} where
Const :: Type a -> a -> Expr tu (TU tu a)
Var2 :: String -> TU tu (Type a) -> Expr tu (TU tu a)
```
It mostly works, which still amazes me, but there are some small glitches. For example in some cases I have to use **(TU Typed Bool)** instead of
**Bool**, even if they should be equal (**type instance TU Typed b = b**). In other cases I have to artificially restrict or generalize functions' type signatures. Or I have to put type signatures in patterns. The biggest problem is that it isn't obvious which workaround is needed in a given case. For some cases I don't have a satisfactory workaround yet.
Perhaps these problems simply reflect immaturity of type synonym family support in GHC, but, on the other hand, it may be some simple bug which could be fixed for GHC 6.8.
I've created a set of test files which I will attach to this ticket. Run check.sh to see how GHC handles the original (inteded) code and the workarounds. But first set the path to ghc in the script.
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | ----------------------- |
| Version | 6.8 |
| 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":"Code using type synonym families requires workarounds to compile","status":"New","operating_system":"Unknown","component":"Compiler (Type checker)","related":[],"milestone":"","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"6.8","keywords":[],"differentials":[],"test_case":"","architecture":"Unknown","cc":[""],"type":"Bug","description":"I am trying to use type synonym families to create GADTs that can be used interchangably as both typed and untyped ASTs for a small programming language. Here are the (cut down & simplified) definitions:\r\n\r\n{{{\r\ndata Typed\r\ndata Untyped\r\n\r\ntype family TU a b :: *\r\ntype instance TU Typed b = b\r\ntype instance TU Untyped b = ()\r\n\r\n-- A type witness type, use eg. for pattern-matching on types\r\ndata Type a where\r\n TypeInt :: Type Int\r\n TypeBool :: Type Bool\r\n TypeString :: Type String\r\n TypeList :: Type t -> Type [t]\r\n\r\ndata Expr :: * -> * -> * {- tu a -} where\r\n Const :: Type a -> a -> Expr tu (TU tu a)\r\n Var2 :: String -> TU tu (Type a) -> Expr tu (TU tu a)\r\n}}}\r\n\r\nIt mostly works, which still amazes me, but there are some small glitches. For example in some cases I have to use '''(TU Typed Bool)''' instead of\r\n'''Bool''', even if they should be equal ('''type instance TU Typed b = b'''). In other cases I have to artificially restrict or generalize functions' type signatures. Or I have to put type signatures in patterns. The biggest problem is that it isn't obvious which workaround is needed in a given case. For some cases I don't have a satisfactory workaround yet.\r\n\r\nPerhaps these problems simply reflect immaturity of type synonym family support in GHC, but, on the other hand, it may be some simple bug which could be fixed for GHC 6.8.\r\n\r\nI've created a set of test files which I will attach to this ticket. Run check.sh to see how GHC handles the original (inteded) code and the workarounds. But first set the path to ghc in the script.","type_of_failure":"OtherFailure","blocking":[]} -->6.10 branchManuel M T ChakravartyManuel M T Chakravartyhttps://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":[]} -->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/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/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/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/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/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/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/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/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/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/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/1331indexed types panic: wrongKindOfFamily main:ShouldCompile.Sd{tc r6A}2021-02-24T11:23:39ZIan Lynagh <igloo@earth.li>indexed types panic: wrongKindOfFamily main:ShouldCompile.Sd{tc r6A}Lots of indexed types tests are hitting an unhandled case in wrongKindOfFamily, e.g.:
```
Simple1.hs:11:2:ghc-6.7.20070504: panic! (the 'impossible' happened)
(GHC version 6.7.20070504 for x86_64-unknown-linux):
wrongKindOfFam...Lots of indexed types tests are hitting an unhandled case in wrongKindOfFamily, e.g.:
```
Simple1.hs:11:2:ghc-6.7.20070504: panic! (the 'impossible' happened)
(GHC version 6.7.20070504 for x86_64-unknown-linux):
wrongKindOfFamily main:ShouldCompile.Sd{tc r6A}
```
Affected tests:
```
ATLoop(normal,optc)
GMapAssoc(normal,optc)
GMapTop(normal,optc)
Over(normal)
Records(normal,optc)
Simple1(normal,optc)
Simple10(normal)
Simple11a(normal)
Simple11b(normal)
Simple11c(normal)
Simple11d(normal)
Simple1a(normal)
Simple2(normal,optc)
Simple3(normal,optc)
Simple4(normal,optc)
Simple5(normal,optc)
Simple5a(normal)
Simple5b(normal)
Simple6(normal,optc)
Simple7(normal)
Simple9(normal)
impexp(normal,optc)
ind1(normal,optc)
ind2(normal,optc)
```
<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":"indexed types panic: wrongKindOfFamily main:ShouldCompile.Sd{tc r6A}","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":"Lots of indexed types tests are hitting an unhandled case in wrongKindOfFamily, e.g.:\r\n{{{\r\nSimple1.hs:11:2:ghc-6.7.20070504: panic! (the 'impossible' happened)\r\n (GHC version 6.7.20070504 for x86_64-unknown-linux):\r\n wrongKindOfFamily main:ShouldCompile.Sd{tc r6A}\r\n}}}\r\nAffected tests:\r\n{{{\r\n ATLoop(normal,optc)\r\n GMapAssoc(normal,optc)\r\n GMapTop(normal,optc)\r\n Over(normal)\r\n Records(normal,optc)\r\n Simple1(normal,optc)\r\n Simple10(normal)\r\n Simple11a(normal)\r\n Simple11b(normal)\r\n Simple11c(normal)\r\n Simple11d(normal)\r\n Simple1a(normal)\r\n Simple2(normal,optc)\r\n Simple3(normal,optc)\r\n Simple4(normal,optc)\r\n Simple5(normal,optc)\r\n Simple5a(normal)\r\n Simple5b(normal)\r\n Simple6(normal,optc)\r\n Simple7(normal)\r\n Simple9(normal)\r\n impexp(normal,optc)\r\n ind1(normal,optc)\r\n ind2(normal,optc)\r\n}}}","type_of_failure":"OtherFailure","blocking":[]} -->6.8.1https://gitlab.haskell.org/ghc/ghc/-/issues/1313HEAD gives warnings about code that it generates itself2019-07-07T19:14:11ZIan Lynagh <igloo@earth.li>HEAD gives warnings about code that it generates itselfThe HEAD is now giving warnings about code that it generates itself, e.g.
```
module Q where
data Foo = Bar Int
```
gives
```
$ ghc -fforce-recomp -Wall -fgenerics -c q.hs
q.hs:4:5:
Warning: Definition but no type signature for ...The HEAD is now giving warnings about code that it generates itself, e.g.
```
module Q where
data Foo = Bar Int
```
gives
```
$ ghc -fforce-recomp -Wall -fgenerics -c q.hs
q.hs:4:5:
Warning: Definition but no type signature for `Q.$gtoFoo'
Inferred type: Q.$gtoFoo :: Int -> Foo
q.hs:4:5:
Warning: Definition but no type signature for `Q.$gfromFoo'
Inferred type: Q.$gfromFoo :: Foo -> Int
```
I assume that this is since the change which added the inferred type to the
warning, but I haven't confirmed 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 | |
| Operating system | Unknown |
| Architecture | Unknown |
</details>
<!-- {"blocked_by":[],"summary":"HEAD gives warnings about code that it generates itself","status":"New","operating_system":"Unknown","component":"Compiler (Type checker)","related":[],"milestone":"6.8 branch","resolution":"Unresolved","owner":{"tag":"OwnedBy","contents":"simonpj"},"version":"6.7","keywords":[],"differentials":[],"test_case":"","architecture":"Unknown","cc":[""],"type":"Bug","description":"The HEAD is now giving warnings about code that it generates itself, e.g.\r\n{{{\r\nmodule Q where\r\n\r\ndata Foo = Bar Int\r\n}}}\r\ngives\r\n{{{\r\n$ ghc -fforce-recomp -Wall -fgenerics -c q.hs\r\n\r\nq.hs:4:5:\r\n Warning: Definition but no type signature for `Q.$gtoFoo'\r\n Inferred type: Q.$gtoFoo :: Int -> Foo\r\n\r\nq.hs:4:5:\r\n Warning: Definition but no type signature for `Q.$gfromFoo'\r\n Inferred type: Q.$gfromFoo :: Foo -> Int\r\n}}}\r\nI assume that this is since the change which added the inferred type to the\r\nwarning, but I haven't confirmed that.","type_of_failure":"OtherFailure","blocking":[]} -->6.8.1Simon Peyton JonesSimon Peyton Joneshttps://gitlab.haskell.org/ghc/ghc/-/issues/1241Functional dependency Coverage Condition is lifted, and should not be2019-07-07T19:14:32ZguestFunctional dependency Coverage Condition is lifted, and should not beHello,
GHC 6.6 (with flags `-fglasgow-exts -fallow-undecidable-instances`) is too liberal when accepting instances. Here is an example:
```
class F a b | a -> b where f :: (a,b)
instance F Int b
```
The instance violates the functional...Hello,
GHC 6.6 (with flags `-fglasgow-exts -fallow-undecidable-instances`) is too liberal when accepting instances. Here is an example:
```
class F a b | a -> b where f :: (a,b)
instance F Int b
```
The instance violates the functional dependency constraint of `F` because (in theory) it can be used to solve both `F Int Bool` and `F Int Char`. In practice, it seems that some free variable gets bound upon the first use of `f` with a concrete type, leading to some rather confusing behavior. Example:
```
x :: (Int,a)
x = f
y :: (Int,Bool)
y = f
z :: (Int,Char)
z = x -- works, but 'z = f' does not
```
-Iavorhttps://gitlab.haskell.org/ghc/ghc/-/issues/1220Newtype deriving should only work if superclasses are newtype-derived2019-07-07T19:14:38ZSimon Peyton JonesNewtype deriving should only work if superclasses are newtype-derivedTwan van Laarhoven writes: I just noticed some unexpected consequences of the way newtype deriving is implemented in GHC. Because the dictionary of the underlying type is reused, so are base classes. This message is a literate Haskell pr...Twan van Laarhoven writes: I just noticed some unexpected consequences of the way newtype deriving is implemented in GHC. Because the dictionary of the underlying type is reused, so are base classes. This message is a literate Haskell program
illustrating the problem.
```
> {-# OPTIONS_GHC -fglasgow-exts #-}
```
This problem comes up when an instance method calls a method of a base
class. Consider the following useless example:
```
> class Show a => Show2 a where
> show2 :: a -> String
> show2 = show
>
> instance Show2 Int
```
Now consider a type deriving Show2, but having a different
implementation of Show (also derived).
```
> newtype Meter = Meter Int
> deriving (Eq, Show, Show2)
```
Now, for show2 the derived Show instance (which also shows the
constructor name) is \*not\* used, instead the Show Int instance is used:
```
] > show2 (Meter 1)
] "1"
] > show (Meter 1)
] "Meter 1"
```
This is quite unexpected, unless you consider what is going on behind
the scenes. Even more confusingly, GHC requires that there is a Show
instance for Meters, even if it will not be used!
```
] No instance for (Show Meter)
] arising from the superclasses of an instance declaration at ...
] Probable fix: add an instance declaration for (Show Meter)
] In the instance declaration for `Show2 Meter'
```
This problem can come up whenever a class instance uses a function from
a base class. Right now this not likely happen, but it will become more
common if the standard classes are split up:
```
> class Additive a where
> add :: a -> a -> a
> class Additive a => Subtractive a where
> neg :: a -> a
> sub :: a -> a -> a
> sub x y = add x (neg y) -- calls base class function add
> class Functor m => Monad' m where
> return' :: a -> m a
> join' :: m (m a) -> m a
> join' x = bind' x id
> bind' :: m a -> (a -> m b) -> m b
> bind' ma k = join' (fmap k ma) -- calls base class function fmap
```
As a solution I would suggest that newtype deriving a class instance is
only allowed if all base classes instances are also derived using
newtype deriving. This presents problems for Show and Read, because they
cannot be derived in that way. It will, however, catch problems with
most other classes.
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | ------------------------------------- |
| Version | 6.6 |
| Type | Bug |
| TypeOfFailure | OtherFailure |
| Priority | normal |
| Resolution | Unresolved |
| Component | Compiler (Type checker) |
| Test case | |
| Differential revisions | |
| BlockedBy | |
| Related | |
| Blocking | |
| CC | Twan van Laarhoven [twanvl@gmail.com] |
| Operating system | Unknown |
| Architecture | Unknown |
</details>
<!-- {"blocked_by":[],"summary":"Newtype deriving should only work if superclasses are newtype-derived","status":"New","operating_system":"Unknown","component":"Compiler (Type checker)","related":[],"milestone":"6.8 branch","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"6.6","keywords":[],"differentials":[],"test_case":"","architecture":"Unknown","cc":["Twan van Laarhoven [twanvl@gmail.com]"],"type":"Bug","description":"Twan van Laarhoven writes: I just noticed some unexpected consequences of the way newtype deriving is implemented in GHC. Because the dictionary of the underlying type is reused, so are base classes. This message is a literate Haskell program\r\nillustrating the problem.\r\n{{{\r\n > {-# OPTIONS_GHC -fglasgow-exts #-}\r\n}}}\r\nThis problem comes up when an instance method calls a method of a base\r\nclass. Consider the following useless example:\r\n{{{\r\n > class Show a => Show2 a where\r\n > show2 :: a -> String\r\n > show2 = show\r\n >\r\n > instance Show2 Int\r\n}}}\r\nNow consider a type deriving Show2, but having a different\r\nimplementation of Show (also derived).\r\n{{{\r\n > newtype Meter = Meter Int\r\n > deriving (Eq, Show, Show2)\r\n}}}\r\nNow, for show2 the derived Show instance (which also shows the\r\nconstructor name) is *not* used, instead the Show Int instance is used:\r\n{{{\r\n] > show2 (Meter 1)\r\n] \"1\"\r\n] > show (Meter 1)\r\n] \"Meter 1\"\r\n}}}\r\nThis is quite unexpected, unless you consider what is going on behind\r\nthe scenes. Even more confusingly, GHC requires that there is a Show\r\ninstance for Meters, even if it will not be used!\r\n{{{\r\n] No instance for (Show Meter)\r\n] arising from the superclasses of an instance declaration at ...\r\n] Probable fix: add an instance declaration for (Show Meter)\r\n] In the instance declaration for `Show2 Meter'\r\n}}}\r\nThis problem can come up whenever a class instance uses a function from\r\na base class. Right now this not likely happen, but it will become more\r\ncommon if the standard classes are split up:\r\n{{{\r\n > class Additive a where\r\n > add :: a -> a -> a\r\n > class Additive a => Subtractive a where\r\n > neg :: a -> a\r\n > sub :: a -> a -> a\r\n > sub x y = add x (neg y) -- calls base class function add\r\n\r\n > class Functor m => Monad' m where\r\n > return' :: a -> m a\r\n > join' :: m (m a) -> m a\r\n > join' x = bind' x id\r\n > bind' :: m a -> (a -> m b) -> m b\r\n > bind' ma k = join' (fmap k ma) -- calls base class function fmap\r\n}}}\r\nAs a solution I would suggest that newtype deriving a class instance is\r\nonly allowed if all base classes instances are also derived using\r\nnewtype deriving. This presents problems for Show and Read, because they\r\ncannot be derived in that way. It will, however, catch problems with\r\nmost other classes.","type_of_failure":"OtherFailure","blocking":[]} -->6.8.2https://gitlab.haskell.org/ghc/ghc/-/issues/1214Iface type variable out of scope2019-07-07T19:14:39ZIan Lynagh <igloo@earth.li>Iface type variable out of scopeChristophe Poucet reports the below bug; the 6.6 branch is broken, but the HEAD works.
----
While working some code I stumbled into a bug with GHC. Basically I have a
GADT that has a phantom-type for all but one of it's data constructo...Christophe Poucet reports the below bug; the 6.6 branch is broken, but the HEAD works.
----
While working some code I stumbled into a bug with GHC. Basically I have a
GADT that has a phantom-type for all but one of it's data constructors. When
I try to store a record-type in that tag it gives me a problem due to
interfaces when I recompile something against the interface file containing
the GADT. Namely, it complains that the type variable is out of scope.
The code in question (after treeing to find out what the actual problem was,
namely the combination of GADTs with records) is the following:
```
-- AST.hs
{-# OPTIONS_GHC -fglasgow-exts #-}
module AST where
data Exp_;
data AST :: * -> * -> * where
Var :: String -> AST Exp_ tag
Tag :: tag -> AST a tag -> AST a tag
```
```
-- Main.hs
module Main where
import AST
data Foo = Foo { bar :: Int }
convert :: AST a tag -> AST a Foo
convert t = case t of
Var v -> Tag (Foo 42) $ Var v
Tag t e -> Tag (Foo 42) $ convert e
main = return ()
```
The bug is easily replicated with the following commands:
```
> ghc --make Main.hs
-- Works fine
> touch Main.hs
> ghc --make Main.hs
-- The interface for `main:AST'
-- Declaration for AST
-- Constructor AST.Tag:
-- Iface type variable out of scope: tag
-- Cannot continue after interface file error
> rm -f Main.hi Main.o AST.hi AST.o
> ghc --make Main.hs
-- Works fine
```
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | ----------------------- |
| Version | 6.6 |
| 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":"Iface type variable out of scope","status":"New","operating_system":"Unknown","component":"Compiler (Type checker)","related":[],"milestone":"6.6.2","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"6.6","keywords":[],"differentials":[],"test_case":"","architecture":"Unknown","cc":[""],"type":"Bug","description":"Christophe Poucet reports the below bug; the 6.6 branch is broken, but the HEAD works.\r\n\r\n----\r\n\r\nWhile working some code I stumbled into a bug with GHC. Basically I have a\r\nGADT that has a phantom-type for all but one of it's data constructors. When\r\nI try to store a record-type in that tag it gives me a problem due to\r\ninterfaces when I recompile something against the interface file containing\r\nthe GADT. Namely, it complains that the type variable is out of scope.\r\n\r\nThe code in question (after treeing to find out what the actual problem was,\r\nnamely the combination of GADTs with records) is the following:\r\n{{{\r\n-- AST.hs\r\n{-# OPTIONS_GHC -fglasgow-exts #-}\r\nmodule AST where\r\n\r\ndata Exp_;\r\n\r\ndata AST :: * -> * -> * where\r\n Var :: String -> AST Exp_ tag\r\n Tag :: tag -> AST a tag -> AST a tag\r\n}}}\r\n{{{\r\n-- Main.hs\r\nmodule Main where\r\nimport AST\r\n\r\ndata Foo = Foo { bar :: Int }\r\n\r\nconvert :: AST a tag -> AST a Foo\r\nconvert t = case t of\r\n Var v -> Tag (Foo 42) $ Var v\r\n Tag t e -> Tag (Foo 42) $ convert e\r\n\r\nmain = return ()\r\n}}}\r\n\r\nThe bug is easily replicated with the following commands:\r\n\r\n{{{\r\n> ghc --make Main.hs\r\n -- Works fine\r\n> touch Main.hs\r\n> ghc --make Main.hs\r\n -- The interface for `main:AST'\r\n -- Declaration for AST\r\n -- Constructor AST.Tag:\r\n -- Iface type variable out of scope: tag\r\n -- Cannot continue after interface file error\r\n> rm -f Main.hi Main.o AST.hi AST.o\r\n> ghc --make Main.hs\r\n -- Works fine\r\n}}}","type_of_failure":"OtherFailure","blocking":[]} -->6.8.1Simon Peyton JonesSimon Peyton Jones