🎆

静的型付け関数型言語 PureScript の環境構築。【 WSL2/2021年9月 ver. 】

に公開

雨のしずくに
景色が映っている
しずくのなかに
別の世界がある

― 大江健三郎『私という小説家の作り方』(新潮社)

前提

Ubuntu 20.04 LTS(WSL2)
PureScript 0.14.4

手順

以下の公式のドキュメントを参考に、PureScript の環境構築を行ってまいります。

Getting Started with PureScript
https://github.com/purescript/documentation/blob/master/guides/Getting-Started.md

最初に PureScript をグローバルインストールします。

terminal
npm install -g purescript
 npm install -g purescript
npm WARN deprecated request@2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142
npm WARN deprecated har-validator@5.1.5: this library is no longer supported
npm WARN deprecated uuid@3.4.0: Please upgrade  to version 7 or higher.  Older versions may use Math.random() in certain circumstances, which is known to be problematic.  See https://v8.dev/blog/math-random for details.
/home/mumei/.nodenv/versions/14.17.3/bin/purs -> /home/mumei/.nodenv/versions/14.17.3/lib/node_modules/purescript/purs.bin

> purescript@0.14.3 postinstall /home/mumei/.nodenv/versions/14.17.3/lib/node_modules/purescript
> install-purescript --purs-ver=0.14.3

 Check if a prebuilt 0.14.3 binary is provided for linux (785ms)
 Download the prebuilt PureScript binary (992ms)
 Verify the prebuilt binary works correctly (140ms)
 Save the downloaded binary to the npm cache directory (328ms)

Installed to /home/mumei/.nodenv/versions/14.17.3/lib/node_modules/purescript/purs.bin 49.66 MB
Cached to /home/mumei/.cache/purescript-npm-installer-nodejs/content-v2/sha512/9f/2b 49.66 MB

+ purescript@0.14.3
added 153 packages from 88 contributors in 18.925s

path を通します。

ここで、npm install -g purescript実行時のメッセージを見てみます。
すると、
Installed to /home/mumei/.nodenv/versions/14.17.3/lib/node_modules/purescript/purs.bin とありますように、
/home/mumei/.nodenv/versions/14.17.3/lib/node_modules/purescript/purs.binに PureScript がインストールされたようです。

(ここは環境によって違うと思うので読み替えてください。)

したがって、この path を設定します。

.zshrc
export PATH="$HOME/.nodenv/versions/14.17.3/lib/node_modules/purescript/purs.bin:$PATH"

.zshrc を更新して path を反映します。

terminal
source ~/.zshrc

ここで任意のディレクトリを作成し、以下のコマンドを実行します。

terminal
spago init

すると、下記のようなファイル、ディレクトリがインストールされました。

さらに以下を実行します。

terminal
spago build

ここで、私の環境では、キャプチャのように、「依存している Prelude がない」というエラーが出たので、

サジェストどおり、

terminal
spago install prelude

でインストールしました。

再度、spago build を実行し、spago testを実行します。

test/Main.purs
module Test.Main where

import Prelude

import Effect (Effect)
import Effect.Class.Console (log)

main :: Effect Unit
main = do
  log "🍝"
  log "You should add some tests."

(すごい PureScript の syntax highlight が効く!!)

terminal
spago test
 spago test 
[info] Build succeeded.
🍝
You should add some tests.
[info] Tests succeeded.

成功しました。これで、いったんは PureScript の導入は成功です。

ちなみに、🍝が文字化けするという場合もあるかと思います。

私の場合、Windows Terminal や Visual Studio Code で、CaskaydiaCove NF というフォントを設定しましたら、文字化けせずに、🍝が表示されました。

以上となります。

Discussion