108

Is it possible to write a module in Haskell, which re-exports a module in addition to exporting everything visible inside?

Lets consider following module:

module Test where
import A

f x = x

This module exports everything defined inside, so it exports f but does not re-export anything imported from A.

On the other hand, if I want to re-export the module A:

module Test (
    module A,
    f
) where
import A

f x = x

Is there a way to re-export A and export everything defined in Test without needing to explicitly write every function defined within Test?

Chris Stryczynski
  • 30,145
  • 48
  • 175
  • 286
Wojciech Danilo
  • 11,573
  • 17
  • 66
  • 132

1 Answers1

153

There is a simple solution, just export the module from the module:

module Test
    ( module Test
    , module A
    ) where

import Prelude()
import A
f x = x
Thomas M. DuBuisson
  • 64,245
  • 7
  • 109
  • 166
  • Exploited [here](https://github.com/ndmitchell/tagsoup/commit/1f1fff1e9ce4bd3233a2ef9607287b5018b516a7#diff-430b750c0b6fd0e9461c82565a1345dcR8). – PyRulez Jan 26 '16 at 18:25
  • Also, any insight as to why this works? (Any documentation?) – PyRulez Jan 26 '16 at 18:31
  • 1
    @PyRulez The Haskell Report is the definitive source: https://www.haskell.org/onlinereport/haskell2010/haskellch5.html#x11-1000005.2 – Thomas M. DuBuisson Jan 26 '16 at 19:21