Multiple imports on a single line

Hello! What do you think about an idea to have multiple imports on a single line, like: module MyApp where import Data.Text, Data.Foldable, Control.Concurrent ... That way we could write more concise and short code as Haskell promises. This will be useful for small programs like scripts, small tools, tutorials, examples, etc. Best regards, Vassil Keremidchiev

On Wed, Feb 01, 2017 at 04:18:13PM +0200, Vassil Ognyanov Keremidchiev wrote:
Hello!
What do you think about an idea to have multiple imports on a single line, like:
module MyApp where import Data.Text, Data.Foldable, Control.Concurrent ...
Hello Vassil, how would qualified/as work? Would import statement like this: import Data.Text, qualified Data.Foldable as F, Control.Concurrent be allowed?

likewise, why not use semicolon? per se we already can do mulitple lines on
a single line via semicolon :)
On Wed, Feb 1, 2017 at 10:34 AM, Francesco Ariis
Hello!
What do you think about an idea to have multiple imports on a single
On Wed, Feb 01, 2017 at 04:18:13PM +0200, Vassil Ognyanov Keremidchiev wrote: line,
like:
module MyApp where import Data.Text, Data.Foldable, Control.Concurrent ...
Hello Vassil, how would qualified/as work? Would import statement like this:
import Data.Text, qualified Data.Foldable as F, Control.Concurrent
be allowed?
_______________________________________________ Haskell-prime mailing list Haskell-prime@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-prime

