This is gonna be a somewhat rambling request for comment/ideas about imports in Haskell. It’s spurred by Announcing Imp, a GHC plugin for automatically importing modules - #16 by atravers but is something I’ve thought about for a while.
I have been wondering about for a while is if an import plugin introducing a new import
syntax, with the following features, would be possible:
- Allow importing in a hierarchy a la Rust
- Reduce the syntax needed to do the “type and qualified module” idiom that people (or at least, me) often use, like importing the type
Vector
and qualified importing all ofData.Vector
underVector
name as well. - Support renaming
- Explicit namespaces only
What I’d like is something like:
use Data.Text (type Text, module as Text, module Encoding as Text)
-- with renaming
use Data.Text.Lazy (type Text as LText, module as LText, module Encoding as LText)
to mean
import qualified Data.Text as Text
import qualified Data.Text.Encoding as Text
import Data.Text (Text)
-- renaming
import qualified Data.Text as LText
import qualified Data.Text.Encoding as LText
import qualified Data.Text.Lazy
-- something like `type LText = Data.Text.Lazy.Text`, except done by the renamer
It would not support unqualified-as
imports at all - I just think that those are a mistake. I looked at GHC plugins briefly and it seems like extending what syntax import
allows wouldn’t be possible, hence use
. Can a renamer plugin do the renaming part? Is it possible at all?
There’s a few things disheartening me though: (1) required time and effort (2) that the entire Haskell module system just doesn’t work that well, and such a plugin as above would be just papering over that fact, but then actually changing it is fairly unfathomable. I sometimes wish we had “default”/“index” modules in directory hierarchies, inline-defined modules, module exports / “qualified exports” like Data.Text
exports a namespace/module called Encoding
which, i.e. Data.Text.Encoding
.