Opened 3 years ago

Last modified 3 years ago

#12693 new feature request

Relax qualified import syntax

Reported by: cblp Owned by:
Priority: normal Milestone:
Component: Compiler (Parser) Version: 8.0.1
Keywords: import, qualified, syntax Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Test Case:
Blocked By: Blocking:
Related Tickets: 10478 Differential Rev(s):
Wiki Page:

Description

Problem

Case 1.

import Data.HashMap (HashMap)
import qualified Data.HashMap as HashMap
import Data.Map (Map)
import qualified Data.Map as Map
import Data.Set (Set)
import qualified Data.Set as Set
import Data.Text (Text)
import qualified Data.Text as Text

Module names start in different columns, so the user cannot search it without help of tools, so the code is unreadable.

Case 2.

import           Data.HashMap (HashMap)
import qualified Data.HashMap as HashMap
import           Data.Map (Map)
import qualified Data.Map as Map
import           Data.Set (Set)
import qualified Data.Set as Set
import           Data.Text (Text)
import qualified Data.Text as Text

Too many space used, too less space left for imported items list, too hard to maintain without special tools.

Proposal

Allow to write qualified keyword after module name:

import Data.HashMap (HashMap)
import Data.HashMap qualified as HashMap
import Data.Map (Map)
import Data.Map qualified as Map
import Data.Set (Set)
import Data.Set qualified as Set
import Data.Text (Text)
import Data.Text qualified as Text

All the problems solved!

This proposal looks a little like ShorterImportSyntax and #10478, but differs from them in such ways:

  1. It doesn't actually make imports shorter in visible symbols, only in lines used (in case of very long imported items list), a little.
  2. It doesn't introduce new syntax constructions looking like existing but doing other things.
  3. It is easy to implement and understand.
  4. It looks more natural from the point of view of English language.

Change History (2)

comment:1 Changed 3 years ago by goldfire

While this is a fine idea, I think the best place to have this discussion is as a GHC Proposal. See https://github.com/ghc-proposals/ghc-proposals. There, the community can weigh in on pros and cons of this proposal. If the community (and the GHC Committee) accept this request, then we can use a Trac ticket to track implementation.

Thanks for posting!

Note: See TracTickets for help on using tickets.