如何在Linux上安装2018年的Haskell(平台或堆栈)?

时间:2021-10-22 17:43:50

I am trying to learn Haskell from the book Learn You a Haskell by Miran Lipovača. Both the book and haskell.org recommends installing the Haskell Platform but there is no download for Manjaro Linux (Arch based) which I use.

我试图从MiranLipovača的书“了解你的哈斯克尔”一书中学习Haskell。本书和haskell.org都建议安装Haskell平台,但我没有下载Manjaro Linux(基于Arch)。

I found this guide from 2014 and decided to install the packages from Manjaro's repository. This worked fine until I wanted to use haskell-mode in Emacs. I troubleshooted this and found out that it was a problem with the packages (Stack mainly).

我从2014年开始找到这个指南,并决定从Manjaro的存储库安装这些软件包。这很好用,直到我想在Emacs中使用haskell-mode。我对此进行了故障排除,发现它是一个包的问题(主要是Stack)。

Looking for ways to fix this I found this Reddit thread, which describes ways to install Haskell (not the Platform), and problems with the packages. I followed one of the comments and ended up installing Stack (and GHC) with the script as described here:

寻找解决方法,我找到了这个Reddit线程,它描述了安装Haskell(不是平台)的方法,以及包的问题。我按照其中一条评论结束了安装Stack(和GHC)的脚本,如下所述:

wget -qO- https://get.haskellstack.org/ | sh
stack setup
stack update

My questions are related to this:

我的问题与此有关:

  1. Is this the recommended starter way to install a functioning Haskell (Platform) on Linux (Manjaro) in 2018? If not: what is the/a way to do it?
  2. 这是在2018年在Linux(Manjaro)上安装正常运行的Haskell(平台)的推荐启动方式吗?如果不是:这样做的方式是什么?
  3. Haskell Platform contains: GHC, Cabal, Stack, and some packages. GHC and Stack are installed, how do I install Cabal through Stack?
  4. Haskell平台包含:GHC,Cabal,Stack和一些包。安装了GHC和Stack,如何通过Stack安装Cabal?
  5. Do I need Cabal (Stack seems to have overlapping functionality)?
  6. 我是否需要Cabal(堆栈似乎具有重叠功能)?
  7. Looking at the packages of the Haskell Platform, what, if anything, am I missing by installing Stack as described above? Looking in $HOME/.stack/programs/x86_64-linux/ghc-tinfo6-nopie-8.2.2/lib/ghc-8.2.2 many of these seems installed already.
  8. 看看Haskell平台的软件包,如上所述安装Stack会丢失什么,如果有的话?查看$ HOME / .stack / programs / x86_64-linux / ghc-tinfo6-nopie-8.2.2 / lib / ghc-8.2.2这些似乎已经安装了很多。

2 个解决方案

#1


17  

Here's a (long) alternative answer. Note that I used to recommend Stack for beginners, too, but I've since changed my mind.

这是一个(长期)替代答案。请注意,我曾经为初学者推荐Stack,但我已经改变了主意。

TL;DR: Either Haskell Platform or a pure Stack installation can provide you with everything you need, and you won't be "missing" anything by choosing one or the other. You'll probably find it easiest to skip Stack and install Haskell Platform using the "Generic" Linux installer, because it comes with everything you need and the setup will more closely matched what's described in the LYAH book. You can install Stack later when you're doing more serious development on multiple projects. If you prefer to stick with a pure Stack installation, I'd suggest starting with a "global project only" workflow. Either way, you can use "haskell-mode" with some configuration fixes suggested below (including a key setting that will be required if you're working in the global project of a Stack-only installation).

TL; DR:无论是Haskell平台还是纯粹的Stack安装都可以为您提供所需的一切,而且您不会通过选择其中任何一个来“遗漏”任何东西。您可能会发现使用“通用”Linux安装程序跳过Stack并安装Haskell平台最容易,因为它提供了您需要的所有内容,并且设置将更加符合LYAH书中描述的内容。当您在多个项目上进行更严肃的开发时,可以稍后安装Stack。如果您更喜欢坚持使用纯Stack安装,我建议您从“仅限全局项目”工作流程开始。无论哪种方式,您都可以使用“haskell-mode”以及下面建议的一些配置修复程序(包括如果您在仅限堆栈的安装的全局项目中工作将需要的密钥设置)。

Here's the long answer...

这是一个很长的答案......

Stack vs. Platform vs. Cabal

The LYAH book pre-dates Stack, which is certainly the main reason it doesn't mention it. At haskell.org, they recommend using either a minimal installer, Stack, or the Haskell Platform. All three methods are perfectly reasonable ways in 2018 to set up a working Haskell environment. They differ both in the ways they choose to isolate different versions of the compiler and/or libraries into "sandboxes" for development work, and in how much they install initially, but there's nothing "missing" from any one of them that can't be installed on demand. Depending on which you choose, there will be some differences in your workflow (see below).

