haskell vscode下的环境搭配(包含各种坑的解决办法)
這可能是最傻瓜化的在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/ | shor:
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>.
換源
畢竟源在國外,所以我們首先必須要進行換源,幸好清華大學開源網站鏡像站有提供,更具體一點可以看Stackage 鏡像使用說明,這里記錄下
vim ~/.stack/config.yaml # add package-indices: - name: Tsinghuadownload-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.jsonlts-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。
要想使用以上插件,必須安裝以下幾個包:
安裝時可能出現問題
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.24Basically 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"
總結
以上是生活随笔為你收集整理的haskell vscode下的环境搭配(包含各种坑的解决办法)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 南阳62(笨小熊)
- 下一篇: JAVA加密算法(DSA)