如何在haskell中重新匯出單個物體?
我知道模塊可以重新匯出,但這是否也適用于單個物體(如函式)?
我試過這個例子:
檔案:SomeData.hs
module SomeData where
data SomeData = SomeData
檔案:ReExport.hs
module ReExport ( SomeData ) where
import SomeData
檔案:Main.hs
import ReExport
x = SomeData -- Error on this line: Illegal term-level use of the type constructor ‘SomeData’
單獨重新匯出編譯沒有問題,但是當我嘗試使用其中的任何內容時,我得到錯誤:Illegal term-level use of the type constructor 'SomeData'。在這種情況下,究竟ReExport.hs
出口的是什么?
uj5u.com熱心網友回復:
在這種情況下,ReExport.hs 究竟匯出了什么?
型別建構式,因此您可以SomeData
用作型別:
import ReExport
x :: SomeData
x = undefined
如果你定義了一個型別:
data SomeType = SomeData
因此,您正在匯出SomeType
.
如果您還想匯出資料建構式,請使用:
module ReExport (SomeData(SomeData)) where
import SomeData
然后你可以使用:
import ReExport
x :: SomeData
x = SomeData
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/495428.html
上一篇:我如何計算(>0)的型別?
下一篇:哈斯克爾警告