Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
  • Sign in / Register
  • GHC GHC
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
    • Locked Files
  • Issues 5,399
    • Issues 5,399
    • List
    • Boards
    • Service Desk
    • Milestones
    • Iterations
  • Merge requests 592
    • Merge requests 592
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
    • Test Cases
  • Deployments
    • Deployments
    • Releases
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Code review
    • Insights
    • Issue
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Glasgow Haskell CompilerGlasgow Haskell Compiler
  • GHCGHC
  • Issues
  • #7268
Closed
Open
Issue created Sep 24, 2012 by ToRA@trac-ToRA

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
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Assignee
Assign to
Time tracking