5

假设有一个Foo不受我控制的库模块:

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

thing现在假设我有自己的库模块,它从模块中重新导出Foo

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

出于兼容性原因,我不想导出不同的thing. 我想确保我 export Foo.thing,这样如果用户同时导入FooBar模块,它们将得到相同的结果thing并且不会发生名称冲突。

现在假设我们有第三个模块使用Bar.

module Main where
import Bar

让我们将第三个加载到 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

而不是 ghci 和黑线鳕表明thing在 moduleBar有 type Foo.Foo,我希望它声明thing有 type Bar。有没有办法在不导出不同的情况下实现这一点thing

4

1 回答 1

0

除非我听到相反的证据,否则答案似乎是:你不能

于 2012-10-18T22:03:57.347 回答