简体   繁体   English

是否可以为haskell脚本指定`stack.yaml`文件?

[英]Is it possible to specify a `stack.yaml` file for a haskell script?

Let's say I have the following script inside my haskell project directory: 假设我的haskell项目目录中有以下脚本:

#!/usr/bin/env stack
-- stack --resolver lts-12.5 script

-- some imports here

main :: IO ()
main = do
  -- some code here

I'd like to use the stack.yaml file that exists inside the project directory, in order to get the required packages, as I want to get them from a specific git commit instead of lts-12.5 . 我想使用项目目录中存在的stack.yaml文件,以获取所需的包,因为我想从特定的git提交而不是lts-12.5获取它们。

I've tried adding --stack-yaml stack.yaml after --resolver lts-12.5 but I'm getting this warning when I run the script: Ignoring override stack.yaml file for script command: stack.yaml . 我尝试在--resolver lts-12.5之后添加--stack-yaml stack.yaml但是当我运行脚本时我收到此警告: Ignoring override stack.yaml file for script command: stack.yaml

Is it possible to use my stack.yaml file for the script? 是否可以将我的stack.yaml文件用于脚本? or is it possible to specify the git commit from which I want to get the package (like using location with commit and git inside stack.yaml )? 或者是否可以指定我想从中获取包的git提交(比如在stack.yaml使用commitgit location )?

You can achieve this using custom snapshot files. 您可以使用自定义快照文件实现此目的。 For example, in snapshot.yaml : 例如,在snapshot.yaml

resolver: ghc-8.4.3
name: has-acme-missiles
packages:
- acme-missiles-0.3

In Main.hs : Main.hs

#!/usr/bin/env stack
-- stack --resolver snapshot.yaml script
import Acme.Missiles

main :: IO ()
main = launchMissiles

Results in: 结果是:

$ ./Main.hs 
Nuclear launch detected.

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM