RE: module system/namespaces: separate with/use, allow local "use"

On 30 January 2006 09:03, Simon Peyton-Jones wrote:
With the module system, we should make a distinction between declaring
(1) that we want to use a module (2) how to bring the module's names into scope
Perhaps 'import' should be allowed anywhere among definitions.
Indeed. Requiring the import clauses to be at the top, and the fixity declarations, makes them easy to find -- but we don't require that for type signatures or class declarations etc. It'd be more consistent to allow imports and fixity declarations anywhere.
This'd be a backward compatible change, but it's an utterly un-forced one. It's not something that people complain about much.
I vaguely remember suggesting this for Haskell 98 or Haskell 1.4 (can't remember which) but nobody saw the need for it back then. In favour: - simplifies the syntax, more consistent - makes it easier to add a temporary import (eg. imagine using 'trace' for debugging, you can put 'import Debug.Trace' right next to the use, rather than at the top of the module where you'll probably forget about it) - simpler for tools that auto-generate code, or annotate existing code (eg. Happy wants to add imports sometimes) Against: - tools that collect imports have to parse the whole file (eg. GHC's dependency analyser) - can't easily see what is imported on balance, I like the way it is now. (fixity decls are currently allowed anywhere in the module, BTW - I think it was in 1.4 they were restricted to being just below the import decls). Cheers, Simon

"Simon Marlow"
On 30 January 2006 09:03, Simon Peyton-Jones wrote:
With the module system, we should make a distinction between declaring
(1) that we want to use a module (2) how to bring the module's names into scope
Perhaps 'import' should be allowed anywhere among definitions.
Indeed. Requiring the import clauses to be at the top, and the fixity declarations, makes them easy to find -- but we don't require that for type signatures or class declarations etc. It'd be more consistent to allow imports and fixity declarations anywhere.
This'd be a backward compatible change, but it's an utterly un-forced one. It's not something that people complain about much.
I vaguely remember suggesting this for Haskell 98 or Haskell 1.4 (can't remember which) but nobody saw the need for it back then. (snip pros & cons summary)
Can one of you add a ticket / wiki page with this summary? I'd like to track things like this in case they come up again. Johannes, if you have any more specific proposals you'd like to make, please do so on the mailing list, then add a ticket once some consensus emerges. peace, isaac

"Simon Marlow"
on balance, I like the way it is now.
An opinion to the contrary: http://www.uclic.ucl.ac.uk/harold/srf/javaspae.html "Importing packages: A brief example of design issues" -- __("< Marcin Kowalczyk \__/ qrczak@knm.org.pl ^^ http://qrnik.knm.org.pl/~qrczak/

Simon Marlow wrote:
Perhaps 'import' should be allowed anywhere among definitions.
[...] Against: - tools that collect imports have to parse the whole file (eg. GHC's dependency analyser) - can't easily see what is imported
only if we keep the idea that "import" both says *that* a module is imported *and* brings it into scope at the same time. Ada has "with" at the top (that would answer your objections) and then allows local "use" for the scoping issues (but you'd have to "with" any module that you want to "use"). I think the current "import .. qualified .. as .. hiding" is trying to do too much at the same time. best regards, -- -- Johannes Waldmann -- Tel/Fax (0341) 3076 6479/80 -- ---- http://www.imn.htwk-leipzig.de/~waldmann/ -------
participants (4)
-
Isaac Jones
-
Johannes Waldmann
-
Marcin 'Qrczak' Kowalczyk
-
Simon Marlow