Conflicting exports [GHC-69158]

This error means that a module is trying to export two identifiers with the same name, but which are actually different because they were imported from separate modules. This can happen when at least one of the identifiers is re-exported using a qualified name, or all imported identifiers from a module are re-exported using the module keyword.

Examples

Name clash due to mix of qualified and unqualified re-export

Error Message

Greeting.hs:3:5: error: [GHC-69158]
    Conflicting exports for ‘greeting’:
       ‘W.greeting’ exports ‘W.greeting’
         imported qualified from ‘World’ at Greeting.hs:6:1-27
         (and originally defined at World.hs:4:1-8)
       ‘U.greeting’ exports ‘U.greeting’
         imported qualified from ‘Universe’ at Greeting.hs:7:1-30
         (and originally defined at Universe.hs:4:1-8)
  |
3 |   , U.greeting
  |     ^^^^^^^^^^

Explanation

This example defines the modules World and Universe, both of which export an identifier named greeting. The Greeting module then imports World and Universe qualified, meaning it can use both identifiers named greeting in the body of bothGreetings without any ambiguity. However, the export of both greetings in Greeting’s export list does cause ambiguity, because a module can only export one identifier with a given name.

In this case, we decide that we want to export just one default greeting, and that most users of our code won’t need to greet the entire universe. Therefore, we fix the error by removing the re-export of U.greeting.

If we still want to somehow export U.greeting in addition to W.greeting, we’ll have to define a new identifier and set it equal to U.greeting, and then export that instead. For example, we could define universalGreeting = U.greeting in the body of Greeting.

Greeting.hs
Before
module Greeting
  ( W.greeting
  , U.greeting
  ) where

import qualified World as W
import qualified Universe as U

bothGreetings :: String
bothGreetings = unlines [W.greeting, U.greeting]
After
module Greeting
  ( W.greeting
  ) where

import qualified World as W
import qualified Universe as U

bothGreetings :: String
bothGreetings = unlines [W.greeting, U.greeting]
Universe.hs
Before
module Universe where

greeting :: String
greeting = "Hello, Universe!"
After
module Universe where

greeting :: String
greeting = "Hello, Universe!"
World.hs
Before
module World where

greeting :: String
greeting = "Hello, World!"
After
module World where

greeting :: String
greeting = "Hello, World!"