In GHC 8:
{-# LANGUAGE DuplicateRecordFields #-}
data Dog = Dog { name::String }
data Human = Human { name::String }
dog = Dog "Spike"
main = putStrLn $ name dog
This code does not compile:
Ambiguous occurrence `name'
It could refer to either the field `name', defined at A.hs:4:22
or the field `name', defined at A.hs:3:18
How to correctly retrieve the name of my dog?
DisambiguateRecordFieldsDisambiguationExtension
extension? — ...Be sure to check out Nikita Volkov'srecords
library, which should make these extensions completely unnecessary. — (FTR: I don't think the writers of these extensions are doing a bad job, in fact I've usedRecordWildCards
in the past and found it to work reasonably well. Nevertheless, I daresay it's overall not the right approach.) – Danedanegeld