Explicit type signatures for top level record pattern matches polymorphism fail
Consider the following module, which declares a record with two fields (X), an instance of this record (x), and then (at the top level) pattern matches the fields of x to create two new functions.
{-# LANGUAGE RankNTypes #-}
module Foo where
data X
= X { a :: forall a . a -> a , b :: Int -> Int }
x :: X
x = X { a = id, b = succ }
succ' :: Int -> Int
X { a = id', b = succ' } = x
If we ask ghci what the type of id' is, we get told:
:t id'
id' :: a -> a
However adding this type explicitly, gives the following:
Foo.hs:15:9:
Couldn't match expected type `forall a. a -> a'
with actual type `a -> a'
In the pattern: X {a = id', b = succ'}
In a pattern binding: X {a = id', b = succ'} = x
Failed, modules loaded: none.
This can happen in practice when using (e.g.) Parsec's TokenParser.
Trac metadata
Trac field | Value |
---|---|
Version | 7.4.1 |
Type | Bug |
TypeOfFailure | OtherFailure |
Priority | normal |
Resolution | Unresolved |
Component | Compiler (Type checker) |
Test case | |
Differential revisions | |
BlockedBy | |
Related | |
Blocking | |
CC | |
Operating system | |
Architecture |