haiju's 開発メモ

開発に必要な情報を自分用にメモ

Manjaro Fluxbox 15.12_x86-64にインストールしたNode.js v8.9.4でPurescriptをインストール

jQueryは嫌いだけどJSでUIはもはや避けて通れないから何か

JSの処理系を覚えるとしたら何にしようか?ってことで、

Haskellをやってる人がまともな言語はPurescriptって言っていた

のを思い出して、ElmもいいけどあれはWebUIに特化してる気が

したので、この際、Purescriptにどっぷり沈んでみようと思って

環境を再構築した備忘録をまとめてみる(ΦωΦ)

さっきの記事の続きだけどwww

[手順]

1.npmでシステム全体にpurescriptをインストール。

% npm install -g purescript

/home/haiju/.anyenv/envs/nodenv/versions/8.9.4/bin/purs -> /home/haiju/.anyenv/envs/nodenv/versions/8.9.4/lib/node_modules/purescript/purs.bin

> purescript@0.11.7 postinstall /home/haiju/.anyenv/envs/nodenv/versions/8.9.4/lib/node_modules/purescript
> install-purescript --purs-ver=0.11.7 --name=purs.bin .
 
✔ Check if a prebuilt 0.11.7 binary is provided for Linux (12s)
✔ Download the prebuilt PureScript binary (3s)
✖ Verify the prebuilt binary works correctly
Error: Command failed: /home/haiju/.anyenv/envs/nodenv/versions/8.9.4/lib/node_modules/purescript/purs.bin --version

 /home/haiju/.anyenv/envs/nodenv/versions/8.9.4/lib/node_modules/purescript/purs.bin: error while loading shared libraries: libtinfo.so.5: cannot open shared object file: No suc h file or directory
at Promise.all.then.arr (/home/haiju/.anyenv/envs/nodenv/versions/8.9.4/lib/node_modules/purescript/node_modules/execa/index.js:231:11)
at <anonymous>
▬ Save the downloaded binary to the cache directory
 
↓ Fallback: building from source
 
✔ Check if 'stack' command is available
✔ Check if 'stack' command is available
1.6.3.1 found at /usr/bin/stack
✔ Download the PureScript 0.11.7 source (7s)
✔ Ensure the appropriate GHC is installed (1m)
✔ Build a binary from source (19m)
✔ Save the built binary to the cache directory (3s)
 
Installed to ~/.anyenv/envs/nodenv/versions/8.9.4/lib/node_modules/purescript/purs.bin
Cached to ~/.cache/purescript/npm/v0.11.7-linux-x64.tgz
 
+ purescript@0.11.7
added 118 packages in 1279.453s

2.purescriptのビルドツールのpulp,パッケージマネージャ?のbowerをインストール。

% npm install -g pulp bower

3.実行中にnpmをアップデートしろというメッセージが出るのでアップデート。

% npm i -g npm

/home/haiju/.anyenv/envs/nodenv/versions/8.9.4/bin/npm -> /home/haiju/.anyenv/envs/nodenv/versions/8.9.4/lib/node_modules/npm/bin/npm-cli.js
/home/haiju/.anyenv/envs/nodenv/versions/8.9.4/bin/npx -> /home/haiju/.anyenv/envs/nodenv/versions/8.9.4/lib/node_modules/npm/bin/npx-cli.js
+ npm@5.7.1
added 63 packages, removed 6 packages and updated 49 packages in 14.294s

4.改めて、pulpとbowerをインストール。

% npm install -g pulp bower

