[英]stack.yaml file & .cabal file differences?
I have recently started using stack for Haskell, when specifying external dependencies for your project. 我最近开始为Haskell使用stack,为项目指定外部依赖项。 Sometimes you place it in the .cabal file while other times you place it in the .yaml file. 有时您将它放在.cabal文件中,而有时您将它放在.yaml文件中。
Am I right in thinking that when you put it in the cabal file it only looks in the stackage repository for your packages. 我是否正确地认为当您将其放入cabal文件时,它只会在堆栈存储库中查找您的包。 However when you place it in your .yaml file it also searches in the Hackage server, if it cannot find it in any of the snapshots? 但是,当您将它放在.yaml文件中时,它还会在Hackage服务器中搜索,如果它无法在任何快照中找到它?
All of the dependencies for your project go into the .cabal
file. 项目的所有依赖项都会进入.cabal
文件。 You are correct, though, that sometimes you also list packages in the stack.yaml
file, which can be understandably confusing. 但是,你是正确的,有时你也会在stack.yaml
文件中列出包,这可以理解为令人困惑。 Why is that? 这是为什么?
Well, the .cabal
file always expresses your dependencies upon packages, but the stack.yaml
file effectively configures where those packages come from . 好吧, .cabal
文件总是表示你对包的依赖,但是stack.yaml
文件有效地配置了这些包的来源 。 Usually, when using stack
, packages come from Stackage based on the resolver you specify in the stack.yaml
file. 通常,在使用stack
,包来自Stackage,基于您在stack.yaml
文件中指定的解析程序 。 However, Stackage does not include all the packages in Hackage, and it is not intended to—when you need packages that live outside of Stackage, you have to specify them in the stack.yaml
file. 但是,Stackage不包含Hackage中的所有软件包,并且不打算 - 当您需要在Stackage之外的软件包时,您必须在stack.yaml
文件中指定它们。
Why is this? 为什么是这样? Well, the resolver automatically couples two important pieces of information together: package names and package versions. 好吧,解析器会自动将两个重要的信息耦合在一起:包名和包版本。 Stackage resolvers provide a (weak) guarantee that all of the packages within a single resolver will work together, so when a package comes from a resolver, there is no need to manually pick which version you want. Stackage解析器提供(弱)保证单个解析器中的所有包可以一起工作,因此当包来自解析器时,无需手动选择所需的版本。 Instead, Stackage will decide for you. 相反,Stackage将为您决定。
When pulling packages from Hackage, you do not have this luxury, so you need to specify packages and their versions using extra-deps
. 当从Hackage拉包,你没有这种奢侈,所以你需要指定使用的软件包及其版本extra-deps
。 For example, you might have something like this: 例如,您可能有这样的事情:
extra-deps:
- crypto-pubkey-openssh-0.2.7
- data-bword-0.1
- data-dword-0.3
This entry determines specifically which versions of which packages should be pulled from Hackage rather than Stackage. 此条目具体确定应从Hackage而不是Stackage中提取哪些软件包的版本。
When building an application, this might seem a little redundant—you can specify version constraints in the .cabal
file, too, so why duplicate them in the stack.yaml
file? 构建应用程序时,这似乎有点多余 - 您也可以在.cabal
文件中指定版本约束,那么为什么要在stack.yaml
文件中复制它们呢? However, when building a library, the distinction is a little more significant: the .cabal
file expresses the actual version constraints of your library (if any), but the stack.yaml
file specifies precisely which versions to actually install when developing locally. 但是,在构建库时,区别更为重要: .cabal
文件表示库的实际版本约束(如果有),但stack.yaml
文件精确指定了在本地开发时实际安装的版本。
In this sense, the stack.yaml
file serves a purpose similar to the Gemfile.lock
or npm-shrinkwrap.json
files of other package managers, though the responsibilities are not nearly as clear-cut with stack
(in part due to historical reasons around how Haskell's package system works and some of the problems it's had in the past). 从这个意义上讲, stack.yaml
文件的用途类似于其他软件包管理器的Gemfile.lock
或npm-shrinkwrap.json
Gemfile.lock
文件,尽管责任并不像stack
那样明确(部分原因是由于历史原因) Haskell的包系统如何工作以及它过去遇到的一些问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.