1

This isn't an important issue but I was just wondering if I have some modules in a stack (or cabal doesn't matter in this case) Haskell project, which are imported in a lot of other modules how to make them public so that I do not need to keep importing them? I also found out that importing modules is not transitive either. I mean this will not be an issue but it will save repetition in a big project. Thanks for your help in advance.

1
  • 1
    I think typically this is solved by making a module that re-exports. For example for a Yesod server, typically a module named Import is made that reexports all important aspects. Commented Nov 4, 2023 at 10:36

1 Answer 1

2

I also found out that importing modules is not transitive either.

That is indeed correct. But you can reexport items. This is what is often done to minimize imports. For example if you create a Yesod webserver, typically there is a module named Import that re-exports all important aspects.

You can re-export by simply mentioning variables that are in scope in the module in the export list. For example we can make a module Import that exports maybe and either from two modules:

module Import (maybe, either) where

import Data.Either (either)
import Data.Maybe (maybe)

By then importing the Import module, we get maybe an either in scope, and these originate from two different modules.

Sign up to request clarification or add additional context in comments.

1 Comment

I'd add that you can also export all entities from a module using module exports as described in point 5 in section 5.2 of the standard: haskell.org/onlinereport/haskell2010/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.