npm WARN deprecated bower@1.8.2: ...psst! Your project can stop working at any moment because its dependencies can change. Prevent this by migrating to Yarn: https://bower.io/blog/ 2017/how-to-migrate-away-from-bower/
/home/haiju/.anyenv/envs/nodenv/versions/8.9.4/bin/bower -> /home/haiju/.anyenv/envs/nodenv/versions/8.9.4/lib/node_modules/bower/bin/bower
/home/haiju/.anyenv/envs/nodenv/versions/8.9.4/bin/pulp -> /home/haiju/.anyenv/envs/nodenv/versions/8.9.4/lib/node_modules/pulp/index.js
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.1.3 (node_modules/pulp/node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.1.3: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
 
+ pulp@12.0.1
+ bower@1.8.2
updated 2 packages in 19.467s

5.pulpとbowerのPATHを.zshrcに設定し、再起動。

vim ~/.zchrc

export PATH="$HOME/.anyenv/envs/nodenv/versions/8.9.4/bin/bower:$PATH"

export PATH="$HOME/.anyenv/envs/nodenv/versions/8.9.4/bin/pulp:$PATH"

% source ~/.zshrc

6.pulpとbowerの動作確認のため、こんにちは世界サンプルを作成。

6-1.まず pulp init で任意のプロジェクト「hello-pur」プロジェクト作成。

pulp init
* Generating project skeleton in /home/haiju/workspace/hello-pur
bower purescript-console#* cached https://github.com/purescript/purescript-console.git#2.0.0
bower purescript-console#* validate 2.0.0 against https://github.com/purescript/purescript-console.git#*
bower purescript-prelude#* cached https://github.com/purescript/purescript-prelude.git#3.1.1
bower purescript-prelude#* validate 3.1.1 against https://github.com/purescript/purescript-prelude.git#*
bower purescript-console#* new version for https://github.com/purescript/purescript-console.git#*
bower purescript-console#* resolve https://github.com/purescript/purescript-console.git#*
bower purescript-console#* download https://github.com/purescript/purescript-console/archive/v3.0.0.tar.gz
bower purescript-console#* extract archive.tar.gz
bower purescript-console#* resolved https://github.com/purescript/purescript-console.git#3.0.0
bower purescript-eff#^3.0.0 cached https://github.com/purescript/purescript-eff.git#3.1.0
bower purescript-eff#^3.0.0 validate 3.1.0 against https://github.com/purescript/purescript-eff.git#^3.0.0
bower purescript-eff#^3.0.0 new version for https://github.com/purescript/purescript-eff.git#^3.0.0
bower purescript-eff#^3.0.0 resolve https://github.com/purescript/purescript-eff.git#^3.0.0
bower purescript-eff#^3.0.0 download https://github.com/purescript/purescript-eff/archive/v3.2.0.tar.gz
bower purescript-eff#^3.0.0 extract archive.tar.gz
bower purescript-eff#^3.0.0 resolved https://github.com/purescript/purescript-eff.git#3.2.0
bower purescript-monoid#^3.3.0 cached https://github.com/purescript/purescript-monoid.git#3.3.0
bower purescript-monoid#^3.3.0 validate 3.3.0 against https://github.com/purescript/purescript-monoid.git#^3.3.0
bower purescript-newtype#^2.0.0 cached https://github.com/garyb/purescript-newtype.git#2.0.0
bower purescript-newtype#^2.0.0 validate 2.0.0 against https://github.com/garyb/purescript-newtype.git#^2.0.0
bower purescript-invariant#^3.0.0 cached https://github.com/purescript/purescript-invariant.git#3.0.0
bower purescript-invariant#^3.0.0 validate 3.0.0 against https://github.com/purescript/purescript-invariant.git#^3.0.0
bower purescript-control#^3.0.0 cached https://github.com/purescript/purescript-control.git#3.3.1
bower purescript-control#^3.0.0 validate 3.3.1 against https://github.com/purescript/purescript-control.git#^3.0.0
bower purescript-prelude#^3.0.0 install purescript-prelude#3.1.1
bower purescript-console#^3.0.0 install purescript-console#3.0.0
bower purescript-eff#^3.0.0 install purescript-eff#3.2.0
bower purescript-monoid#^3.3.0 install purescript-monoid#3.3.0
bower purescript-invariant#^3.0.0 install purescript-invariant#3.0.0
bower purescript-newtype#^2.0.0 install purescript-newtype#2.0.0
bower purescript-control#^3.0.0 install purescript-control#3.3.1

purescript-prelude#3.1.1 bower_components/purescript-prelude

purescript-console#3.0.0 bower_components/purescript-console
└── purescript-eff#3.2.0
 
purescript-eff#3.2.0 bower_components/purescript-eff
├── purescript-monoid#3.3.0
└── purescript-prelude#3.1.1
 
purescript-monoid#3.3.0 bower_components/purescript-monoid
├── purescript-control#3.3.1
├── purescript-invariant#3.0.0
└── purescript-newtype#2.0.0
 
purescript-invariant#3.0.0 bower_components/purescript-invariant
└── purescript-prelude#3.1.1
 
purescript-newtype#2.0.0 bower_components/purescript-newtype
└── purescript-prelude#3.1.1
 
purescript-control#3.3.1 bower_components/purescript-control
└── purescript-prelude#3.1.1

bower purescript-psci-support#* cached https://github.com/purescript/purescript-psci-support.git#2.0.0
bower purescript-psci-support#* validate 2.0.0 against https://github.com/purescript/purescript-psci-support.git#*
bower purescript-psci-support#* new version for https://github.com/purescript/purescript-psci-support.git#*
bower purescript-psci-support#* resolve https://github.com/purescript/purescript-psci-support.git#*
bower purescript-psci-support#* download https://github.com/purescript/purescript-psci-support/archive/v3.0.0.tar.gz
bower purescript-psci-support#* extract archive.tar.gz
bower purescript-psci-support#* resolved https://github.com/purescript/purescript-psci-support.git#3.0.0
bower purescript-psci-support#^3.0.0 install purescript-psci-support#3.0.0
 
purescript-psci-support#3.0.0 bower_components/purescript-psci-support
└── purescript-console#3.0.0

7.途中でbowerもアップデートできるよメッセージが出るが今回は無視。

 ※アップデートする場合は以下。

% npm i -g bower to update

8.pulp buildコマンドでビルド。

 6で作成したhello-pursプロジェクトをビルド。

pulp build

* Building project in /home/haiju/workspace/hello-pur
Compiling Data.Boolean
Compiling Data.NaturalTransformation
Compiling Data.Show
Compiling Control.Semigroupoid
Compiling Control.Category
Compiling Data.Function
Compiling Data.Unit
Compiling Data.Void
Compiling Control.Lazy
Compiling Data.Semiring
Compiling Data.Semigroup
Compiling Data.HeytingAlgebra
Compiling Data.Eq
Compiling Data.Functor
Compiling Data.Ring
Compiling Control.Apply
Compiling Control.Alt
Compiling Data.CommutativeRing
Compiling Control.Plus
Compiling Control.Extend
Compiling Data.BooleanAlgebra
Compiling Data.Functor.Invariant
Compiling Data.Ordering
Compiling Data.EuclideanRing
Compiling Control.Comonad
Compiling Control.Applicative
Compiling Data.Ord.Unsafe
Compiling Data.Ord
Compiling Control.Bind
Compiling Control.Alternative
Compiling Data.DivisionRing
Compiling Data.Field
Compiling Control.Monad
Compiling Control.MonadZero
Compiling Data.Bounded
Compiling Control.MonadPlus
Compiling Prelude
Compiling Data.Monoid
Compiling Data.Newtype
Compiling Control.Monad.Eff
Compiling Data.Monoid.Multiplicative
Compiling Data.Monoid.Dual
Compiling Data.Monoid.Endo
Compiling Control.Monad.Eff.Console
Compiling Data.Monoid.Conj
Compiling Data.Monoid.Alternate

Compiling Control.Monad.Eff.Uncurried
Compiling Data.Monoid.Disj
Compiling Control.Monad.Eff.Class
Compiling Data.Monoid.Additive
Compiling Control.Monad.Eff.Unsafe
Compiling Main
Compiling PSCI.Support
* Build successful.

9.pulp test コマンドでテスト実行。

pulp test
* Building project in /home/haiju/workspace/hello-pur
Compiling Test.Main
* Build successful.
* Running tests...
You should add some tests.
* Tests OK.

10.purescriptのREPLのpsciを起動してみる。

pulp repl
Compiling Data.NaturalTransformation
Compiling Data.Boolean
Compiling Control.Semigroupoid
Compiling Data.Show
Compiling Control.Category
Compiling Data.Void
Compiling Data.Unit
Compiling Data.Function
Compiling Data.HeytingAlgebra
Compiling Control.Lazy
Compiling Data.Semigroup
Compiling Data.Eq
Compiling Data.Semiring
Compiling Data.Functor
Compiling Data.BooleanAlgebra
Compiling Data.Ordering
Compiling Data.Ring
Compiling Control.Alt
Compiling Data.Functor.Invariant
Compiling Control.Extend
Compiling Control.Apply
Compiling Control.Plus
Compiling Data.CommutativeRing
Compiling Data.Ord.Unsafe
Compiling Data.Ord
Compiling Control.Comonad
Compiling Data.EuclideanRing
Compiling Control.Applicative
Compiling Data.DivisionRing
Compiling Data.Field
Compiling Control.Alternative
Compiling Control.Bind
Compiling Data.Bounded
Compiling Control.Monad
Compiling Control.MonadZero
Compiling Prelude
Compiling Control.MonadPlus
Compiling Data.Newtype
Compiling Data.Monoid
Compiling Control.Monad.Eff
Compiling Data.Monoid.Additive
Compiling Data.Monoid.Dual
Compiling Control.Monad.Eff.Class
Compiling Data.Monoid.Alternate

Compiling Data.Monoid.Endo
Compiling Control.Monad.Eff.Unsafe
Compiling Data.Monoid.Disj
Compiling Data.Monoid.Multiplicative
Compiling Data.Monoid.Conj
Compiling Control.Monad.Eff.Uncurried
Compiling Control.Monad.Eff.Console
Compiling Test.Main
Compiling Main
Compiling PSCI.Support
PSCi, version 0.11.7
Type :? for help
 
import Prelude
>
>
See ya!

 ※ターミナルに戻るには「Ctrl + d」

11.サンプルプロジェクトの中身を見てみる。

 % vim ~/hello-urs/src/Main.purs

module Main where

import Prelude
import Control.Monad.Eff (Eff)
import Control.Monad.Eff.Console (CONSOLE, log)
 
main :: forall e. Eff (console :: CONSOLE | e) Unit
main = do
log "Hello sailor!"  ---  ここを"Hello, world!"と変更する

12.pulp runコマンドでサンプルプロジェクトの実行。

pulp run
* Building project in /home/haiju/workspace/hello-pur
* Build successful.
Hello, world!

 ※実行はせずにビルドのみ済ませたい場合は、pulp buildコマンド。

13.テスト実行。

  ※pulp testコマンドを実行すると、src/Main.pursのMainモジュール

  ではなく、test/Main.pursのTest.Mainモジュールが実行される。

% pulp test
* Building project in /home/haiju/workspace/hello-pur
* Build successful.
* Running tests...
You should add some tests.
* Tests OK.

[参考サイト]

qiita.com

documentation/Getting-Started.md at master · purescript/documentation · GitHub

purescript/INSTALL.md at master · purescript/purescript · GitHub