I like this idea. How about some more syntactic sugar? {-# LANGUAGE ImportSugar #-} import [Data.[Text, Foldable q-as F, Vector (Vector), Vector q-as V hiding (Vector)], Control.Concurrent, Data.List q (sum)] - tree structure, one import per leaf - prefix qualified -> postfix q - qualified/as -> q-as or q as or q/as or qas
Gesendet: Mittwoch, 01. Februar 2017 um 16:34 Uhr Von: "Francesco Ariis"
An: haskell-prime@haskell.org Betreff: Re: Multiple imports on a single line On Wed, Feb 01, 2017 at 04:18:13PM +0200, Vassil Ognyanov Keremidchiev wrote:
Hello!
What do you think about an idea to have multiple imports on a single line, like:
module MyApp where import Data.Text, Data.Foldable, Control.Concurrent ...
Hello Vassil, how would qualified/as work? Would import statement like this:
import Data.Text, qualified Data.Foldable as F, Control.Concurrent
be allowed?
_______________________________________________ Haskell-prime mailing list Haskell-prime@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-prime

2017-02-01 20:51 GMT+01:00 Marc Ziegert
[...] How about some more syntactic sugar?
{-# LANGUAGE ImportSugar #-} import [Data.[Text, Foldable q-as F, Vector (Vector), Vector q-as V hiding (Vector)], Control.Concurrent, Data.List q (sum)] [...]
o_O I am really not sure if this is a serious proposal or just some funny remark, taking the initial proposal to an extreme: Is it really a good idea to condense something so heavily? I don't think so, deciphering the above import probably takes you multiple times the effort to read the plain old simple imports spanning several (easy) lines. Quoting Martin Fowler: *"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." *This simply looks too ingenious, so http://wiki.c2.com/?KillYourDarlings probably applies, and so does https://en.wikipedia.org/wiki/KISS_principle. Apart from the incomprehensibility for humans: For every seemingly "easy" syntactic extension, the cost for related tools like IDEs etc. has to be considered. Have fun e.g. extending syntax highlighting to handle such stuff. And finally: What problem are we actually trying to solve? From my POV, imports are largely irrelevant when reading code, you just skim over them to get an idea, and then forget about them/fold them in your editor/mechanically clean them up via your IDE/etc. The only time they are really important is when something goes wrong and/or name resolution is not obvious. And exactly at that time, one really needs simple stuff to look at, not a Perl-like one-liner. But as I said, that's just my opinion...

The main annoying thing in import lists for me at the moment is the
proliferation of modules which one would like to import both qualified
under some alias and to import a handful of names unqualified (especially
infix functions and types). It would be nice if rather than
import qualified Data.Map as Map
import Data.Map (Map)
import qualified Data.Sequence as S
import Data.Sequence (Seq, ViewR(..), ViewL(..), (<|), (|>))
we could instead have some variation like:
import Data.Map qualified as Map, (Map)
import Data.Sequence qualified as S, (Seq, ViewR(..), ViewL(..), (<|),
(|>))
I'm thinking something along the lines of the following:
*impdecl* -> import *modid impspec_1, impspec_2, ..., impspec_*n (n >= 0)
*impspec* -> ( *import*_1, ..., *import*_n [,] ) [*impqual*] (n >= 0)
| *impqual*
*impqual* -> [qualified] as *modid* [*imphiding*]
| *imphiding*
*imphiding* -> hiding (*import*_1, ..., *import*_n [,] ) (n >= 0)
I haven't thought particularly hard about this BNF, though hopefully it
gets across my idea. You'd also certainly want to mix in support (perhaps
with deprecation?) for the existing syntax which places the 'qualified'
before the module identifier, even though I've personally always found that
awkward, as it makes imports hard to read and sort.
The other thing which would greatly ameliorate the annoyance with import
lists would be the ability to import and then re-export modules in a way
that retains the manner in which things were qualified. So one could, if
one wanted, have a module which imports things like Map, Set, (lazy and
strict) Text, (lazy and strict) ByteString, etc. re-exported qualified the
way one wants, and then import that from the other modules in the project.
On Wed, Feb 1, 2017, 10:36 Francesco Ariis
Hello!
What do you think about an idea to have multiple imports on a single line, like:
module MyApp where import Data.Text, Data.Foldable, Control.Concurrent ...
Hello Vassil, how would qualified/as work? Would import statement like this: import Data.Text, qualified Data.Foldable as F, Control.Concurrent be allowed? _______________________________________________ Haskell-prime mailing list Haskell-prime@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-prime

You can already write this, with only a tiny bit of syntax: module MyApp where import Data.Text; import Data.Foldable; import Control.Concurrent Whether it is good style is another matter, but all compilers will certainly accept it. Regards, Malcolm On 1 Feb 2017, at 14:18, Vassil Ognyanov Keremidchiev wrote:
Hello!
What do you think about an idea to have multiple imports on a single line, like:
module MyApp where import Data.Text, Data.Foldable, Control.Concurrent ...
That way we could write more concise and short code as Haskell promises. This will be useful for small programs like scripts, small tools, tutorials, examples, etc.
Best regards, Vassil Keremidchiev _______________________________________________ Haskell-prime mailing list Haskell-prime@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-prime

Yes, but it could be a bit more denser without so much repetition of
"import", like:
import Data.Text, qualified Data.Map as M, qualified Vector as V hiding
(Vector)
i.e. the same as current situation, but allow for multiple imports for the
same word "import" comma separated. What do you think? The difference in
syntax is not so much different, than just allowing commas.
2017-02-01 23:23 GMT+02:00 Malcolm Wallace
You can already write this, with only a tiny bit of syntax:
module MyApp where import Data.Text; import Data.Foldable; import Control.Concurrent
Whether it is good style is another matter, but all compilers will certainly accept it.
Regards, Malcolm
On 1 Feb 2017, at 14:18, Vassil Ognyanov Keremidchiev wrote:
Hello!
What do you think about an idea to have multiple imports on a single line, like:
module MyApp where import Data.Text, Data.Foldable, Control.Concurrent ...
That way we could write more concise and short code as Haskell promises. This will be useful for small programs like scripts, small tools, tutorials, examples, etc.
Best regards, Vassil Keremidchiev _______________________________________________ Haskell-prime mailing list Haskell-prime@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-prime

2017-02-01 22:39 GMT+01:00 Vassil Ognyanov Keremidchiev
Yes, but it could be a bit more denser without so much repetition of "import", like:
import Data.Text, qualified Data.Map as M, qualified Vector as V hiding (Vector)
i.e. the same as current situation, but allow for multiple imports for the same word "import" comma separated. What do you think? The difference in syntax is not so much different, than just allowing commas.
I think this is worse than separate imports, each on a separate line. The Python people have even put something like this into a PEP: https://www.python.org/dev/peps/pep-0008/#imports This is for a very good reason: The one-liners have very few visual hints for the reader to comprehend it quickly. So even if Haskell allowed this comma-separated chain of imports, code containing it probably wouldn't survive a code review in most companies, where maintainability is the prime goal. I often see a confusion between greater expresiveness (good goal) and having to type less (largely irrelevant goal). By all means make the module system more expressive, but try to avoid "clever" things for convenience.

Sven Panne
I often see a confusion between greater expresiveness (good goal) and having to type less (largely irrelevant goal). By all means make the module system more expressive, but try to avoid "clever" things for convenience.
+1 -- Jón Fairbairn Jon.Fairbairn@cl.cam.ac.uk
participants (8)
-
Cale Gibbard
-
Carter Schonwald
-
Francesco Ariis
-
Jon Fairbairn
-
Malcolm Wallace
-
Marc Ziegert
-
Sven Panne
-
Vassil Ognyanov Keremidchiev