Attached file `A.hs`

($1234).

Minimal testcase

GHC seems to only be using the first signature for pattern synonyms

GHC 8.0.2 allows this to compile:

```
{-# LANGUAGE PatternSynonyms #-}
module Pattern where
pattern Foo :: ()
pattern Foo :: Bool
pattern Foo = ()
```

but not this:

```
{-# LANGUAGE PatternSynonyms #-}
module Pattern where
pattern Foo :: Bool
pattern Foo :: ()
pattern Foo = ()
```

This compiles and ghci tells me the type of `Foo`

is `()`

:

```
{-# LANGUAGE PatternSynonyms #-}
module Pattern where
pattern Foo :: ()
pattern Foo :: Bool
pattern Foo <- _
where Foo = undefined
```

This doesn't compile (as expected):

```
{-# LANGUAGE PatternSynonyms #-}
module Pattern where
pattern Foo :: ()
pattern Foo :: Bool Bool
pattern Foo = ()
```

Trac field | Value |
---|---|

Version | 8.0.1 |

Type | Bug |

TypeOfFailure | OtherFailure |

Priority | normal |

Resolution | Unresolved |

Component | Compiler |

Test case | |

Differential revisions | |

BlockedBy | |

Related | |

Blocking | |

CC | |

Operating system | |

Architecture |

Yes, as 8.1 suggests, this constraint is redundant.

I encountered this in the trifecta library. It can be seen in the `rend`

and `restOfLine`

member functions of the `DeltaParsing`

class here https://hackage.haskell.org/package/trifecta-1.6/docs/src/Text.Trifecta.Combinators.html\#DeltaParsing (this is fixed in trifecta's HEAD now).

I imagine that this can happen when a top level constrained function is moved to be a member of a class.

GHC 8.0.1 is able to compile this without a problem and doesn't require FlexibleContexts.

```
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE ConstrainedClassMethods #-}
module A where
class C m where
foo :: C m => m ()
newtype N m a = N (m a)
deriving C
```

Compare the output of 8.0.1, 8.0.2 and 8.1. I turned on -fdefer-type-errors in order for -ddump-deriv to work.

```
$ ghc --version
The Glorious Glasgow Haskell Compilation System, version 8.0.1
$ ghc -ddump-deriv A.hs
[1 of 1] Compiling A ( A.hs, A.o )
==================== Derived instances ====================
Derived instances:
instance A.C m_aNK => A.C (A.N m_aNK) where
A.foo = GHC.Prim.coerce (A.foo :: m_ap1 ()) :: A.N m_ap1 ()
GHC.Generics representation types:
```

```
$ ghc --version
The Glorious Glasgow Haskell Compilation System, version 8.0.2
$ ghc A.hs
[1 of 1] Compiling A ( A.hs, A.o )
A.hs:10:12: error:
• Couldn't match type ‘m’ with ‘N m’
arising from the coercion of the method ‘foo’
from type ‘C m => m ()’ to type ‘C (N m) => N m ()’
‘m’ is a rigid type variable bound by
the deriving clause for ‘C (N m)’ at A.hs:10:12
• When deriving the instance for (C (N m))
$ ghc -ddump-deriv -fdefer-type-errors A.hs
[1 of 1] Compiling A ( A.hs, A.o )
==================== Derived instances ====================
Derived instances:
instance A.C m_awm => A.C (A.N m_awm) where
A.foo
= GHC.Prim.coerce
@(A.C m_ap0 => m_ap0 ()) @(A.C (A.N m_ap0) => A.N m_ap0 ()) A.foo
GHC.Generics representation types:
A.hs:11:12: warning: [-Wdeferred-type-errors]
• Couldn't match type ‘m’ with ‘N m’
arising from a use of ‘GHC.Prim.coerce’
‘m’ is a rigid type variable bound by
the instance declaration at A.hs:11:12
• In the expression:
GHC.Prim.coerce @(C m => m ()) @(C (N m) => N m ()) foo
In an equation for ‘foo’:
foo = GHC.Prim.coerce @(C m => m ()) @(C (N m) => N m ()) foo
When typechecking the code for ‘foo’
in a derived instance for ‘C (N m)’:
To see the code I am typechecking, use -ddump-deriv
In the instance declaration for ‘C (N m)’
• Relevant bindings include foo :: N m () (bound at A.hs:11:12)
```

There's no '8.0.2' version to report this against so I've chosen 8.1. GHC 8.1 gives very similar results:

```
$ ghc --version
The Glorious Glasgow Haskell Compilation System, version 8.1.20160930
$ ghc A.hs
[1 of 1] Compiling A ( A.hs, A.o )
A.hs:11:12: error:
• Couldn't match type ‘m’ with ‘N m’
arising from the coercion of the method ‘foo’
from type ‘C m => m ()’ to type ‘C (N m) => N m ()’
‘m’ is a rigid type variable bound by
the deriving clause for ‘C (N m)’ at A.hs:11:12
• When deriving the instance for (C (N m))
$ ghc -ddump-deriv -fdefer-type-errors A.hs
[1 of 1] Compiling A ( A.hs, A.o )
==================== Derived instances ====================
Derived instances:
instance A.C m_awK => A.C (A.N m_awK) where
A.foo
= GHC.Prim.coerce
@(A.C m_app => m_app ()) @(A.C (A.N m_app) => A.N m_app ()) A.foo
GHC.Generics representation types:
A.hs:11:12: warning: [-Wsimplifiable-class-constraints]
The constraint ‘C (N m)’ matches an instance declaration
instance C m => C (N m) -- Defined at A.hs:11:12
This makes type inference for inner bindings fragile;
either use MonoLocalBinds, or simplify it using the instance
A.hs:11:12: warning: [-Wdeferred-type-errors]
• Couldn't match type ‘m’ with ‘N m’
arising from a use of ‘GHC.Prim.coerce’
‘m’ is a rigid type variable bound by
the instance declaration at A.hs:11:12
• In the expression:
GHC.Prim.coerce @(C m => m ()) @(C (N m) => N m ()) foo
In an equation for ‘foo’:
foo = GHC.Prim.coerce @(C m => m ()) @(C (N m) => N m ()) foo
When typechecking the code for ‘foo’
in a derived instance for ‘C (N m)’:
To see the code I am typechecking, use -ddump-deriv
In the instance declaration for ‘C (N m)’
• Relevant bindings include foo :: N m () (bound at A.hs:11:12)
```

Trac field | Value |
---|---|

Version | 8.1 |

Type | Bug |

TypeOfFailure | OtherFailure |

Priority | normal |

Resolution | Unresolved |

Component | Compiler |

Test case | |

Differential revisions | |

BlockedBy | |

Related | |

Blocking | |

CC | |

Operating system | |

Architecture |

`Q`

is capable of being an instance of `MonadFix`

. The definition of `mfix`

is the same as `fixIO`

except that the `MVar`

handling is wrapped in `runIO`

.

```
instance MonadFix Q where
mfix k = do
m <- runIO newEmptyMVar
ans <- runIO (unsafeInterleaveIO (takeMVar m))
result <- k ans
runIO (putMVar m result)
pure result
```

Trac field | Value |
---|---|

Version | |

Type | FeatureRequest |

TypeOfFailure | OtherFailure |

Priority | normal |

Resolution | Unresolved |

Component | Template Haskell |

Test case | |

Differential revisions | |

BlockedBy | |

Related | |

Blocking | |

CC | |

Operating system | |

Architecture |