GHC import function or error

I found that the GHC accepts the following code:

import Prelude hiding (filter)
import qualified Prelude as P

The idea of ​​these two imports is to make all Prelude functions available as usual, but require that they filterbe qualified as P.filter.

I have never seen such an example anywhere, so my question is: is this a function or an error in GHC?

thanks

+4
source share
2 answers

It is allowed. The import mechanism is very flexible, sometimes surprising.

You can, for example, import a module under different names:

import qualified M as A
import qualified M as B

After that, the two A.xand B.xwill invoke M.x.

Perhaps more surprisingly, you can also import two modules under the same name.

import qualified M as A
import qualified N as A

A.x M.x, N.x. , .

, , , .

+3

, Github, , , .

:

import Data.Text (Text)
import qualified Data.Text as T

, Text , , Prelude (, Data.Text.filter, Data.Text.zip ..).

+3

Source: https://habr.com/ru/post/1615922/


All Articles