这可能是最傻瓜化的在 vscode 下的 haskell 配置介绍文章
为什么要写这篇文章?
在自己写搭建环境的过程中,搜了一些博文,有些真的及其不服责任和敷衍,草草几句话就带过,但是在 google 上排名还很高,带着一种鄙视这些文章的态度,于是写下这篇文章,希望给后面的人有帮助
安装 haskell
我的平台:deepin-15.8,基于 debian8,(ubuntu 等应该
这里是一份 haskell 的学习指南,粗略介绍了安装,资源等一些东西根据上面链接的内容,我们可以得知:不推荐使用 Haskell-platform 直接安装也不太推荐使用 cabel
更推荐使用 stack 安装官网安装文档
安装
For many Un*x operating systems, all you need to do is run:// 对于 unix 类系统
curl -sSL https://get.haskellstack.org/ | sh
or:
wget -qO- https://get.haskellstack.org/ | sh
(对于 windows 系统)On Windows, you can download and install the Windows 64-bit Installer.
创建你的 project:
stack new my-project
cd my-project
stack setup
stack build
stack exec my-project-exe
The stack new command will create a new directory containing all the needed files to start a project correctly.
The stack setup will download the compiler if necessary in an isolated location (default ~/.stack) that won’t interfere with any system-level installations. (For information on installation paths, please use the stack path command.).
The stack build command will build the minimal project.
stack exec my-project-exe will execute the command.
If you just want to install an executable using stack, then all you have to do is stack install <package-name>.
注意,linux 系统最好将~/.local/bin 加入 PATH 中
换源
毕竟源在国外,所以我们首先必须要进行换源,幸好清华大学开源网站镜像站有提供,更具体一点可以看 Stackage 镜像使用说明,这里记录下
vim ~/.stack/config.yaml
# add
package-indices:
– name: Tsinghua
download-prefix: https://mirrors.tuna.tsinghua.edu.cn/hackage/package/
http: https://mirrors.tuna.tsinghua.edu.cn/hackage/00-index.tar.gz
setup-info: “http://mirrors.tuna.tsinghua.edu.cn/stackage/stack-setup.yaml”
urls:
latest-snapshot: http://mirrors.tuna.tsinghua.edu.cn/stackage/snapshots.json
lts-build-plans: http://mirrors.tuna.tsinghua.edu.cn/stackage/lts-haskell/
nightly-build-plans: http://mirrors.tuna.tsinghua.edu.cn/stackage/stackage-nightly/
# 开始使用 stack,这个命令需要稍稍等待
stack setup
# 安装完成之后
stack ghci
# 会出现以下输出
Configuring GHCi with the following packages:
GHCi, version 8.0.1: http://www.haskell.org/ghc/ :? for help
Loaded GHCi configuration from /private/var/folders/0s/j3c0tlx10z9_x9wzhl14xmgh0000gn/T/ghci11066/ghci-script
Prelude>
搭建 vscode
打开 vscode,下载 extension,这里我推荐这四个插件:Haskell Syntax Highlighting、Haskell ghc-mod、haskell-linter、Haskelly,其中第四个插件离不开 stack。要想使用以上插件,必须安装以下几个包:
# for Haskell ghc-mod
stack install ghc-mod
# for haskell-linter
stack install hlint
# for Haskelly
stack install intero
stack install QuickCheck
stack install stack-run
安装时可能出现问题
ghc-mod 安装时如果报错
stackoverflow 上的解决办法我采用了 stack install ghc-mod –resolver lts-8.24 去解决
stack-run 安装报错
github issue
I found a workaround.
Create a file: ~/.stack/global-project/stack-cabal-1.24.yaml
flags: {}
extra-package-dbs: []
packages: []
extra-deps: []
resolver: lts-8.24
Basically it’s using an old stack lts that was from around the time the last update to stack-run was >made.
Then just run this:
stack –stack-yaml ~/.stack/global-project/stack-cabal-1.24.yaml install stack-run
and it should work (did for me, at least)
intero 安装报错
stack install intero –resolver lts-8.24 去解决
vscode 插件配置
然后打开 vscode 的配置文件,加上 ghc-mod 和 hlint 的路径,如下:
“haskell.ghcMod.executablePath”: “/home/.local/bin/ghc-mod”,
“haskell.hlint.executablePath”: “/home/.local/bin/hlint”