haskellhaskell-stack

How to import modules implicitly in a haskell stack project?


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.


Solution

  • 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.