本文介绍了导入语法"import" cryptonite"中带引号的字符串有什么作用? Crypto.Hash`是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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)

在导入的 haskell Wiki上似乎未提及该语法.

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

"cryptonite"字符串在这里做什么?

What does the "cryptonite" string do here?

此语法从何而来?

这是Haskell2010的一部分吗?如果是,它是否在语言报告中提到?

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

推荐答案

使用 PackageImports 扩展名:

import "network" Network.Socket

将导入模块Network.Socket 从软件包network(任何版本)中获取.这可能用来 当多个模块提供相同的模块时,可以消除导入的歧义 软件包,或者同时存在于当前正在构建的软件包和 外部包装.

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.

偶尔会出现两个程序包导出具有相同名称的模块的情况.例如, hashmap unordered-containers 导出 .如果同时安装了两个软件包,则我们希望在不同的软件包之间进行歧义消除.因此,使用这种类型的导入,作者可以指定 cryptonite 需要使用.

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.

据我所知,这不是标准的Haskell(在某种意义上,其他Haskell编译器没有没有支持此功能,似乎 not Haskell 2010报告的导入声明部分),但是是格拉斯哥Haskell编译器扩展.当然,其他编译器也可以支持此功能,但是没有此扩展名的编译器仍然可以正确地称自己为"Haskell编译器".为了激活此扩展,您需要使用-XPackageImports扩展进行编译:

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

这是一个 dynamic 标志,因此也可以在Haskell源文件的编译指示"中指定.

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

这篇关于导入语法"import" cryptonite"中带引号的字符串有什么作用? Crypto.Hash`是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-27 22:01