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

Indeed, being able to introduce a short name for the current module, or having a fixed short name like 'This' or 'Self' would be neat. The standard workaround for your example would be import Prelude hiding (length,null) Did you try a .hs-boot file with your self-import trick? Cheers, Andreas On 29.09.2014 10:19, Herbert Valerio Riedel wrote:
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 _______________________________________________ ghc-devs mailing list ghc-devs@haskell.org http://www.haskell.org/mailman/listinfo/ghc-devs
-- Andreas Abel <>< Du bist der geliebte Mensch. Department of Computer Science and Engineering Chalmers and Gothenburg University, Sweden andreas.abel@gu.se http://www2.tcs.ifi.lmu.de/~abel/

On 2014-09-29 at 10:43:28 +0200, Andreas Abel wrote:
Indeed, being able to introduce a short name for the current module, or having a fixed short name like 'This' or 'Self' would be neat.
The standard workaround for your example would be
import Prelude hiding (length,null)
That won't work though, because what I failed to mention is that I needed this (while avoiding CPP) to cope with external modules growing their exports lists, such as Data.Foldable starting to export 'length' and 'null' in base-4.8.0.0 Moreover, hiding a non-existent symbol is a warning in recent GHC's but a hard error in older GHCs, so that's not an option either if you want to avoid CPP, support GHCs back to 7.0, and be -Werror-clean. More generally, 'hiding'-imports aren't robust in terms of forward-compatibility.
Did you try a .hs-boot file with your self-import trick?
Not yet

The other two work arounds are 1. Explicit import lists for the stuff you need. 2. Explicit export list for your module (which you do), and internally use non-overloaded identifiers. module AnnoyinglyLongModuleName ( AnnoyinglyLongModuleName.length , AnnoyinglyLongModuleName.null ) where length = length' null = null' length' :: a -> Int length' _ = 0 null' :: a -> Bool null' = (== 0) . length' On 29.09.2014 10:48, Herbert Valerio Riedel wrote:
On 2014-09-29 at 10:43:28 +0200, Andreas Abel wrote:
Indeed, being able to introduce a short name for the current module, or having a fixed short name like 'This' or 'Self' would be neat.
The standard workaround for your example would be
import Prelude hiding (length,null)
That won't work though, because what I failed to mention is that I needed this (while avoiding CPP) to cope with external modules growing their exports lists, such as Data.Foldable starting to export 'length' and 'null' in base-4.8.0.0
Moreover, hiding a non-existent symbol is a warning in recent GHC's but a hard error in older GHCs, so that's not an option either if you want to avoid CPP, support GHCs back to 7.0, and be -Werror-clean.
More generally, 'hiding'-imports aren't robust in terms of forward-compatibility.
Did you try a .hs-boot file with your self-import trick?
Not yet
-- Andreas Abel <>< Du bist der geliebte Mensch. Department of Computer Science and Engineering Chalmers and Gothenburg University, Sweden andreas.abel@gu.se http://www2.tcs.ifi.lmu.de/~abel/

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
participants (5)
-
Andreas Abel
-
Christian Maeder
-
Herbert Valerio Riedel
-
Herbert Valerio Riedel
-
Jan Stolarek