2012-08-24 6 views
5

私のコントロール下にないライブラリモジュールFooがあるとしますコントロール文書型シグネチャ

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

は今、私はFooからthingを輸出し直す自分のライブラリモジュールを、持っていると仮定モジュール。互換性の理由から

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

、私はは異なるthingをエクスポートする必要はありませありません。 Foo.thingをエクスポートして、FooBarの両方のモジュールをインポートすると、同じthingが得られ、名前の衝突は発生しません。

ここで、Barを使用する第3のモジュールがあるとします。

module Main where 
import Bar 

ghciに3を読み込みましょう。代わりGHCiのモジュールBarthingFoo.Foo型を持つことを示すhaddocksの

[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 

、私はそれがthingBarを入力した状態たいです。異なるthingをエクスポートせずにこれを実行する方法はありますか?

+0

ユーザーが両方のモジュールをインポートすると、待ち時間がありません。 –

+0

@GabrielGonzalez 3番目のファイルに 'import Foo'を追加してみてください!両方とも輸入されている場合、ghciに 'Foo'より' Bar'を優先させるように依頼したいと思います。 –

+0

WOW!この機能はどれくらいの期間利用可能でしたか?これはすべての変更です。 –

答えて

0

逆の証拠がない限り、答えは次のようになります。できません。

関連する問題