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
[email protected]
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
[email protected]
http://www2.tcs.ifi.lmu.de/~abel/
_______________________________________________
ghc-devs mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/ghc-devs