Proposal: Relative Module Imports
Problem: We need a way to simplify module imports. Problem details: * Hierarchical module names are getting really long (including a functional area, a package name, and a module name). * People typically import multiple modules from areas close to each other in the hierarchical module namespace (especially in the case of intra-package imports). * Long module names are required even for non-exposed modules because a program may contain only one module with a given name (regardless of its visibility). Idea: Allow module relative imports in a manner that does not break any existing code. Proposal: * Use preceding dots to indicate that module name is relative * Use from keyword to specify a different relative base. Example: Dot relative syntax Translation ------------------- ----------- module Text.Space.Foo.M where module Text.Space.Foo.M where import .M2 import Text.Space.Foo.M2 as M2 import ..Bar.Baz import Text.Space.Bar.Baz as Bar.Baz import Data.Set import Data.Set from ...HaXML.XML import .Types import Text.HaXML.XML.Types as Types import .Escape import Text.HaXML.XML.Escape as Escape import .Pretty import Text.HaXML.XML.Pretty as Pretty I believe that the proposed syntax is much more concise and readable than the current equivalent. -Alex- ______________________________________________________________ S. Alexander Jacobson tel:917-770-6565 http://alexjacobson.com
On 5/3/05, S. Alexander Jacobson <alex <at> alexjacobson.com> wrote:
Problem: We need a way to simplify module imports.
Problem details:
* Hierarchical module names are getting really long (including a functional area, a package name, and a module name).
* People typically import multiple modules from areas close to each other in the hierarchical module namespace (especially in the case of intra-package imports).
* Long module names are required even for non-exposed modules because a program may contain only one module with a given name (regardless of its visibility).
Idea: Allow module relative imports in a manner that does not break any existing code.
This would be really nice, but I'm not sure I like the way you propose to do it. Those bare dots don't look very nice to me, and I really don't like the idea of having to count them... I'm not even sure I like the idea of imports relative to the current module. I almost want "import Text.HaXML.XML.{Types,Escape,Pretty}", but not quite. And that would not be nice for qualified imports, anyway. Maybe something like from Text.HaXML.XML import (Types, Escape, Pretty) would be nice. -- Sam
Samuel Bronson <naesten@gmail.com> wrote:
On 5/3/05, S. Alexander Jacobson <alex <at> alexjacobson.com> wrote:
Problem: We need a way to simplify module imports. Idea: Allow module relative imports in a manner that does not break any existing code.
I almost want "import Text.HaXML.XML.{Types,Escape,Pretty}", but not quite. And that would not be nice for qualified imports, anyway.
Maybe something like from Text.HaXML.XML import (Types, Escape, Pretty) would be nice.
That's really funny. Some 4th year students here just finished a project under my supervision that I called 'SJ' for 'Short Java', where the basic premise was that most Java code is unecessarily verbose. One of the 'low hanging fruit' for shortening were import declarations. I had advised the students to go with something that would be the equivalent of import Text.HaXML.XML.{Types|Escape|Pretty} but they chose something a bit worse than that. Of course, the project aimed for more substantial 'shortenings', but the end-result was very unsatisfying as this particular group didn't "get it". I will try again next year, hopefully with a bigger group. Jacques PS: I tried to get them to use Parsec and write their own pretty-printer for in Haskell, but gave up on that because of the weakness of the group. They ended up using ANTLR (good) and some awful Java pretty-printer that was quite buggy :-(
On Tue, 3 May 2005, Samuel Bronson wrote:
Maybe something like
from Text.HaXML.XML import (Types, Escape, Pretty)
would be nice.
The problem with this one is that you need a way to express all the other stuff in import statements like "qualified" or "as", the imported list, etc. If you don't like the dots and are willing to deal with having to type the current module hierarchy twice, a more verbose syntax would be Proposal Translation -------- ----------- module Foo.Bar.Baz.Bing where module Foo.Bar.Baz.Bing where from Foo.Bar.Baz import Blip import Foo.Bar.Baz.Blip as Blip from Text.HaXML.XML import Types import Text.HaXML.XML.Types as Types import Escape import Text.HaXML.XML.Escape as Escape Not as tight as the prior syntax I proposed, but more readable and still a large improvement on the status quo. Thoughts? -Alex- ______________________________________________________________ S. Alexander Jacobson tel:917-770-6565 http://alexjacobson.com On Tue, 3 May 2005, Samuel Bronson wrote:
On 5/3/05, S. Alexander Jacobson <alex <at> alexjacobson.com> wrote:
Problem: We need a way to simplify module imports.
Problem details:
* Hierarchical module names are getting really long (including a functional area, a package name, and a module name).
* People typically import multiple modules from areas close to each other in the hierarchical module namespace (especially in the case of intra-package imports).
* Long module names are required even for non-exposed modules because a program may contain only one module with a given name (regardless of its visibility).
Idea: Allow module relative imports in a manner that does not break any existing code.
This would be really nice, but I'm not sure I like the way you propose to do it. Those bare dots don't look very nice to me, and I really don't like the idea of having to count them... I'm not even sure I like the idea of imports relative to the current module.
I almost want "import Text.HaXML.XML.{Types,Escape,Pretty}", but not quite. And that would not be nice for qualified imports, anyway.
Maybe something like
from Text.HaXML.XML import (Types, Escape, Pretty)
would be nice.
-- Sam
_______________________________________________ Haskell mailing list Haskell@haskell.org http://www.haskell.org/mailman/listinfo/haskell
On 5/5/05, S. Alexander Jacobson <alex@alexjacobson.com> wrote:
On Tue, 3 May 2005, Samuel Bronson wrote:
Maybe something like
from Text.HaXML.XML import (Types, Escape, Pretty)
would be nice.
The problem with this one is that you need a way to express all the other stuff in import statements like "qualified" or "as", the imported list, etc.
Hmm, I guess it isn't dead obvious what they would do, but it seems like it would make more sense that way than with braces-and-commas in the shell style.
If you don't like the dots and are willing to deal with having to type the current module hierarchy twice, a more verbose syntax would be
Proposal Translation -------- ----------- module Foo.Bar.Baz.Bing where module Foo.Bar.Baz.Bing where from Foo.Bar.Baz import Blip import Foo.Bar.Baz.Blip as Blip from Text.HaXML.XML import Types import Text.HaXML.XML.Types as Types import Escape import Text.HaXML.XML.Escape as Escape
Not as tight as the prior syntax I proposed, but more readable and still a large improvement on the status quo.
Thoughts?
That looks pretty much like what I had only with an import for each module, instead of one import with syntax a bit like deriving... probably much easier to parse, and a bit more obvious what it means. Definately makes qualified and friends more fine-grained than I was thinking. You could even nest them. Also, it is much easier on the eyes than your previous suggestion, and there are no dots to count. I like it ;-). --Sam
participants (3)
-
Jacques Carette -
S. Alexander Jacobson -
Samuel Bronson