gpt4 book ai didi

haskell - 导入语法 `import "cryptonite"Crypto.Hash` 中带引号的字符串是什么意思?

转载 作者:行者123 更新时间:2023-12-03 07:08:52 25 4
gpt4 key购买 nike

如标题所述。有一个代码库,我在其中看到了以下语法

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

haskell wiki on imports 上似乎没有提到这个语法。 .

"cryptonite" 字符串在这里有什么作用?

这个语法从何而来?

它是 Haskell2010 的一部分,如果是的话,在语言报告中的什么地方提到了它?

最佳答案

这是使用PackageImports时支持的额外语法。扩展名:

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.

偶尔会发生两个包导出同名模块的情况。例如 hashmapunordered-containers导出Data.HashSet。如果两个软件包都已安装,我们希望消除不同软件包之间的歧义。通过这种类型的导入,作者指定 Crypto.Hash cryptonite的模块需要使用。

据我所知,这不是标准的 Haskell(从某种意义上说,其他 Haskell 编译器没有支持这一点,似乎没有import statement section of the Haskell 2010 report ),但是 Glasgow Haskell 编译器扩展。当然其他编译器也可以支持这一点,但是没有此扩展的编译器仍然可以正确地称自己为“Haskell 编译器”。为了激活此扩展,您需要使用 -XPackageImports 扩展进行编译:

ghc <b>-XPackageImports</b> main.hs

这是一个动态标志,因此也可以在 Haskell 源文件的“pragma”中指定。

关于haskell - 导入语法 `import "cryptonite"Crypto.Hash` 中带引号的字符串是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51742717/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com