Imports a haskell module as a qualified good practice?

I know that import-related names have the advantage of preventing name conflicts. I ask purely in terms of readability.

Not familiar with haskell standard libraries, one thing that I find annoying when reading Haeckel code (mostly from books and textbooks online) is that when I come across a function, I don't know if it belongs to an imported module or will later defined by the user.

Based on the background of C ++, it is generally considered good practice to call a standard library function with a namespace, such as std :: find. Is this the same for haskell? If not, how do you overcome the problem I mentioned above?

+4
source share
4 answers

From the Haskell Style Guide :

Always use explicit import lists or qualified imports for standard and third-party libraries. This makes the code more resilient to changes in these libraries. Exception: Prelude.

So the answer is yes. Using qualified imports is considered good practice for standard and third-party libraries other than Prelude. But for an infix function with characters (something like <|*|>), you can explicitly import it, since qualified import does not look nice on it.

+7
source

, . , , , , - , .

, Control.Applicative, ; . , - , , , . import Data.List (sortBy), import System.Random.Shuffle (shuffleM) - , , , ( using std::cout;). , , ghci

* ClunkyModule > : strangeFunction

, .

, , , : . - , -, .

+5

, . functionName , , , . " " , ! , . , , .

import qualified Long.Path.To.Module as M

... use M.functionName ...

import qualified Long.Path.To.Module as Module

... use Module.functionName ...

import qualified Long.Path.To.Module

... use Long.Path.To.Module.functionName ...

infix.

+2

.

1) - . B.ByteString , Data.ByteString.ByteString. , Control.Monad.

2) , //, . , - , - , .

3) , , , .

4) If possible, try to avoid using functions with the same name from different modules, even if these modules are renamed differently. If someone knows what the function is doing X.foo, they are likely to be confused by the function Y.foo. If this is unavoidable, consider creating a separate, very small module that imports both functions and exports them under different names.

+1
source

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


All Articles