Dan*_*ton 5 haskell module export ghci haddock
假设有一个Foo不受我控制的库模块:
module Foo (Foo, thing) where
data Foo = Foo Int
thing :: Foo
thing = Foo 3
Run Code Online (Sandbox Code Playgroud)
现在假设我有自己的库模块,它thing从Foo模块重新导出.
module Bar (Foo.thing, getBar) where
import qualified Foo
type Bar = Foo.Foo
getBar :: Bar -> Int
getBar (Foo i) = i
Run Code Online (Sandbox Code Playgroud)
由于兼容性的原因,我不希望导出不同thing.我想确保导出Foo.thing,这样如果用户同时导入Foo和Bar模块,它们将获得相同的,thing并且不会有名称冲突.
现在假设我们有第三个使用的模块Bar.
module Main where
import Bar
Run Code Online (Sandbox Code Playgroud)
让我们将第三个加载到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
Run Code Online (Sandbox Code Playgroud)
而不是ghci和haddocks表明thing在模块中Bar有类型Foo.Foo,我希望它说明thing有类型Bar.有没有办法在不导出不同的情况下实现这一目标thing?
| 归档时间: |
|
| 查看次数: |
96 次 |
| 最近记录: |