Skip to content

Unable to infer type when using DuplicateRecordFields

It seems to me that GHC should be able to easily infer the types for the record updates in this simple example. Is there a reason that it is unable to infer the type currently?

{-# LANGUAGE OverloadedLabels, DuplicateRecordFields #-}
module C where

main = do
  print aThing
  print bThing
  print (aThing { a = 5 } )
  print (bThing { a = 5 } )

data B = B { a :: Int} deriving Show

bThing = B 10

data A = A { a :: Int } deriving Show

aThing = A 10

{-

[1 of 1] Compiling C                ( C.hs, C.o )

C.hs:7:10: error:
    • Record update is ambiguous, and requires a type signature
    • In the first argument of ‘print’, namely ‘(aThing {a = 5})’
      In a stmt of a 'do' block: print (aThing {a = 5})
      In the expression:
        do { print aThing;
             print bThing;
             print (aThing {a = 5});
             print (bThing {a = 5}) }
-}
Trac metadata
Trac field Value
Version 7.10.3
Type Bug
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component Compiler
Test case
Differential revisions
BlockedBy
Related
Blocking
CC adamgundry
Operating system
Architecture
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information