
| It would be useful to be able to do a | | module Doc.Pretty.Long.Name where | | import Doc.Pretty.Long.Name as This | | so within the module we can refer to itself as 'This' without having to | write out the full name, however ghc complains that the hi file for the | module it is trying to compile is not available. It would be nice if ghc | could recognize the self-import case and handle it directly. I quite liked this idea until I thought of this: module Doc.Pretty.Long( M.f, f ) where import qualified M( f ) import Doc.Pretty.Long as M f x = x The second import decl imports all the things exported by Doc.Pretty.Long. But what does it export? Well, M.f. But what is M.f. Well, it could be the f coming from 'import M.f'. But wait! Doc.Pretty.Long exports the locally-defined f too... and the second import decl will make that be called M.f too. It seems that we may need a fixpoint loop to sort all this out. Seems scary. I think what you want is actually more directly stated thus: module Doc.Pretty.Long( ... ) as M where ... The 'as M' in the module header gives an alias for Doc.Pretty.Long just as it does for an import statement. Simple. Your scheme had the advantage of no new syntax. I'd be interested to know whether lots of people would like 'as M' in the module header, as new syntax. A bit more complexity, but perhaps useful. Simon

On Tue, 2005-01-18 at 10:13 +0000, Simon Peyton-Jones wrote:
I think what you want is actually more directly stated thus:
module Doc.Pretty.Long( ... ) as M where ...
The 'as M' in the module header gives an alias for Doc.Pretty.Long just as it does for an import statement. Simple.
Your scheme had the advantage of no new syntax. I'd be interested to know whether lots of people would like 'as M' in the module header, as new syntax. A bit more complexity, but perhaps useful.
And if it turns out we are in the mood to look at extending the inport/export/module syntax perhaps we could also consider the qualified export idea posted a few weeks ago. That was so that you could say: import Graphics.UI.Gtk and then use Button.setText (rather than buttonSetText) as $DEITY intended. Down with the moduleNamePrefix! :-) Duncan

Simon Peyton-Jones wrote:
I quite liked this idea until I thought of this:
module Doc.Pretty.Long( M.f, f ) where import qualified M( f ) import Doc.Pretty.Long as M
f x = x
The second import decl imports all the things exported by Doc.Pretty.Long. But what does it export? Well, M.f. But what is M.f. Well, it could be the f coming from 'import M.f'. But wait! Doc.Pretty.Long exports the locally-defined f too... and the second import decl will make that be called M.f too.
Our module system paper has answers to this type of questions, since it deals with the meaning of recursive modules: http://www.cse.ogi.edu/~diatchki/hsmod/ It is implemented in the Programatica Haskell front-end, which thus supports modules importing themselves in particular, and mutually recursive modules in general, without the need for boot .hi files. I wonder when other Haskell implementations are going to catch up? :-) -- Thomas H
participants (3)
-
Duncan Coutts
-
Simon Peyton-Jones
-
Thomas Hallgren