[英]External dependencies, Haskell, stack: should I modify something or 'import' suppose to be sufficient?
I am pretty new to Haskell as well as stack. 对于Haskell以及堆栈我都是很新的。
import Data.Set
import Data.Stack
The statements above trigger compilation error: Could not find module 'Data.Set'. Perhaps you meant 'Data.Int'
上面的语句触发编译错误: Could not find module 'Data.Set'. Perhaps you meant 'Data.Int'
Could not find module 'Data.Set'. Perhaps you meant 'Data.Int'
. Could not find module 'Data.Set'. Perhaps you meant 'Data.Int'
。 I tried to google and found nothing similar. 我试图谷歌搜索,没有发现类似的东西。
Hence, my question is: do I need to specify external dependencies manually or just my stack build
command somewhy fails to grab appropriate modules from somewhat cache or repository? 因此,我的问题是:我是否需要手动指定外部依赖项,还是只是我的stack build
命令为什么无法从某种程度的缓存或存储库中获取适当的模块?
In case I have to specify my dependencies manually, should I prefer .cabal
or .yaml
? 如果我必须手动指定依赖项,我应该选择.cabal
还是.yaml
? What's the correct way to deal with versioning? 处理版本控制的正确方法是什么?
[Do] I need to specify external dependencies manually [...]? [我需要手动指定外部依赖项吗?
Yes. 是。
Since you are using Stack, it is easy to specify the dependent packages you import in your code. 由于使用的是Stack,因此很容易指定要在代码中导入的依赖包。 Depend on your Stack version, the default configuration might be a little bit different: 根据您的Stack版本,默认配置可能有所不同:
If you created your project with the latest version of Stack, you will see package.yaml
in the root of your project ( hpack
is used in this case to specify the configurations). 如果使用最新版本的Stack创建项目,则会在项目的根目录中看到package.yaml
(在这种情况下,使用hpack
来指定配置)。 You need to add package dependencies there, eg, containers
for Data.Set
. 您需要在其中添加包依赖关系,例如Data.Set
containers
。 Here's an example of a dependencies section in one of my projects: 这是我的一个项目中的依赖项部分的示例:
dependencies: - base >= 4.7 && < 5 - containers - time - network - bytestring
If you are using an older version of stack
and do not see package.yaml
, you need to edit your-project-name.cabal
to add the dependencies. 如果您使用的是较旧版本的stack
,但看不到package.yaml
,则需要编辑your-project-name.cabal
以添加依赖项。 Here's the complete document telling you how to do it: https://docs.haskellstack.org/en/stable/GUIDE/#adding-dependencies 这是完整的文档,告诉您如何执行此操作: https : //docs.haskellstack.org/en/stable/GUIDE/#adding-dependencies
Personally, I prefer the new system with hpack
( package.yaml
). 就个人而言,我更喜欢带有hpack
( package.yaml
)的新系统。 Basically, it is simpler, and it saves you time declaring all modules you have (not about dependency). 基本上,它更简单,并且可以节省您声明所有模块的时间(与依赖性无关)。 If you have package.yaml
, do not edit .cabal
, which is automatically generated by hpack
. 如果您有package.yaml
,请不要编辑.cabal
,它是hpack
自动生成的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.