Standard ML(SML)をMacBookに入れる


1. brew installでインストール

There is also a Homebrew cask that wraps the 64-bit installation package. If you have homebrew installed, then you can run the following command to install SML/NJ:

% brew cask install smlnj

なお、brew cask installは、現在はbrew install --caskに変わっている。

Terminal
electron@diynoMacBook-Pro ~ % brew install --cask smlnj
==> Caveats
To use smlnj, you may need to add the /usr/local/smlnj/bin directory
to your PATH environment variable, e.g. (for Bash shell):
  export PATH=/usr/local/smlnj/bin:"$PATH"

==> Downloading http://smlnj.cs.uchicago.edu/dist/working/110.99.2/smlnj-amd64-110.99.2.pkg
######################################################################## 100.0%
==> Installing Cask smlnj
==> Running installer for smlnj; your password may be necessary.
Package installers may write to any location; options such as `--appdir` are ignored.
Password:
installer: Package name is SML/NJ Version 110.99.2
installer: Installing at base path /
installer: The install was successful.
🍺  smlnj was successfully installed!
electron@diynoMacBook-Pro ~ % 

2. REPL(対話型インタプリタ)の動作確認

smlが認識されない。

Terminal
electron@diynoMacBook-Pro ~ % sml
zsh: command not found: sml
electron@diynoMacBook-Pro ~ % smnnj
zsh: command not found: smnnj
electron@diynoMacBook-Pro ~ % 

インストールに成功したとき、次のメッセージが表示されていた。

To use smlnj, you may need to add the /usr/local/smlnj/bin directory
to your PATH environment variable, e.g. (for Bash shell):
  export PATH=/usr/local/smlnj/bin:"$PATH"

カレント・ディレクトリを: /usr/local/smlnj/bin*に移動してから、smlと叩く。

Terminal
electron@diynoMacBook-Pro ~ % ls /usr/local/smlnj/bin
asdlgen     ml-antlr    ml-burg     ml-makedepend   ml-yacc
heap2exec   ml-build    ml-lex      ml-ulex     sml
electron@diynoMacBook-Pro ~ % 
Terminal
electron@diynoMacBook-Pro ~ % cd /usr/local/smlnj/bin
Terminal
electron@diynoMacBook-Pro bin % sml
zsh: command not found: sml
electron@diynoMacBook-Pro bin %

./smlで認識される。

Terminal
electron@diynoMacBook-Pro bin % ./sml
Standard ML of New Jersey (64-bit) v110.99.2 [built: Thu Sep 23 13:44:44 2021]
- 7 + 5;
val it = 12 : int
- 7 + 5 - 3
= ;
val it = 9 : int
- 7 + 5 - 3;
val it = 9 : int
-

3. REPLから抜ける

exitは、OS.Process.exit(OS.Process.success);を実行する。

Terminal
-  OS.Process.exit(OS.Process.success);
[autoloading]
[library $SMLNJ-BASIS/basis.cm is stable]
[library $SMLNJ-BASIS/(basis.cm):basis-common.cm is stable]
[autoloading done]
stdIn:5.2-5.37 Warning: type vars not generalized because of
   value restriction are instantiated to dummy types (X1,X2,...)
electron@diynoMacBook-Pro bin %