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

Simon Marlow simonmar at
Mon Jan 30 12:01:40 EST 2006

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'
   debugging, you can put 'import Debug.Trace' right next to the use,
   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)

 - 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


More information about the Haskell-prime mailing list