新年になったし、いっちょ関数型言語を学んでみるかとHaskellに手を出してみたので、環境構築のメモを投稿します。
色々と環境構築の記事を読んでみたところ、2024年2月現在はHaskell Language Server + VSCode を用いた開発が一強のようです。
参考にさせていただいた記事
GHCupのinstall
GHCup
はGHC
やStack
などの関連ツールのバージョン管理を行ってくれるミドルウェアになります。Rustにおけるrustup
、Pythonにおけるpyenv
ですね。
とりあえずこれを入れておけば必要なものを一緒にインストールしてくれるようです。
最新の情報はGHCUp公式を参照してください。
PowerShellで以下のコマンドを実行します。
Set-ExecutionPolicy Bypass -Scope Process -Force;[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; try { Invoke-Command -ScriptBlock ([ScriptBlock]::Create((Invoke-WebRequest https://www.haskell.org/ghcup/sh/bootstrap-haskell.ps1 -UseBasicParsing))) -ArgumentList $true } catch { Write-Error $_ }
インストール中にいくつか質問をされます。
- インストールフォルダについて
Where to install to (this should be a short Path, preferably a Drive like 'C:\')?
If you accept this path, binaries will be installed into 'C:\ghcup\bin' and msys2 into 'C:\ghcup\msys64'.
Press enter to accept the default [C:\]:
好みの場所を指定してください。デフォルトはC:\
になります。
- Cabalのインストール先について
Specify Cabal directory (this is where haskell packages end up)
Press enter to accept the default [C:\\cabal]:
これも好みの場所で大丈夫です。
- Haskell Language Serverのインストールについて
Install HLS
Do you want to install the haskell-language-server (HLS) for development purposes as well?
[Y] Yes [N] No [A] Abort [?] Help (default is "N"):
HLSをインストールするかを聞かれます。後でインストールすることもできますが、今回はすぐに使うのでYesで押下してください。
- Stackのインストールについて
Install stack
Do you want to install stack as well?
[Y] Yes [N] No [A] Abort [?] Help (default is "N"):
これも同じです。後から入れることもできます。特に問題なければYesを押下してください。
- MSYS2のインストールについて
Install MSys2
Do you want GHCup to install a default MSys2 toolchain (recommended)?
[Y] Yes [N] No [?] Help (default is "Y"):
同上です。
VSCodeで拡張機能の追加
今度はVSCode側の準備を行います。
VSCodeのHaskell拡張機能をinstallします。

GHCupが見つからないと怒られる場合はExtension Settingsからパスを指定します

(インストール時にghcupが入っていれば自動でパスが通るのかもしれません。自分の場合は先に拡張機能を入れてしまったのでエラーになってしまいました。)
GHCupが認識されればそれを経由して適切なバージョンのHLSがインストールされます。
haskellのファイルに下記のような関数定義等のサジェストがでるようになれば成功です。

もし変化がない方は、コマンドパレットからRestart Haskell LSP Server
を実行してみてください。

コメント