5

Suppose there is a library module Foo which is not under my control:

module Foo (Foo, thing) where
data Foo = Foo Int
thing :: Foo
thing = Foo 3

Now suppose I have my own library module, which re-exports thing from the Foo module.

module Bar (Foo.thing, getBar) where
import qualified Foo
type Bar = Foo.Foo
getBar :: Bar -> Int
getBar (Foo i) = i

For compatibility reasons, I do not want to export a different thing. I want to make sure I export Foo.thing, so that if the user imports both the Foo and Bar modules, they will get the same thing and there will not be a name clash.

Now suppose we have a third module that uses Bar.

module Main where
import Bar

Let's load the third into ghci.

[1 of 3] Compiling Foo              ( Foo.hs, interpreted )
[2 of 3] Compiling Bar              ( Bar.hs, interpreted )
[3 of 3] Compiling Main             ( test.hs, interpreted )
Ok, modules loaded: Main, Bar, Foo.
ghci> :t thing
thing :: Foo.Foo
ghci> :t getBar
getBar :: Bar -> Int
ghci> getBar thing
3
ghci> :info Bar
type Bar = Foo.Foo  -- Defined at Bar.hs:3:6-8

Instead of ghci and the haddocks indicating that thing in module Bar has type Foo.Foo, I'd like it to state that thing has type Bar. Is there any way to make this happen without exporting a different thing?

Dan Burton
  • 53,238
  • 27
  • 117
  • 198
  • Wait, wouldn't there be a clash if the user imports both modules? – Gabriella Gonzalez Aug 24 '12 at 16:22
  • @GabrielGonzalez try adding `import Foo` to the third file, and see for yourself! (there's not a clash since they both export *the same* `thing`.) In the event that both are imported, I would *still* like to tell ghci to prefer `Bar` over `Foo`. – Dan Burton Aug 24 '12 at 17:16
  • WOW! How long has that feature been available!?!?! This changes EVERYTHING. – Gabriella Gonzalez Aug 24 '12 at 18:46
  • 3
    @GabrielGonzalez: since always :) if you think about the number of things defined in the standard library and re-exported in the Prelude, you use this feature all the time. – Ben Millwood Sep 20 '12 at 18:33

1 Answers1

0

Unless I hear evidence to the contrary, the answer seems to be: you can't.

Dan Burton
  • 53,238
  • 27
  • 117
  • 198