外部依赖关系,Haskell,堆栈:我应该修改一些东西或“导入"应该足够吗? [英] External dependencies, Haskell, stack: should I modify something or 'import' suppose to be sufficient?
问题描述
对于Haskell以及堆栈我都是新手.
I am pretty new to Haskell as well as stack.
import Data.Set
import Data.Stack
以上语句触发编译错误:找不到模块'Data.Set'.也许您的意思是"Data.Int"
.我试图用Google搜索,但没有发现类似的东西.
The statements above trigger compilation error: Could not find module 'Data.Set'. Perhaps you meant 'Data.Int'
. I tried to google and found nothing similar.
因此,我的问题是:我是否需要手动指定外部依赖项,或者只是我的 stack build
命令为什么无法从某种程度的缓存或存储库中获取适当的模块?
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?
如果我必须手动指定依赖项,我应该使用 .cabal
还是 .yaml
?处理版本控制的正确方法是什么?
In case I have to specify my dependencies manually, should I prefer .cabal
or .yaml
? What's the correct way to deal with versioning?
推荐答案
[我需要手动指定外部依赖项吗[...]?
[Do] I need to specify external dependencies manually [...]?
是的
由于使用的是Stack,因此很容易指定要在代码中导入的依赖包.根据您的Stack版本,默认配置可能会有所不同:
Since you are using Stack, it is easy to specify the dependent packages you import in your code. Depend on your Stack version, the default configuration might be a little bit different:
-
如果您使用最新版本的Stack创建了项目,则会在项目的根目录中看到
package.yaml
(在此代码中使用了hpack
大小写以指定配置).您需要在此处添加包依赖关系,例如,Data.Set
的containers
.这是我的一个项目中的依赖项部分的示例:
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). You need to add package dependencies there, e.g.,containers
forData.Set
. Here's an example of a dependencies section in one of my projects:
dependencies:
- base >= 4.7 && < 5
- containers
- time
- network
- bytestring
如果您使用的是旧版本的 stack
,但没有看到 package.yaml
,则需要编辑您的项目名称.cabal
添加依赖项.这是完整的文档,告诉您如何执行此操作: https://docs.haskellstack.org/en/stable/GUIDE/#adding-dependencies
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. Here's the complete document telling you how to do it: https://docs.haskellstack.org/en/stable/GUIDE/#adding-dependencies
我个人更喜欢使用 hpack
( package.yaml
)的新系统.基本上,它更简单,并且可以节省您声明所有模块的时间(与依赖性无关).如果您有 package.yaml
,请不要编辑 .cabal
,它是由 hpack
自动生成的.
Personally, I prefer the new system with 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
.
这篇关于外部依赖关系,Haskell,堆栈:我应该修改一些东西或“导入"应该足够吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!