haskell vscode下的环境搭配(包含各类坑的解决办法)

这多是最傻瓜化的在vscode下的haskell配置介绍文章

为何要写这篇文章?

在本身写搭建环境的过程当中,搜了一些博文,有些真的及其不服责任和敷衍,草草几句话就带过,可是在google上排名还很高,带着一种鄙视这些文章的态度,因而写下这篇文章,但愿给后面的人有帮助linux

安装haskell

个人平台:deepin-15.8,基于debian8,(ubuntu等应该没太大区别

这里是一份haskell的学习指南,粗略介绍了安装,资源等一些东西
根据上面连接的内容,咱们能够得知:
不推荐使用Haskell-platform直接安装
也不太推荐使用cabelgit

更推荐使用stack安装
官网安装文档github

安装

For many Un*x operating systems, all you need to do is run://对于unix类系统json

curl -sSL https://get.haskellstack.org/ | sh

or:ubuntu

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

(对于windows系统)On Windows, you can download and install the Windows 64-bit Installer.vim

建立你的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 镜像使用说明,这里记录下windows

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
要想使用以上插件,必须安装如下几个包:app

# 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去解决curl

stack-run安装报错

github issueide

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"

图片描述

相关文章
相关标签/搜索