2012-08-24 19 views
5

假設有一個庫模塊Foo這是不是我的控制之下:控制記錄類型簽名轉口功能

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

現在假設我有我自己的庫模塊,其中轉口thingFoo模塊。

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

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模塊Bar具有類型Foo.Foo的黑線鱈,我想它指出thing具有類型Bar。有沒有辦法做到這一點,而不會導出不同的thing

+0

等待,如果用戶導入兩個模塊,是不是會發生衝突? –

+0

@GabrielGonzalez嘗試在第三個文件中添加'import Foo',並親自查看! (因爲他們都輸出*相同的*'東西),所以沒有衝突。)如果兩者都輸入了,我會*仍然*喜歡告訴ghci比'Foo'更喜歡'Bar'。 –

+0

哇!該功能可用多久!?!?!這改變了一切。 –

回答

0

除非我聽到相反的證據,答案似乎是:你不能