Aliasing current module qualifier

Hello *, Here's a situation I've encountered recently, which mades me wish to be able to define a local alias (in order to avoid CPP use). Consider the following stupid module: module AnnoyinglyLongModuleName ( AnnoyinglyLongModuleName.length , AnnoyinglyLongModuleName.null ) where length :: a -> Int length _ = 0 null :: a -> Bool null = (== 0) . AnnoyinglyLongModuleName.length Now it'd be great if I could do the following instead: module AnnoyinglyLongModuleName (M.length, M.null) where import AnnoyinglyLongModuleName as M -- <- does not work length :: a -> Int length _ = 0 null :: a -> Bool null = (== 0) . M.length However, if I try to compile this, GHC complains about AnnoyinglyLongModuleName.hs:4:1: Bad interface file: AnnoyinglyLongModuleName.hi AnnoyinglyLongModuleName.hi: openBinaryFile: does not exist (No such file or directory) while GHCi tells me: Module imports form a cycle: module ‘AnnoyinglyLongModuleName’ (AnnoyinglyLongModuleName.hs) imports itself Is there some other way (without CPP) to create a local alias for the current module-name? If not, is there a reason GHC couldn't support this special case of self-aliasing the current module name? PS: Alternatively, this could be done as a language extension but that'd require extending the Haskell grammar: module AnnoyinglyLongModuleName as M (M.length, M.null) where Cheers, hvr

On a somewhat related note, I'd love to be able to do this in Haskell: import Basics.Nat renaming (_≥_ to _≥ℕ_) (this is taken from Agda). Janek Dnia poniedziałek, 29 września 2014, Herbert Valerio Riedel napisał:
Hello *,
Here's a situation I've encountered recently, which mades me wish to be able to define a local alias (in order to avoid CPP use). Consider the following stupid module:
module AnnoyinglyLongModuleName ( AnnoyinglyLongModuleName.length , AnnoyinglyLongModuleName.null ) where
length :: a -> Int length _ = 0
null :: a -> Bool null = (== 0) . AnnoyinglyLongModuleName.length
Now it'd be great if I could do the following instead:
module AnnoyinglyLongModuleName (M.length, M.null) where
import AnnoyinglyLongModuleName as M -- <- does not work
length :: a -> Int length _ = 0
null :: a -> Bool null = (== 0) . M.length
However, if I try to compile this, GHC complains about
AnnoyinglyLongModuleName.hs:4:1: Bad interface file: AnnoyinglyLongModuleName.hi AnnoyinglyLongModuleName.hi: openBinaryFile: does not exist (No such file or directory)
while GHCi tells me:
Module imports form a cycle: module ‘AnnoyinglyLongModuleName’ (AnnoyinglyLongModuleName.hs) imports itself
Is there some other way (without CPP) to create a local alias for the current module-name? If not, is there a reason GHC couldn't support this special case of self-aliasing the current module name?
PS: Alternatively, this could be done as a language extension but that'd require extending the Haskell grammar:
module AnnoyinglyLongModuleName as M (M.length, M.null) where
Cheers, hvr _______________________________________________ Glasgow-haskell-users mailing list Glasgow-haskell-users@haskell.org http://www.haskell.org/mailman/listinfo/glasgow-haskell-users

Hi, rather than disambiguating a name from the current module by an abbreviated module name, I would prefer a disambiguation as is done for local names that shadows existing bindings. Then only imported names would need to be qualified (possibly using shorter module names). So names of the current module would simple shadow unqualified imported names. I think, that would only make previously ambiguous modules compile. However, this does not help for the case when the whole module plus some imported names need to be exported. module AnnoyinglyLongModuleName ( module AnnoyinglyLongModuleName , ... ) where (Without re-exports the whole export list could be omitted) Cheers Christian Am 29.09.2014 um 10:19 schrieb Herbert Valerio Riedel:
Hello *,
Here's a situation I've encountered recently, which mades me wish to be able to define a local alias (in order to avoid CPP use). Consider the following stupid module:
module AnnoyinglyLongModuleName ( AnnoyinglyLongModuleName.length , AnnoyinglyLongModuleName.null ) where
length :: a -> Int length _ = 0
null :: a -> Bool null = (== 0) . AnnoyinglyLongModuleName.length
Now it'd be great if I could do the following instead:
module AnnoyinglyLongModuleName (M.length, M.null) where
import AnnoyinglyLongModuleName as M -- <- does not work
length :: a -> Int length _ = 0
null :: a -> Bool null = (== 0) . M.length
However, if I try to compile this, GHC complains about
AnnoyinglyLongModuleName.hs:4:1: Bad interface file: AnnoyinglyLongModuleName.hi AnnoyinglyLongModuleName.hi: openBinaryFile: does not exist (No such file or directory)
while GHCi tells me:
Module imports form a cycle: module ‘AnnoyinglyLongModuleName’ (AnnoyinglyLongModuleName.hs) imports itself
Is there some other way (without CPP) to create a local alias for the current module-name? If not, is there a reason GHC couldn't support this special case of self-aliasing the current module name?
PS: Alternatively, this could be done as a language extension but that'd require extending the Haskell grammar:
module AnnoyinglyLongModuleName as M (M.length, M.null) where
Cheers, hvr _______________________________________________ Glasgow-haskell-users mailing list Glasgow-haskell-users@haskell.org http://www.haskell.org/mailman/listinfo/glasgow-haskell-users

