这可能是最傻瓜化的在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 thestack 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安装报错
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 --resolver lts-6.6 intero-0.1.15
去解决
vscode 插件配置
然后打开vscode
的配置文件,加上ghc-mod和hlint
的路径,如下:
"haskell.ghcMod.executablePath": "/home/.local/bin/ghc-mod",
"haskell.hlint.executablePath": "/home/.local/bin/hlint"
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。