インポートしたモジュールの識別子を再度エクスポートするには、 module 宣言の ExportList の中で、
module ModuleName
のように指定すればよい。
これは、例えば、自作プロジェクトにある、複数のモジュールの識別子を、ひとつのモジュールからまとめてインポートできるようにしたい、などという場合に便利。
Example
Reexport.hs
module Reexport (
ToBeDefined(..)
, module Reexport.Foo
, module Reexport.Bar
) where
import Reexport.Foo
import Reexport.Bar
data ToBeDefined = ToBeDefined deriving (Show)
Reexport/Foo.hs
module Reexport.Foo where
data Foo = Foo deriving (Show)
func1 :: String -> Foo
func1 = undefined
Reexport/Bar.hs
module Reexport.Bar (
Bar(..)
, func2
) where
data Bar = Bar deriving (Show)
func2 :: String -> Bar
func2 = undefined
func3 :: Double -> Bar
func3 = undefined
で、実際にこの Reexport モジュールをインポートしてみると、
Main.hs
module Main where
import Reexport
-- $ ghci Main
-- GHCi, version 7.8.3: http://www.haskell.org/ghc/ :? for help
ghci> :show imports
:module +*Main -- added automatically
ghci> ToBeDefined
ToBeDefined
ghci> :i func1
func1 :: String -> Foo -- Defined at Reexport/Foo.hs:7:1
ghci> :i func2
func2 :: String -> Bar -- Defined at Reexport/Bar.hs:7:1
-- func3 は Reexport.Bar の ExportList に含まれていないので再エクスポートされない
ghci> :i func3
Top level:
Not in scope: ‘func3’
Perhaps you meant one of these:
‘func2’ (imported from Reexport),
‘func1’ (imported from Reexport)