Quantcast

Multiple imports on a single line

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
12 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Multiple imports on a single line

varosi
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
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-prime
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Multiple imports on a single line

Francesco Ariis
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
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-prime
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Multiple imports on a single line

Carter Schonwald
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 <[hidden email]> wrote:
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
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-prime


_______________________________________________
Haskell-prime mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-prime
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Aw: Re: Multiple imports on a single line

Marc A. Ziegert
In reply to this post by Francesco Ariis
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" <[hidden email]>
> An: [hidden email]
> 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
> [hidden email]
> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-prime
>
_______________________________________________
Haskell-prime mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-prime
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Multiple imports on a single line

Cale Gibbard
In reply to this post by Francesco Ariis
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 <[hidden email]> wrote:
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
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-prime

_______________________________________________
Haskell-prime mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-prime
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Re: Multiple imports on a single line

Sven Panne-2
In reply to this post by Marc A. Ziegert
2017-02-01 20:51 GMT+01:00 Marc Ziegert <[hidden email]>:
[...] 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...

_______________________________________________
Haskell-prime mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-prime
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Multiple imports on a single line

Malcolm Wallace-2
In reply to this post by varosi
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
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-prime


_______________________________________________
Haskell-prime mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-prime
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Multiple imports on a single line

varosi
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 <[hidden email]>:
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
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-prime



_______________________________________________
Haskell-prime mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-prime
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Multiple imports on a single line

Sven Panne-2
2017-02-01 22:39 GMT+01:00 Vassil Ognyanov Keremidchiev <[hidden email]>:
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.

_______________________________________________
Haskell-prime mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-prime
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Multiple imports on a single line

Jon Fairbairn
Sven Panne <[hidden email]>
writes:

> 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                                 [hidden email]

_______________________________________________
Haskell-prime mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-prime
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Multiple imports on a single line

Doug McIlroy
In reply to this post by varosi
> 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.

To expand upon this principle a bit, syntactic sugar that promises to save O(1)
typing in an n-line module is suspect; that which might save O(n) is more promising.

Doug


_______________________________________________
Haskell-prime mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-prime
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Multiple imports on a single line

varosi
So it's O(N) -> O(1) where N is a number of lines/imports.

But you're right for the readiness. I'm convinced!

2017-02-02 16:52 GMT+02:00 Doug McIlroy <[hidden email]>:
> 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.

To expand upon this principle a bit, syntactic sugar that promises to save O(1)
typing in an n-line module is suspect; that which might save O(n) is more promising.

Doug


_______________________________________________
Haskell-prime mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-prime


_______________________________________________
Haskell-prime mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-prime
Loading...