Aliasing current module qualifier

Jan Stolarek jan.stolarek at p.lodz.pl
Mon Sep 29 09:52:28 UTC 2014


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 at haskell.org
> http://www.haskell.org/mailman/listinfo/glasgow-haskell-users




More information about the Glasgow-haskell-users mailing list