On Mon, Sep 29, 2014 at 4:19 AM, Herbert Valerio Riedel
Now it'd be great if I could do the following instead:
module AnnoyinglyLongModuleName (M.length, M.null) where
import AnnoyinglyLongModuleName as M -- <- does not work
I think if I wanted this syntax, I'd go for: module AnnoyinglyLongModuleName as M where ... -- brandon s allbery kf8nh sine nomine associates allbery.b@gmail.com ballbery@sinenomine.net unix, openafs, kerberos, infrastructure, xmonad http://sinenomine.net

You don't need a new language construct, what i do is:
module AnnoyinglyLongModuleName (M.length, M.null) where
import AnnoyinglongLongModuleName as M
I think ghc would need to be extended a little to make this convienient as
it doesn't handle recursive module imports as transparently.
John
On Mon, Sep 29, 2014 at 8:47 AM, Brandon Allbery
On Mon, Sep 29, 2014 at 4:19 AM, Herbert Valerio Riedel
wrote: Now it'd be great if I could do the following instead:
module AnnoyinglyLongModuleName (M.length, M.null) where
import AnnoyinglyLongModuleName as M -- <- does not work
I think if I wanted this syntax, I'd go for:
module AnnoyinglyLongModuleName as M where ...
-- brandon s allbery kf8nh sine nomine associates allbery.b@gmail.com ballbery@sinenomine.net unix, openafs, kerberos, infrastructure, xmonad http://sinenomine.net
_______________________________________________ Glasgow-haskell-users mailing list Glasgow-haskell-users@haskell.org http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
-- John Meacham - http://notanumber.net/

On Mon, Sep 29, 2014 at 5:02 PM, John Meacham
You don't need a new language construct, what i do is:
module AnnoyinglyLongModuleName (M.length, M.null) where
import AnnoyinglongLongModuleName as M
Isn't that exactly what the OP said doesn't work?
On Mon, Sep 29, 2014 at 8:47 AM, Brandon Allbery
wrote: On Mon, Sep 29, 2014 at 4:19 AM, Herbert Valerio Riedel
wrote: Now it'd be great if I could do the following instead:
module AnnoyinglyLongModuleName (M.length, M.null) where
import AnnoyinglyLongModuleName as M -- <- does not work
I think if I wanted this syntax, I'd go for:
module AnnoyinglyLongModuleName as M where ...
-- brandon s allbery kf8nh sine nomine associates allbery.b@gmail.com ballbery@sinenomine.net unix, openafs, kerberos, infrastructure, xmonad http://sinenomine.net

