LoginSignup
0
0

More than 1 year has passed since last update.

モジュールのre-exportの効率的なやり方

Posted at

Haskellにおいて、複数のモジュールからあるモジュールにシンボルをimportして、それらをまとめてexportする場合、"import as"形式を使うとよさそう。

module Reexporter
    ( module X
    , alpha
    ) where

import Mod1  as X (x, y)
import Mod2  as X (a, b)

alpha :: String
alpha = "hoge"

上記のように、re-exportしたいモジュール(Mod1, Mod2)を同じ名前"X"でimport asして、export listには"module X"と書く。上記の例ならMod1.x, Mod1.y, Mod2.a, Mod2.bをre-exportできる。

また、必要ならReexporter module自身にシンボル(上記の例では"alpha")を定義してexportもできる。これは通常のexport listの書き方と同様。

Reexporter module自身で定義したシンボルを全てexportしたい場合はどうするか? 個人的にはあまりそういうことをしないが、以下のようにexport listを書けばいいようだ。

module Reexporter
    ( module X
    , module Reexporter
    ) where

Reexporterというモジュール名を2回書かないといけないあたりがちょっとイケてないかなあ。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0