gpt4 book ai didi

haskell - 如果两个模块同名怎么办?

转载 作者:行者123 更新时间:2023-12-03 15:10:06 25 4
gpt4 key购买 nike

我有两个提供同名模块的包。当我尝试加载模块时出现错误

Ambiguous interface for ....: It was found in multiple packages.



我应该怎么做才能解决这个问题?

具体来说, cryptonite包和 crypto-api包提供名称为 Crypto.Random 的模块.如何指定要从哪个包加载模块?

最佳答案

如果你碰巧在使用 ghc >= 8.2 阴谋安装 >= 2.0 ,另一种选择是重命名 mixins 中的冲突模块cabal 文件的部分:

  build-depends:       base >=4.10 && <4.11,
cryptonite >= 0.24,
crypto-api >= 0.13.2
mixins:
cryptonite (Crypto.Random as CryptoniteCrypto.Random),
crypto-api (Crypto.Random as CryptoAPICrypto.Random)

然后,您可以导入重命名的模块:
module Main where

import CryptoniteCrypto.Random
import CryptoAPICrypto.Random

以这种方式重命名时要考虑的一件事是,未显式重命名的模块变得不可访问。

事实上,重命名模块的能力 seems to exist since GHC 7.10 ,通过 -package标志和 重新导出的模块 cabal 。 重新导出的模块 在声明时工作(发布包时),而 混合 在使用时工作(取决于包时)。

关于haskell - 如果两个模块同名怎么办?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47110907/

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