Error: Multiple declarations

I got this error when building a code. Please help.

{-# DuplicateRecordFields #-}

module Main where

data Human = Human {name :: String}
data Dog = Dog {name :: String}

main :: IO ()
main = putStrLn “Hello, Haskell!”

   src/Main.hs:6:17: error:
   Multiple declarations of ‘name’
   Declared at: src/Main.hs:5:21
                src/Main.hs:6:17
   |
 6 | data Dog = Dog {name :: String}
   |                 ^^^^

Be careful:

{-# DuplicateRecordFields #-}

should be

{-# Language DuplicateRecordFields #-}

Also mind that even using the extension, some patterns are still ambiguous

-- Will not compile
changeName hum nnam = hum { name = nnam }
1 Like

Thank you for the help.

1 Like