Hello,
What semantics are you using for recursive modules? As far as I see, if
you take a least fixed point semantics (e.g. as described in "A Formal
Specification for the Haskell 98 Module System",
http://yav.github.io/publications/modules98.pdf ) this program is incorrect
as the module does not export anything.
While this may seem a bit counter intuitive at first, this semantics has
the benefit of being precise, easily specified, and uniform (e.g it does
not require any special treatment of the " current " module). As an
example, consider the following variation of your program, where I just
moved the definition in a sperate (still recursive) module:
module A (M.x) where
import B as M
module B (M.x) where
import A as M
x = True
I think that it'd be quite confusing if a single recursive module worked
differently then a larger recursive group, but it is not at all obvious why
B should export 'x'. And for those who like this kind of puzzle: what
should happen if 'A' also had a definition for 'x'?
Iavor
On Sep 29, 2014 11:02 PM, "John Meacham"
You don't need a new language construct, what i do is:
module AnnoyinglyLongModuleName (M.length, M.null) where
import AnnoyinglongLongModuleName as M
I think ghc would need to be extended a little to make this convienient as it doesn't handle recursive module imports as transparently.
John
On Mon, Sep 29, 2014 at 8:47 AM, Brandon Allbery
wrote: On Mon, Sep 29, 2014 at 4:19 AM, Herbert Valerio Riedel
wrote: Now it'd be great if I could do the following instead:
module AnnoyinglyLongModuleName (M.length, M.null) where
import AnnoyinglyLongModuleName as M -- <- does not work
I think if I wanted this syntax, I'd go for:
module AnnoyinglyLongModuleName as M where ...
-- brandon s allbery kf8nh sine nomine associates allbery.b@gmail.com ballbery@sinenomine.net unix, openafs, kerberos, infrastructure, xmonad http://sinenomine.net
_______________________________________________ Glasgow-haskell-users mailing list Glasgow-haskell-users@haskell.org http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
-- John Meacham - http://notanumber.net/
_______________________________________________ ghc-devs mailing list ghc-devs@haskell.org http://www.haskell.org/mailman/listinfo/ghc-devs

If there is to be such a language feature, I strongly feel it should be via something like
module Long.Name.M( f, g, h ) as K where ...
I do not want to try to piggy-back on the possible meaning of a self-import; it’s just asking for trouble, as Iavor points out.
Using “as M” in the module header would be simple. It is easy to explain and fairly easy to implement. I don’t think there are any knock-on complications. So if enough people want it, and someone is prepared to implement it (with a language extension flag of course), then I’d be OK with that. I’m unsure that it’s worth the effort, but I’m happy to let users decide.
Simon
From: Glasgow-haskell-users [mailto:glasgow-haskell-users-bounces@haskell.org] On Behalf Of Iavor Diatchki
Sent: 30 September 2014 13:18
To: john@repetae.net
Cc: GHC Users Mailing List; ghc-devs; Herbert Valerio Riedel
Subject: Re: Aliasing current module qualifier
Hello,
What semantics are you using for recursive modules? As far as I see, if you take a least fixed point semantics (e.g. as described in "A Formal Specification for the Haskell 98 Module System", http://yav.github.io/publications/modules98.pdf ) this program is incorrect as the module does not export anything.
While this may seem a bit counter intuitive at first, this semantics has the benefit of being precise, easily specified, and uniform (e.g it does not require any special treatment of the " current " module). As an example, consider the following variation of your program, where I just moved the definition in a sperate (still recursive) module:
module A (M.x) where
import B as M
module B (M.x) where
import A as M
x = True
I think that it'd be quite confusing if a single recursive module worked differently then a larger recursive group, but it is not at all obvious why B should export 'x'. And for those who like this kind of puzzle: what should happen if 'A' also had a definition for 'x'?
Iavor
On Sep 29, 2014 11:02 PM, "John Meacham"

Yes, that is the semantics I use for recursive module imports in jhc. And
you are right in that it does not accept those examples due to being unable
to bootstrap the least fixed point.
How would the 'as M' proposal interact? Would it actually be new entries in
the name table or rewritten as a macro to the current module name? I can
see some edge cases where it makes a difference. I am thinking the easiest
would be to populate entries for all the M.toplevel names where toplevel
are the top level definitions of the module, will implement it and see how
it shakes out.
John
On Tue, Sep 30, 2014 at 5:18 AM, Iavor Diatchki
Hello,
What semantics are you using for recursive modules? As far as I see, if you take a least fixed point semantics (e.g. as described in "A Formal Specification for the Haskell 98 Module System", http://yav.github.io/publications/modules98.pdf ) this program is incorrect as the module does not export anything.
While this may seem a bit counter intuitive at first, this semantics has the benefit of being precise, easily specified, and uniform (e.g it does not require any special treatment of the " current " module). As an example, consider the following variation of your program, where I just moved the definition in a sperate (still recursive) module:
module A (M.x) where import B as M
module B (M.x) where import A as M x = True
I think that it'd be quite confusing if a single recursive module worked differently then a larger recursive group, but it is not at all obvious why B should export 'x'. And for those who like this kind of puzzle: what should happen if 'A' also had a definition for 'x'?
Iavor On Sep 29, 2014 11:02 PM, "John Meacham"
wrote: You don't need a new language construct, what i do is:
module AnnoyinglyLongModuleName (M.length, M.null) where
import AnnoyinglongLongModuleName as M
I think ghc would need to be extended a little to make this convienient as it doesn't handle recursive module imports as transparently.
John
On Mon, Sep 29, 2014 at 8:47 AM, Brandon Allbery
wrote: On Mon, Sep 29, 2014 at 4:19 AM, Herbert Valerio Riedel
wrote: Now it'd be great if I could do the following instead:
module AnnoyinglyLongModuleName (M.length, M.null) where
import AnnoyinglyLongModuleName as M -- <- does not work
I think if I wanted this syntax, I'd go for:
module AnnoyinglyLongModuleName as M where ...
-- brandon s allbery kf8nh sine nomine associates allbery.b@gmail.com ballbery@sinenomine.net unix, openafs, kerberos, infrastructure, xmonad http://sinenomine.net
_______________________________________________ Glasgow-haskell-users mailing list Glasgow-haskell-users@haskell.org http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
-- John Meacham - http://notanumber.net/
_______________________________________________ ghc-devs mailing list ghc-devs@haskell.org http://www.haskell.org/mailman/listinfo/ghc-devs
-- John Meacham - http://notanumber.net/
participants (7)
-
Brandon Allbery
-
Christian Maeder
-
Herbert Valerio Riedel
-
Iavor Diatchki
-
Jan Stolarek
-
John Meacham
-
Simon Peyton Jones