After considering the reasons here to always import modules explicitly (with the exception of Prelude
), I am trying to abide by this norm. However, this may sometimes be cumbersome. Is there any tool which would analyze working code and give a complete list of explicit imports?
The syntax for importing modules in a Haskell script is import <module name>. This must be done before defining any functions, so imports are usually done at the top of the file. One script can, of course, import several modules. Just put each import statement into a separate line.
A qualified import allows using functions with the same name imported from several modules, e.g. map from the Prelude and map from Data.
Prelude is a module that contains a small set of standard definitions and is included automatically into all Haskell modules.
A module in Haskell serves the dual purpose of controlling name-spaces and creating abstract data types.
A module in Haskell serves the dual purpose of controlling name-spaces and creating abstract data types. The top level of a module contains any of the various declarations we have discussed: fixity declarations, data and type declarations, class and instance declarations, type signatures, function definitions, and pattern bindings.
A Haskell program consists of a collection of modules. A module in Haskell serves the dual purpose of controlling name-spaces and creating abstract data types.
Although Haskell's module system is relatively conservative, there are many rules concerning the import and export of values. Most of these are obvious---for instance, it is illegal to import two different entities having the same name into the same scope.
Haskell solves this problem using qualified names. An import declaration may use the qualified keyword to cause the imported names to be prefixed by the name of the module imported. These prefixes are followed by the `.' character without intervening whitespace. [Qualifiers are part of the lexical syntax.
There is the -ddump-minimal-imports
flag for ghc
.
The results are placed in the file (module-name).imports
.
The -fno-code
ghc option is also helpful here (to avoid the code generation phase.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With