堆栈找不到下载的模块(Data.MultiSet) [英] Stack can't find a downloaded module (Data.MultiSet)

查看:61
本文介绍了堆栈找不到下载的模块(Data.MultiSet)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在Linux中使用堆栈来编译haskell代码,今天我第一次安装了外部模块.我通过运行以下命令安装了Data.MultiSet:

I've been using stack (in my linux computer) to compile my haskell code and today I installed for the first time an external module. I installed Data.MultiSet by running the following command:

sudo堆栈安装多集

sudo stack install multiset

应该成功安装了模块,但是我无法加载它,当我尝试编译代码时,堆栈会抛出以下消息:

Supposedly the module was succesfully installed but I can't load it, stack throws the following message when I try to compile my code:

..错误:找不到模块"Data.MultiSet" ...

..error: Could not find module ‘Data.MultiSet’...

我检查了.stack目录中包含的文件,并且有很多文件带有此程序包的名称,但是我对该目录树不是很熟悉.我还尝试在项目的package.yaml的依赖项字段中写入模块的名称,但是它也不起作用.有什么线索吗?谢谢!

I checked the files contained in my .stack directory and there are many files with the name of this package but I am not very familiar with this directory tree. I also tried writing the name of the module in the dependency field of the package.yaml of my project but it didn't work either. Any clues of what's happening? Thanks!

推荐答案

堆栈不能那样工作. Stack背后的想法是:您有一个 project ,您知道该项目的依赖关系,而Stack确保您现在或将来始终可以构建该项目.堆栈不是关于以某种方式对系统进行调整以使您可以随时随地访问某些软件包的信息.

Stack doesn't work like that. The idea behind Stack is this: you have a project, you know the dependencies of this project, and Stack ensures you can always build that project – now or in the future. Stack is not about tweaking your system in some way that'll give you access to some packages here and now.

因此,如果您将要使用Stack进行开发(我个人不是,但是我也不是说这是个坏主意;很多Haskellers会这样做),那么您应该首先设置项目中正在处理的文件.这就像将文件设为堆栈片段一样简单:在文件顶部添加以下内容(我假设它称为script.hs)

So, if you're going to use Stack for development (which I personally don't, but I also don't say it's a bad idea; lots Haskellers do this) then you should first set up the file you're working on as part of a project. This can be as simple as making your file a Stack snippet: add the following to the top of your file (I'll assume it's called script.hs)

#!/usr/bin/env stack
{- stack --resolver lts-13.0 --install-ghc
      runghc --package multiset
  -}

(您也可以在命令行中为stack传递这些标志,但这很快就会变得乏味.env确实没有做任何事情,但是始终如一.)

(You could also pass those flags on the command line for stack, but that gets tedious quickly. env really does nothing else, but consistently.)

然后使文件可执行 –在Linux或OSX上,可以使用chmod +x script.hs完成–编译&运行该脚本将是./script.hs. (不是 stack script.hsghc script.hs.)这样做的好处是,您可以即时持续集成":如果Stack现在可以构建在计算机上运行脚本的功能,则可以非常确定它将来也可以在其他任何计算机上运行,​​而无需记住要安装什么软件包等.

Then make your file executable – on Linux or OSX this can be done with chmod +x script.hs – and all you need to do to compile & run that script will be ./script.hs. (Not stack script.hs or ghc script.hs.) The great thing about this is that you get "instant continuous integration": if Stack is able to build run your script on your computer now, you can be pretty sure that it'll also work on any other computer in the future, without you needing to remember what packages to install etc..

有关该技术的更多信息: https://www.fpcomplete .com/blog/2016/08/bitrot-free-scripts .

More info on that technique: https://www.fpcomplete.com/blog/2016/08/bitrot-free-scripts.

如果您编写的不仅仅是一个简单的脚本,则应为其进行正确的Cabal/Stack配置.可以使用cabal init轻松创建(无论您要使用Cabal还是Stack).

If it's more than a simple script you're writing, you should make a proper Cabal/Stack configuration for it. This can be created easily with cabal init (regardless of whether you will use Cabal or Stack).

这篇关于堆栈找不到下载的模块(Data.MultiSet)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