LYAH书预先列出Stack,这肯定是它没有提到它的主要原因。在haskell.org,他们建议使用最小安装程序,Stack或Haskell平台。在2018年,所有这三种方法都是完全合理的方法来建立一个有效的Haskell环境。他们选择将不同版本的编译器和/或库分离为开发工作的“沙箱”以及最初安装的数量方式各不相同,但是其中任何一个都无法“丢失”按需安装。根据您的选择,您的工作流程会有一些差异(见下文)。

Both Stack and Cabal are combined package managers and build tools. (Stack has the added ability to actually bootstrap an entire Haskell installation, which is why it's also an installation method in its own right.) While you're working through LYAH, you won't actually be using the "build tool" functionality directly on your own projects. (The built-in build facilities of GHC are more than adequate for building small, multi-module projects.) You'll just need the package manager functionality to install additional libraries.

Stack和Cabal都是组合包管理器和构建工具。 (Stack具有实际引导整个Haskell安装的附加功能,这就是为什么它本身也是一种安装方法。)当你在LYAH工作时,你实际上不会直接使用“构建工具”功能在你自己的项目上。 (GHC的内置构建工具足以构建小型,多模块项目。)您只需要包管理器功能即可安装其他库。

Since Stack and Cabal manage their packages separately, if you're using Stack, you'll have no particular need to use Cabal directly. You can install it if you want (and in fact, Stack makes use of Cabal for some esoteric functionality, like "stack solver", and will require it to be installed in those cases):

由于Stack和Cabal分别管理它们的包,如果你正在使用Stack,你将没有特别需要直接使用Cabal。你可以根据需要安装它(实际上,Stack使用Cabal来实现一些深奥的功能,比如“堆栈求解器”,并且需要在这些情况下安装它):

$ stack install cabal-install

But, even though this will put "cabal" into "$HOME/.local/bin" (and you'll want to make sure this is in your path), you'll find that you need to jump through hoops to run it:

但是,即使这会将“cabal”放入“$ HOME / .local / bin”(并且你想确保它在你的路径中),你会发现你需要跳过箍来运行它:

$ stack exec --no-ghc-package-path cabal -- list

and it doesn't really do anything useful as far as your Stack environment is concerned.

就Stack环境而言,它并没有真正做任何有用的事情。

Update: A note on the "$HOME/.local/bin" path. It looks like the installation script from https://get.haskellstack.org/ may install Stack itself to /usr/local/bin/stack by default if there's no existing installation. However, it should display a warning to put $HOME/.local/bin in your path. If you upgrade Stack in the future with stack upgrade, it'll install the new version of stack there, and that directory will also be used if you install packages that include binaries. For example, stack install hlint will install the Haskell Lint program hlint to that directory. So, it's a good idea to have it in your path and somewhere before /usr/local/bin.

更新:关于“$ HOME / .local / bin”路径的注释。如果没有现有安装,默认情况下,https://get.haskellstack.org/中的安装脚本可能会将堆栈本身安装到/ usr / local / bin / stack。但是,它应该显示一个警告,将$ HOME / .local / bin放在您的路径中。如果您将来使用堆栈升级升级Stack,它将在那里安装新版本的堆栈,如果您安装包含二进制文件的软件包,也将使用该目录。例如,stack install hlint会将Haskell Lint程序hlint安装到该目录。所以,在/ usr / local / bin之前将它放在你的路径和某个地方是个好主意。

What's Missing with Stack

I think that covers your first three questions. For your last, the main thing you're missing having installed Stack instead of the Haskell Platform is that, by design, Stack doesn't really install anything globally other than "stack" itself. So, all your Haskell work including running the Haskell interpreter ("ghci") or compiler ("ghc"), all needs to be done within a Stack environment, either using a specific corresponding Stack command:

我认为这涵盖了你的前三个问题。对于你的最后一件事,你安装Stack而不是Haskell平台时遇到的主要问题是,根据设计,Stack并不真正安装除“堆栈”本身以外的任何其他东西。因此,所有Haskell工作包括运行Haskell解释器(“ghci”)或编译器(“ghc”),都需要在Stack环境中完成,或者使用特定的相应Stack命令:

$ echo 'main = putStrLn "Hello, world!"' > Hello.hs
$ stack ghc -- Hello.hs
[1 of 1] Compiling Main             ( Hello.hs, Hello.o )
Linking Hello ...
$ ./Hello 
Hello, world!
$ 

or else using "stack exec" to run a generic program within an appropriate Stack environment. For example, it can sometimes be helpful to run a Bash shell under stack, after which things behave sort of like a globally installed Haskell Platform environment:

或者使用“stack exec”在适当的Stack环境中运行通用程序。例如,在堆栈下运行Bash shell有时会很有帮助,之后事情就像全局安装的Haskell Platform环境一样:

$ stack exec bash
$ ghci
GHCi, version 8.2.2: http://www.haskell.org/ghc/  :? for help
Prelude> :quit
$ ghc -O2 Hello.hs
[1 of 1] Compiling Main             ( Hello.hs, Hello.o ) [flags changed]
Linking Hello ...
$ exit
$ ghc
The program 'ghc' is currently not installed. ...
$

The other thing you're missing is that the Haskell Platform installs a whole bunch of common libraries by default, while a fresh Stack environment starts with almost nothing (not even the compiler, before you run stack setup). While working through LYAH, you may find you need to periodically install additional libraries. For example, in the Input and Output chapter, the examples using random numbers (module System.Random) will require you to run:

您缺少的另一件事是默认情况下Haskell平台安装了一大堆公共库,而新的Stack环境几乎什么也没有(在运行堆栈设置之前,甚至没有编译器)。在通过LYAH工作时,您可能会发现需要定期安装其他库。例如,在“输入和输出”一章中,使用随机数的示例(模块System.Random)将要求您运行:

$ stack install random

and restart your interpreter.

并重新启动您的口译员。

Recommendation to Use Haskell Platform

Because Stack is a little complicated and you won't really need the facilities it provides at the beginning, you may find the Haskell Platform easier to use when you're starting out. (The "Generic" installer should work fine on your distribution.) It comes with everything installed, and the way you use it will more closely match the way things are described in LYAH. Together with haskell-mode, you should have a pretty decent Haskell environment.

因为Stack有点复杂而且您不需要在开始时提供它所提供的功能,所以您可能会发现在开始时Haskell平台更易于使用。 (“通用”安装程序应该可以在您的发行版上正常工作。)它随附了所有内容,并且您使用它的方式将更加符合LYAH中描述的内容。与haskell模式一起,你应该有一个相当不错的Haskell环境。

In general, there should be no issue having Stack and the Haskell Platform installed side-by-side (as evidenced by the fact that Haskell Platform actually includes Stack). Stack will maintain everything separately under the "$HOME/.stack" subdirectory, so there will be no interference between compilers or packages or anything. Note that in this setup, you'll use cabal to manage the packages installed on the Platform side of things, and stack -- obviously -- to manage packages on the Stack side.

一般来说,堆栈和Haskell平台并排安装应该没有问题(Haskell平台实际上包含Stack的事实证明了这一点)。 Stack将在“$ HOME / .stack”子目录下单独维护所有内容,因此编译器或包之间不会有任何干扰。请注意,在此设置中,您将使用cabal来管理安装在平台端的软件包,并显然可以堆栈以管理堆栈端的软件包。

Beginner Workflow for a Pure Stack Installation

If you want to stick with your pure Stack installation, I might suggest the following workflow when you're starting out:

如果您想坚持使用纯Stack安装,我可能会在您开始时建议以下工作流程:

You will see references to Stack projects, created with "stack new" or "stack init". Avoid these at the beginning, and stick with the stack "global project". This is the implicit project that will be in effect when you run "stack" in a directory that doesn't have a "stack.yaml" file (directly or in a parent directory):

您将看到使用“stack new”或“stack init”创建的Stack项目的引用。在开始时避免使用这些,并坚持使用堆栈“全局项目”。这是在没有“stack.yaml”文件(直接或在父目录中)的目录中运行“stack”时将生效的隐式项目:

$ cd
$ stack path --project-root
/u/buhr/.stack/global-project
$

When you're working in the global project (i.e., not somewhere under a stack.yaml file), you can invoke the interpreter and compiler with:

当您在全局项目中工作时(即,不在stack.yaml文件下的某个位置),您可以使用以下命令调用解释器和编译器:

$ stack exec ghci
$ stack ghc -- -O2 Hello.hs

and they will both have access to any additional libraries (packages) you've installed using commands like:

并且他们都可以使用以下命令访问您安装的任何其他库(包):

$ stack install random

Updated: A note on the difference between stack ghci and stack exec ghci. The former is intended to run GHCi within the context of a local project (i.e., working under a stack.yaml file). It passes some additional flags to hide globally installed packages and to automatically make available modules from your package. When working in the global project, I don't think there's any practical difference except that stack ghci generates a warning; and no matter which you use, you'll need to load your own modules explicitly with :load Whatever.hs. There's a little more info on the difference on this Stack documentation page, particularly at the bottom where it tries to explain the difference.

更新:关于stack ghci和stack exec ghci之间差异的注释。前者旨在在本地项目的上下文中运行GHCi(即,在stack.yaml文件下工作)。它传递一些额外的标志来隐藏全局安装的包,并自动从包中提供可用的模块。在全球项目中工作时,我认为除了堆栈ghci产生警告之外没有任何实际区别;无论你使用哪种,你都需要显式加载你自己的模块:load Whatever.hs。关于这个Stack文档页面的差异,有更多的信息,特别是在它试图解释差异的底部。

Eventually, you may switch to a workflow that uses Stack projects. This will involve using stack new to create a new Stack project directory, stack setup to install/link a private compiler version into that directory, and then modifying the project's xxx.cabal file (and possibly its stack.yaml file) to indicate which additional packages are required, instead of using stack install. It's all a little complicated when you just want to get started writing code.

最终,您可以切换到使用Stack项目的工作流程。这将涉及使用stack new来创建一个新的Stack项目目录,使用堆栈设置将私有编译器版本安装/链接到该目录,然后修改项目的xxx.cabal文件(可能还有其stack.yaml文件)以指示哪个附加包是必需的,而不是使用堆栈安装。当你只是想开始编写代码时,这有点复杂。

You may also see reference to Intero, an Emacs mode designed specifically for Stack. Intero is very nice, but it doesn't work very well when working on files in the global project. It'll tend to want to start up the interpreter in the directory "~/.stack/global-project", which is pretty useless. (I use Intero, but I've patched it to behave better in this respect.)

您还可以看到Intero的参考,这是专为Stack设计的Emacs模式。 Intero非常好,但在处理全局项目中的文件时效果不佳。它倾向于想要在目录“〜/ .stack / global-project”中启动解释器,这是非常没用的。 (我使用Intero,但我已修补它在这方面表现得更好。)

Configuring Haskell-Mode (for Either Platform or Stack)

It's probably best to stick with "haskell-mode" instead, and think about Intero when you start using non-global projects. I'd suggest installing "haskell-mode" from MELPA as per the instructions, but adding the following to your .emacs file instead of what's suggested in the documentation:

最好坚持使用“haskell-mode”,并在开始使用非全局项目时考虑Intero。我建议按照说明从MELPA安装“haskell-mode”,但是将以下内容添加到.emacs文件中,而不是文档中建议的内容:

(require 'haskell)

;; add capability to submit code to interpreter and mark errors
(add-hook 'haskell-mode-hook 'interactive-haskell-mode)

;; add missing keybindings for navigating errors
(define-key interactive-haskell-mode-map (kbd "M-n") 'haskell-goto-next-error)
(define-key interactive-haskell-mode-map (kbd "M-p") 'haskell-goto-prev-error)
(define-key interactive-haskell-mode-map (kbd "C-c M-p") 
 'haskell-goto-first-error)

;; merge this with your existing custom-set-variables
(custom-set-variables

 ;; NOTE: include following line to work around haskell-mode
 ;; bug if using GHC >= 8.2.1.
 ;; See: https://github.com/haskell/haskell-mode/issues/1553
 '(haskell-process-args-stack-ghci 
   '("--ghci-options=-ferror-spans -fshow-loaded-modules"
     "--no-build" "--no-load"))

 ;; some options suggested in the haskell-mode documentation
 '(haskell-process-auto-import-loaded-modules t)
 '(haskell-process-log t)
 '(haskell-process-suggest-remove-import-lines t)

 ;; make sure "stack ghci" is used, even in the global project
 '(haskell-process-type 'stack-ghci))

I've tested this with a pure Stack installation using "haskell-mode-20171022.26", and it seems to work fine. I can load a new Haskell file in the global project, submit it to an interactive session with "C-c C-l", and browse highlighted errors in the source file with "M-n" and "M-p". (The errors appear in the mini-buffer.)

我使用“haskell-mode-20171022.26”进行了纯粹的Stack安装测试,看起来效果很好。我可以在全局项目中加载新的Haskell文件,将其提交到带有“C-c C-l”的交互式会话,并使用“M-n”和“M-p”浏览源文件中突出显示的错误。 (错误出现在迷你缓冲区中。)

If you decide to use the Haskell Platform instead, I think all of this "haskell-mode" configuration will still apply, except you should remove the very last customization line. (The default haskell-process-type of auto will pick something appropriate.)

如果您决定使用Haskell平台,我认为所有这些“haskell-mode”配置仍将适用,除非您应删除最后一个自定义行。 (auto的默认haskell-process-type将选择合适的东西。)

Hope that helps!

希望有所帮助!

#2


5  

You have three choices.

你有三个选择。

Haskell Platform

It is a possibility but not a popular choice for many reasons which you will discover in due time if you choose to go this way. You will have a much better experience and get much better support with either Stack or Nix. Which of those two people use seems to be mostly about personal preference. They are different beasts but to a beginner the differences will not be immediately obvious so there's little hope that you will be able to make an "informed decision". Just pick one and reevaluate later.

这是一种可能性,但不是一个受欢迎的选择,出于很多原因,如果您选择这样,您将在适当的时候发现。使用Stack或Nix可以获得更好的体验并获得更好的支持。这两个人中的哪一个似乎主要是关于个人偏好。它们是不同的野兽,但对于初学者而言,差异不会立即明显,因此您无法做出“明智的决定”。只需选择一个并稍后重新评估。

Stack

This is what I would suggest to anyone (not familiar with Nix) wanting to get started with Haskell quickly. Period. You do not need to separately install anything, Stack will handle all the Haskell stuff for you. You don't normally ever use cabal directly with Stack. stack build uses cabal internally but you don't need to worry about that. One thing to note, Stack is not a package manager. It's a build tool. It doesn't normally install anything. It does however fetch all the dependencies that it needs and stores them in ~/.stack together with other things.

这是我建议任何想要快速开始使用Haskell的人(不熟悉Nix)。期。你不需要单独安装任何东西,Stack会为你处理所有Haskell的东西。您通常不会直接使用Stack与cabal。堆栈构建在内部使用cabal,但您不必担心这一点。有一点需要注意,Stack不是包管理器。这是一个构建工具。它通常不会安装任何东西。但它会获取所需的所有依赖项,并将它们与其他内容一起存储在〜/ .stack中。

Nix

This is what I use personally so I may be biased but I think this is the best solution overall in the long term. The caveat is that there is a rather steep learning curve and you are given many chances to shoot yourself in the foot when starting out.

这是我个人使用的所以我可能有偏见,但我认为从长远来看这是最好的解决方案。需要注意的是,有一个相当陡峭的学习曲线,你有很多机会在开始时用脚射击自己。

I highly recommend starting with Stack but keeping an open mind about Nix as your journey with Haskell continues.

我强烈建议从Stack开始,但随着你对Haskell的旅程的继续,保持对Nix的开放态度。

#1


17  

Here's a (long) alternative answer. Note that I used to recommend Stack for beginners, too, but I've since changed my mind.

这是一个(长期)替代答案。请注意,我曾经为初学者推荐Stack,但我已经改变了主意。

TL;DR: Either Haskell Platform or a pure Stack installation can provide you with everything you need, and you won't be "missing" anything by choosing one or the other. You'll probably find it easiest to skip Stack and install Haskell Platform using the "Generic" Linux installer, because it comes with everything you need and the setup will more closely matched what's described in the LYAH book. You can install Stack later when you're doing more serious development on multiple projects. If you prefer to stick with a pure Stack installation, I'd suggest starting with a "global project only" workflow. Either way, you can use "haskell-mode" with some configuration fixes suggested below (including a key setting that will be required if you're working in the global project of a Stack-only installation).

TL; DR:无论是Haskell平台还是纯粹的Stack安装都可以为您提供所需的一切,而且您不会通过选择其中任何一个来“遗漏”任何东西。您可能会发现使用“通用”Linux安装程序跳过Stack并安装Haskell平台最容易,因为它提供了您需要的所有内容,并且设置将更加符合LYAH书中描述的内容。当您在多个项目上进行更严肃的开发时,可以稍后安装Stack。如果您更喜欢坚持使用纯Stack安装,我建议您从“仅限全局项目”工作流程开始。无论哪种方式,您都可以使用“haskell-mode”以及下面建议的一些配置修复程序(包括如果您在仅限堆栈的安装的全局项目中工作将需要的密钥设置)。

Here's the long answer...

这是一个很长的答案......

Stack vs. Platform vs. Cabal

The LYAH book pre-dates Stack, which is certainly the main reason it doesn't mention it. At haskell.org, they recommend using either a minimal installer, Stack, or the Haskell Platform. All three methods are perfectly reasonable ways in 2018 to set up a working Haskell environment. They differ both in the ways they choose to isolate different versions of the compiler and/or libraries into "sandboxes" for development work, and in how much they install initially, but there's nothing "missing" from any one of them that can't be installed on demand. Depending on which you choose, there will be some differences in your workflow (see below).

LYAH书预先列出Stack,这肯定是它没有提到它的主要原因。在haskell.org,他们建议使用最小安装程序,Stack或Haskell平台。在2018年,所有这三种方法都是完全合理的方法来建立一个有效的Haskell环境。他们选择将不同版本的编译器和/或库分离为开发工作的“沙箱”以及最初安装的数量方式各不相同,但是其中任何一个都无法“丢失”按需安装。根据您的选择,您的工作流程会有一些差异(见下文)。

Both Stack and Cabal are combined package managers and build tools. (Stack has the added ability to actually bootstrap an entire Haskell installation, which is why it's also an installation method in its own right.) While you're working through LYAH, you won't actually be using the "build tool" functionality directly on your own projects. (The built-in build facilities of GHC are more than adequate for building small, multi-module projects.) You'll just need the package manager functionality to install additional libraries.

Stack和Cabal都是组合包管理器和构建工具。 (Stack具有实际引导整个Haskell安装的附加功能,这就是为什么它本身也是一种安装方法。)当你在LYAH工作时,你实际上不会直接使用“构建工具”功能在你自己的项目上。 (GHC的内置构建工具足以构建小型,多模块项目。)您只需要包管理器功能即可安装其他库。

Since Stack and Cabal manage their packages separately, if you're using Stack, you'll have no particular need to use Cabal directly. You can install it if you want (and in fact, Stack makes use of Cabal for some esoteric functionality, like "stack solver", and will require it to be installed in those cases):

由于Stack和Cabal分别管理它们的包,如果你正在使用Stack,你将没有特别需要直接使用Cabal。你可以根据需要安装它(实际上,Stack使用Cabal来实现一些深奥的功能,比如“堆栈求解器”,并且需要在这些情况下安装它):

$ stack install cabal-install

But, even though this will put "cabal" into "$HOME/.local/bin" (and you'll want to make sure this is in your path), you'll find that you need to jump through hoops to run it:

但是,即使这会将“cabal”放入“$ HOME / .local / bin”(并且你想确保它在你的路径中),你会发现你需要跳过箍来运行它:

$ stack exec --no-ghc-package-path cabal -- list

and it doesn't really do anything useful as far as your Stack environment is concerned.

就Stack环境而言,它并没有真正做任何有用的事情。

Update: A note on the "$HOME/.local/bin" path. It looks like the installation script from https://get.haskellstack.org/ may install Stack itself to /usr/local/bin/stack by default if there's no existing installation. However, it should display a warning to put $HOME/.local/bin in your path. If you upgrade Stack in the future with stack upgrade, it'll install the new version of stack there, and that directory will also be used if you install packages that include binaries. For example, stack install hlint will install the Haskell Lint program hlint to that directory. So, it's a good idea to have it in your path and somewhere before /usr/local/bin.

更新:关于“$ HOME / .local / bin”路径的注释。如果没有现有安装,默认情况下,https://get.haskellstack.org/中的安装脚本可能会将堆栈本身安装到/ usr / local / bin / stack。但是,它应该显示一个警告,将$ HOME / .local / bin放在您的路径中。如果您将来使用堆栈升级升级Stack,它将在那里安装新版本的堆栈,如果您安装包含二进制文件的软件包,也将使用该目录。例如,stack install hlint会将Haskell Lint程序hlint安装到该目录。所以,在/ usr / local / bin之前将它放在你的路径和某个地方是个好主意。

What's Missing with Stack

I think that covers your first three questions. For your last, the main thing you're missing having installed Stack instead of the Haskell Platform is that, by design, Stack doesn't really install anything globally other than "stack" itself. So, all your Haskell work including running the Haskell interpreter ("ghci") or compiler ("ghc"), all needs to be done within a Stack environment, either using a specific corresponding Stack command:

我认为这涵盖了你的前三个问题。对于你的最后一件事,你安装Stack而不是Haskell平台时遇到的主要问题是,根据设计,Stack并不真正安装除“堆栈”本身以外的任何其他东西。因此,所有Haskell工作包括运行Haskell解释器(“ghci”)或编译器(“ghc”),都需要在Stack环境中完成,或者使用特定的相应Stack命令:

$ echo 'main = putStrLn "Hello, world!"' > Hello.hs
$ stack ghc -- Hello.hs
[1 of 1] Compiling Main             ( Hello.hs, Hello.o )
Linking Hello ...
$ ./Hello 
Hello, world!
$ 

or else using "stack exec" to run a generic program within an appropriate Stack environment. For example, it can sometimes be helpful to run a Bash shell under stack, after which things behave sort of like a globally installed Haskell Platform environment:

或者使用“stack exec”在适当的Stack环境中运行通用程序。例如,在堆栈下运行Bash shell有时会很有帮助,之后事情就像全局安装的Haskell Platform环境一样:

$ stack exec bash
$ ghci
GHCi, version 8.2.2: http://www.haskell.org/ghc/  :? for help
Prelude> :quit
$ ghc -O2 Hello.hs
[1 of 1] Compiling Main             ( Hello.hs, Hello.o ) [flags changed]
Linking Hello ...
$ exit
$ ghc
The program 'ghc' is currently not installed. ...
$

The other thing you're missing is that the Haskell Platform installs a whole bunch of common libraries by default, while a fresh Stack environment starts with almost nothing (not even the compiler, before you run stack setup). While working through LYAH, you may find you need to periodically install additional libraries. For example, in the Input and Output chapter, the examples using random numbers (module System.Random) will require you to run:

您缺少的另一件事是默认情况下Haskell平台安装了一大堆公共库,而新的Stack环境几乎什么也没有(在运行堆栈设置之前,甚至没有编译器)。在通过LYAH工作时,您可能会发现需要定期安装其他库。例如,在“输入和输出”一章中,使用随机数的示例(模块System.Random)将要求您运行:

$ stack install random

and restart your interpreter.

并重新启动您的口译员。

Recommendation to Use Haskell Platform

Because Stack is a little complicated and you won't really need the facilities it provides at the beginning, you may find the Haskell Platform easier to use when you're starting out. (The "Generic" installer should work fine on your distribution.) It comes with everything installed, and the way you use it will more closely match the way things are described in LYAH. Together with haskell-mode, you should have a pretty decent Haskell environment.

因为Stack有点复杂而且您不需要在开始时提供它所提供的功能,所以您可能会发现在开始时Haskell平台更易于使用。 (“通用”安装程序应该可以在您的发行版上正常工作。)它随附了所有内容,并且您使用它的方式将更加符合LYAH中描述的内容。与haskell模式一起,你应该有一个相当不错的Haskell环境。

In general, there should be no issue having Stack and the Haskell Platform installed side-by-side (as evidenced by the fact that Haskell Platform actually includes Stack). Stack will maintain everything separately under the "$HOME/.stack" subdirectory, so there will be no interference between compilers or packages or anything. Note that in this setup, you'll use cabal to manage the packages installed on the Platform side of things, and stack -- obviously -- to manage packages on the Stack side.

一般来说,堆栈和Haskell平台并排安装应该没有问题(Haskell平台实际上包含Stack的事实证明了这一点)。 Stack将在“$ HOME / .stack”子目录下单独维护所有内容,因此编译器或包之间不会有任何干扰。请注意,在此设置中,您将使用cabal来管理安装在平台端的软件包,并显然可以堆栈以管理堆栈端的软件包。

Beginner Workflow for a Pure Stack Installation

If you want to stick with your pure Stack installation, I might suggest the following workflow when you're starting out:

如果您想坚持使用纯Stack安装,我可能会在您开始时建议以下工作流程:

You will see references to Stack projects, created with "stack new" or "stack init". Avoid these at the beginning, and stick with the stack "global project". This is the implicit project that will be in effect when you run "stack" in a directory that doesn't have a "stack.yaml" file (directly or in a parent directory):

您将看到使用“stack new”或“stack init”创建的Stack项目的引用。在开始时避免使用这些,并坚持使用堆栈“全局项目”。这是在没有“stack.yaml”文件(直接或在父目录中)的目录中运行“stack”时将生效的隐式项目:

$ cd
$ stack path --project-root
/u/buhr/.stack/global-project
$

When you're working in the global project (i.e., not somewhere under a stack.yaml file), you can invoke the interpreter and compiler with:

当您在全局项目中工作时(即,不在stack.yaml文件下的某个位置),您可以使用以下命令调用解释器和编译器:

$ stack exec ghci
$ stack ghc -- -O2 Hello.hs

and they will both have access to any additional libraries (packages) you've installed using commands like:

并且他们都可以使用以下命令访问您安装的任何其他库(包):

$ stack install random

Updated: A note on the difference between stack ghci and stack exec ghci. The former is intended to run GHCi within the context of a local project (i.e., working under a stack.yaml file). It passes some additional flags to hide globally installed packages and to automatically make available modules from your package. When working in the global project, I don't think there's any practical difference except that stack ghci generates a warning; and no matter which you use, you'll need to load your own modules explicitly with :load Whatever.hs. There's a little more info on the difference on this Stack documentation page, particularly at the bottom where it tries to explain the difference.

更新:关于stack ghci和stack exec ghci之间差异的注释。前者旨在在本地项目的上下文中运行GHCi(即,在stack.yaml文件下工作)。它传递一些额外的标志来隐藏全局安装的包,并自动从包中提供可用的模块。在全球项目中工作时,我认为除了堆栈ghci产生警告之外没有任何实际区别;无论你使用哪种,你都需要显式加载你自己的模块:load Whatever.hs。关于这个Stack文档页面的差异,有更多的信息,特别是在它试图解释差异的底部。

Eventually, you may switch to a workflow that uses Stack projects. This will involve using stack new to create a new Stack project directory, stack setup to install/link a private compiler version into that directory, and then modifying the project's xxx.cabal file (and possibly its stack.yaml file) to indicate which additional packages are required, instead of using stack install. It's all a little complicated when you just want to get started writing code.

最终,您可以切换到使用Stack项目的工作流程。这将涉及使用stack new来创建一个新的Stack项目目录,使用堆栈设置将私有编译器版本安装/链接到该目录,然后修改项目的xxx.cabal文件(可能还有其stack.yaml文件)以指示哪个附加包是必需的,而不是使用堆栈安装。当你只是想开始编写代码时,这有点复杂。

You may also see reference to Intero, an Emacs mode designed specifically for Stack. Intero is very nice, but it doesn't work very well when working on files in the global project. It'll tend to want to start up the interpreter in the directory "~/.stack/global-project", which is pretty useless. (I use Intero, but I've patched it to behave better in this respect.)

您还可以看到Intero的参考,这是专为Stack设计的Emacs模式。 Intero非常好,但在处理全局项目中的文件时效果不佳。它倾向于想要在目录“〜/ .stack / global-project”中启动解释器,这是非常没用的。 (我使用Intero,但我已修补它在这方面表现得更好。)

Configuring Haskell-Mode (for Either Platform or Stack)

It's probably best to stick with "haskell-mode" instead, and think about Intero when you start using non-global projects. I'd suggest installing "haskell-mode" from MELPA as per the instructions, but adding the following to your .emacs file instead of what's suggested in the documentation:

最好坚持使用“haskell-mode”,并在开始使用非全局项目时考虑Intero。我建议按照说明从MELPA安装“haskell-mode”,但是将以下内容添加到.emacs文件中,而不是文档中建议的内容:

(require 'haskell)

;; add capability to submit code to interpreter and mark errors
(add-hook 'haskell-mode-hook 'interactive-haskell-mode)

;; add missing keybindings for navigating errors
(define-key interactive-haskell-mode-map (kbd "M-n") 'haskell-goto-next-error)
(define-key interactive-haskell-mode-map (kbd "M-p") 'haskell-goto-prev-error)
(define-key interactive-haskell-mode-map (kbd "C-c M-p") 
 'haskell-goto-first-error)

;; merge this with your existing custom-set-variables
(custom-set-variables

 ;; NOTE: include following line to work around haskell-mode
 ;; bug if using GHC >= 8.2.1.
 ;; See: https://github.com/haskell/haskell-mode/issues/1553
 '(haskell-process-args-stack-ghci 
   '("--ghci-options=-ferror-spans -fshow-loaded-modules"
     "--no-build" "--no-load"))

 ;; some options suggested in the haskell-mode documentation
 '(haskell-process-auto-import-loaded-modules t)
 '(haskell-process-log t)
 '(haskell-process-suggest-remove-import-lines t)

 ;; make sure "stack ghci" is used, even in the global project
 '(haskell-process-type 'stack-ghci))

I've tested this with a pure Stack installation using "haskell-mode-20171022.26", and it seems to work fine. I can load a new Haskell file in the global project, submit it to an interactive session with "C-c C-l", and browse highlighted errors in the source file with "M-n" and "M-p". (The errors appear in the mini-buffer.)

我使用“haskell-mode-20171022.26”进行了纯粹的Stack安装测试,看起来效果很好。我可以在全局项目中加载新的Haskell文件,将其提交到带有“C-c C-l”的交互式会话,并使用“M-n”和“M-p”浏览源文件中突出显示的错误。 (错误出现在迷你缓冲区中。)

If you decide to use the Haskell Platform instead, I think all of this "haskell-mode" configuration will still apply, except you should remove the very last customization line. (The default haskell-process-type of auto will pick something appropriate.)

如果您决定使用Haskell平台,我认为所有这些“haskell-mode”配置仍将适用,除非您应删除最后一个自定义行。 (auto的默认haskell-process-type将选择合适的东西。)

Hope that helps!

希望有所帮助!

#2


5  

You have three choices.

你有三个选择。

Haskell Platform

It is a possibility but not a popular choice for many reasons which you will discover in due time if you choose to go this way. You will have a much better experience and get much better support with either Stack or Nix. Which of those two people use seems to be mostly about personal preference. They are different beasts but to a beginner the differences will not be immediately obvious so there's little hope that you will be able to make an "informed decision". Just pick one and reevaluate later.

这是一种可能性,但不是一个受欢迎的选择,出于很多原因,如果您选择这样,您将在适当的时候发现。使用Stack或Nix可以获得更好的体验并获得更好的支持。这两个人中的哪一个似乎主要是关于个人偏好。它们是不同的野兽,但对于初学者而言,差异不会立即明显,因此您无法做出“明智的决定”。只需选择一个并稍后重新评估。

Stack

This is what I would suggest to anyone (not familiar with Nix) wanting to get started with Haskell quickly. Period. You do not need to separately install anything, Stack will handle all the Haskell stuff for you. You don't normally ever use cabal directly with Stack. stack build uses cabal internally but you don't need to worry about that. One thing to note, Stack is not a package manager. It's a build tool. It doesn't normally install anything. It does however fetch all the dependencies that it needs and stores them in ~/.stack together with other things.

这是我建议任何想要快速开始使用Haskell的人(不熟悉Nix)。期。你不需要单独安装任何东西,Stack会为你处理所有Haskell的东西。您通常不会直接使用Stack与cabal。堆栈构建在内部使用cabal,但您不必担心这一点。有一点需要注意,Stack不是包管理器。这是一个构建工具。它通常不会安装任何东西。但它会获取所需的所有依赖项,并将它们与其他内容一起存储在〜/ .stack中。

Nix

This is what I use personally so I may be biased but I think this is the best solution overall in the long term. The caveat is that there is a rather steep learning curve and you are given many chances to shoot yourself in the foot when starting out.

这是我个人使用的所以我可能有偏见,但我认为从长远来看这是最好的解决方案。需要注意的是,有一个相当陡峭的学习曲线,你有很多机会在开始时用脚射击自己。

I highly recommend starting with Stack but keeping an open mind about Nix as your journey with Haskell continues.

我强烈建议从Stack开始,但随着你对Haskell的旅程的继续,保持对Nix的开放态度。