Search code examples
haskellmoduleexportghcihaddock

Control documented type signature of re-exported function


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?


Solution

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