Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does the `import Some.Module as Import` in Yesod mean?

Tags:

haskell

yesod

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

like image 933
Jakub Arnold Avatar asked Jun 09 '14 23:06

Jakub Arnold


1 Answers

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.

like image 166
Shoe Avatar answered Nov 15 '22 10:11

Shoe