LoginSignup
4

More than 5 years have passed since last update.

PureScript の Interactive mode (`psci`) を動かしてみる

Last updated at Posted at 2016-12-01

この記事は (bouzuya) PureScript Advent Calendar 2016 の 2 日目。 (bouzuya) PureScript Advent Calendar 2016 は bouzuya の PureScript 学習の記録だ。

概要

今日は PureScriptpsci を試してみる。

環境は前回の続きを想定している。

psci をまず動かしてみる

npm i -D purescript のあと $(npm bin)/psci すると次のようなエラーが表示される。

$ $(npm bin)/psci
PSCi requires the psci-support package to be installed.
You can install it using Bower as follows:

  bower i purescript-psci-support --save-dev

Or using psc-package:

  psc-package install psci-support

For help getting started, visit http://wiki.purescript.org/PSCi

bowerpsc-packagepurescript-psci-support をインストールしろということらしい。

bowerpurescript-psci-support をインストールしてみる

前回は NPM で PureScript をインストールしたので、今回はその延長として NPM で bower をインストールして使っていく。まずは NPM で bower をインストールする。

$ npm install -D bower

npm install --global しない理由は前回説明したとおりだ。

$ $(npm bin)/bower --version
1.8.0

bower@1.8.0 がインストールされたようだ。次は bower のパッケージを管理するための bower.json を生成する。

$ $(npm bin)/bower init

private: true くらいで、ほかは適当に ENTER で流す。

bower.json
{
  "name": "project1",
  "description": "",
  "main": "index.js",
  "authors": [
    "bouzuya <m@bouzuya.net> (http://bouzuya.net/)"
  ],
  "license": "MIT",
  "homepage": "",
  "private": true,
  "ignore": [
    "**/.*",
    "node_modules",
    "bower_components",
    "test",
    "tests"
  ]
}

次は purescript-psci-support をインストールしていく。

$ $(npm bin)/bower install -D purescript-psci-support
$ $(npm bin)/bower list
project1 /Users/bouzuya/project1
└─┬ purescript-psci-support#2.0.0
  └─┬ purescript-console#2.0.0
    └─┬ purescript-eff#2.0.0
      └── purescript-prelude#2.1.0

purescript-psci-support#2.0.0 がインストールされたようだ。

改めて psci を動かしてみる

$ $(npm bin)/psci
PSCi requires the psci-support package to be installed.
You can install it using Bower as follows:

  bower i purescript-psci-support --save-dev

Or using psc-package:

  psc-package install psci-support

For help getting started, visit http://wiki.purescript.org/PSCi

変わらないぞ……。上記の出力にもある Wiki によると、次のような引数が必要らしい。

psci 'src/**/*.purs' 'bower_components/purescript-*/src/**/*.purs'

読み込む PureScript ファイル (*.purs) を指定しないといけないようだ。pulp を推奨しているようなので、別途そちらに進む必要がありそうだ。

$ $(npm bin)/psci 'bower_components/purescript-*/src/**/*.purs'
PSCi, version 0.10.2
Type :? for help

>

動いた。

いろいろ入力してみる

$ $(npm bin)/psci 'bower_components/purescript-*/src/**/*.purs'
> 1
1

> 1 + 2
Error found:
in module $PSCI
at  line 1, column 1 - line 1, column 5

  Unknown operator (+)


See https://github.com/purescript/purescript/wiki/Error-Code-UnknownName for more information,
or to contribute content related to this error.


> "Hello, World!"
"Hello, World!"

> let x = 123
> x
123

> let f x = x
> f x
123

はい。足し算 ((+)) さえできない。前回も書いたとおり、Hello, World! なんてできるわけがない。

ヘルプをみてみる

$ $(npm bin)/psci 'bower_components/purescript-*/src/**/*.purs'
> :?
The following commands are available:

    :?                        Show this help menu
    :quit                     Quit PSCi
    :reset                    Discard all imported modules and declared bindings
    :browse      <module>     See all functions in <module>
    :type        <expr>       Show the type of <expr>
    :kind        <type>       Show the kind of <type>
    :show        import       Show all imported modules
    :show        loaded       Show all loaded modules
    :paste       paste        Enter multiple lines, terminated by ^D

Further information is available on the PureScript wiki:
 --> https://github.com/purescript/purescript/wiki/psci

> :q
See ya!

:quit:q と短く打っても通った。

$ $(npm bin)/psci 'bower_components/purescript-*/src/**/*.purs'
> :t 123
Int

> :t "Hello"
String

> :t 1.0
Number

> :t [123]
Array Int

> :t { foo: 123 }
{ foo :: Int
}

:type で型を見てみる。ふむふむ。ほかはまだモジュールを読み込んだりしていないので、いまいちだ。

……とりあえずはこんなところか。

次回以降の TODO

  • pulp を試す
  • psc-package を試す
  • psci の未使用コマンドを試す

あたりが不明点か。もうすこしドキュメントに触れたほうが良さそうだ。

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4