匯出建構函式
要匯出型別及其所有建構函式,必須使用以下語法:
module X (Person (..)) where
因此,對於名為 People.hs 的檔案中的以下頂級定義:
data Person = Friend String | Foe deriving (Show, Eq, Ord)
isFoe Foe = True
isFoe _ = False
頂部的這個模組宣告:
module People (Person (..)) where
只會輸出 Person 及其建構函式 Friend 和 Foe。
如果省略 module 關鍵字後面的匯出列表,則將匯出繫結在模組頂層的所有名稱:
module People where
將匯出 Person,其建構函式和 isFoe 函式。