What does a quoted string in the import syntax `import “cryptonite” Crypto.Hash` mean?

落爺英雄遲暮 提交于 2020-04-06 04:56:45

问题


As stated in the title. There is a codebase, where I have seen the following syntax

import       "cryptonite" Crypto.Hash
             (Context, Digest, SHA256, hash, hashFinalize, hashInit,
             hashUpdate)

This syntax doesn't seem to be mentioned on haskell wiki on imports.

What does the "cryptonite" string do here?

Where does this syntax come from?

Is is part of Haskell2010 and if it is so where in the language report is it mentioned?


回答1:


This is extra syntax that is supported when using the PackageImports extension:

With the PackageImports extension, GHC allows import declarations to be qualified by the package name that the module is intended to be imported from. For example:

import "network" Network.Socket

would import the module Network.Socket from the package network (any version). This may be used to disambiguate an import when the same module is available from multiple packages, or is present in both the current package being built and an external package.

The special package name this can be used to refer to the current package being built.

It occasionally happens that two packages export a module with the same name. For example both hashmap and unordered-containers export Data.HashSet. If both packages are installed, we want to disambiguate between the different packages. With this type of import, the author thus specifies that the Crypto.Hash module of the cryptonite needs to be used.

This is to to the best of my knowledge not standard Haskell (in the sense that other Haskell compilers do not have to support this, it seems not specified in the import statement section of the Haskell 2010 report), but a Glasgow Haskell compiler extension. Of course other compilers can support this as well, but a compiler without this extension, can still rightfully call itself a "Haskell compiler". In order to activate this extension, you need to compile with the -XPackageImports extension:

ghc -XPackageImports main.hs

This is a dynamic flag, and thus can be specified in the "pragma" of a Haskell source file as well.



来源:https://stackoverflow.com/questions/51742717/what-does-a-quoted-string-in-the-import-syntax-import-cryptonite-crypto-hash

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!