For the most part, I have really enjoyed working with Haskell’s import system. It’s also an area I’ve run into confusing issues when the scenario is a bit more advanced than the simple imports we all normally do most of the time. In particular, I get a bit confused when trying to make an “Import” module that contains a bunch of re-exports for stuff I’m going use over and over in a bunch of other modules, or when normally using qualified, needing to drop that in certain scenarios.
For example, maybe the library is a client for some API, and you group functions into modules according to the upstream API, and then each of those modules has the same 20-lines of imports that you need for the API functions. Eventually, it seems better to consolidate the imports into a module that exports those functions/data types / modules you want to use (and then in each module there is a single
import Import rather than the 20).
http://dev.stephendiehl.com/hask/#packageimports and https://github.com/commercialhaskell/rio/blob/master/rio/src/RIO.hs are examples I could easily locate, though I have seen a few variants on this in the past.
A few questions:
- Do you know of any useful resources on this topic you would recommend?
- Or maybe you can help me scope out some of the best practices here?
- Out of the resources I’ve listed below are any of them grossly out of date?
- Is there a reasonable way to export multiple modules (such as
ByteString, given their conflicts over
concat/etc) from an
Some existing prior art, specifically on modules/imports:
EDIT: Text/ByteString (both lazy/regular) in particular (and vector sometimes as well) often push the experience over the edge from reasonable to unreasonable… any recommendations for wrangling the conflicts that result from using those libs together in practice? I generally succumb to hacks (such as keeping those out of my import module, and having a smaller group of qualified imports for the T/BL/BS group).