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"

圖片描述

相關文章
相關標籤/搜索