The scaffolded site in Yesod generates an Import.hs
file which contains the following.
module Import
( module Import
) where
import Prelude as Import
import Yesod as Import
-- ...
What is this pattern for? My understanding is that it exports everything from the modules imported in the Import.hs
package, but wouldn't just module Import where
do the same thing? What is the meaning of the nested module
keyword inside the module Import (module Import) where ...
?
In the Haskell language report exporting a module is described as:
The form “module M” names the set of all entities that are in scope with both an unqualified name “e” and a qualified name “M.e”. This set may be empty.
§5.2 Export Lists
An export list identifies the entities to be exported by a module declaration. A module implementation may only export an entity that it declares, or that it imports from some other module. If the export list is omitted, all values, types and classes defined in the module are exported, but not those that are imported.
Entities in an export list may be named as follows:
...
The form “module M” names the set of all entities that are in scope with both an unqualified name “e” and a qualified name “M.e”. This set may be empty.
It means that the semantic of:
module Import
( module Import
) where
import Prelude as Import
import Yesod as Import
-- ...
is to take all that is contained in Prelude
and Yesod
modules and export it.
What you propose instead:
module Import where
would not export what's imported by Prelude
and Yesod
, as per quote above:
If the export list is omitted, all values, types and classes defined in the module are exported, but not those that are imported.
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