简体   繁体   English

外部依赖关系,Haskell,堆栈:我是否应该修改某些东西或“导入”以备足够?

[英]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版本,默认配置可能有所不同:

  1. 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 
  2. 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 ). 就个人而言,我更喜欢带有hpackpackage.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.

相关问题 Haskell堆栈版本依赖性 - Haskell stack version dependencies 如何将外部Haskell软件包添加到堆栈项目中? - How can I add an external Haskell package to a stack project? 编译带有外部依赖项的 haskell 脚本,无需 cabal - Compiling a haskell script with external dependencies without cabal Haskell:从具有百万值的列表构造IntMap时,我是否应该获得“堆栈空间溢出”? - Haskell: Should I get “Stack space overflow” when constructing an IntMap from a list with a million values? 使用Haskell Stack时我应该使用哪些-ghc-options? - Which -ghc-options should I use when using Haskell Stack? 无法在Haskell Stack项目中构建yesod / amazonka依赖项 - Trouble building yesod/amazonka dependencies in a Haskell Stack project Haskell:安装Yesod / Snap时出现问题,我想在Windows 7上通过cabal接收其他任何软件包 - Haskell: issue with installing Yesod/Snap and I suppose any other package via cabal on Windows 7 使用Haskell Stack构建工具的项目之间的依赖关系–最佳工作流程? - Dependencies between projects with Haskell Stack build tool — best workflow? 如何修改这个 Haskell function 所以我不必导入 Data.Bool 并且只使用前奏 function? - How do I modify this Haskell function so I don't have to import Data.Bool and only use prelude function? 我应该避免在Haskell中构建吗? - Should I avoid constructing in Haskell?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM