良い本とあちこちで紹介されている、プログラミングにまったく触れたことがない人向けの入門書を買って読んでみる。
これはお茶の水女子大の理学部情報学科の教科書として書かれた本で、初々しい女子大生たちがこの世界に初めて関わる時に 最初に読むという本である。それをこの道20年近いオサーンである私がなんで手にしたかといえば、 若者に対する教育に興味があることもさることながら、この本が
OCamlの本
だからである。関数型が苦手で、勉強したいとは思っているけどもなかなか身につかない私なのである。
この本は初めてのプログラミング言語としてOCamlを女子大生に教えようとする(そして、ある程度、実績を残している)恐るべき本らしい。ほえー・・・。
というわけで、まずはインストールをしなければなるまい。
https://ocaml.org/docs/install.html を見ると、homebrewで良いとある。一緒にいれるOPAMはOCamlのPackage Managerだそうな。
大人のたしなみとして、まずbrew update
はした上で、brew install
する
> brew install ocaml Updating Homebrew... ==> Downloading https://homebrew.bintray.com/bottles/ocaml-4.07.1.high_sierra.bottle.tar.gz ==> Downloading from https://akamai.bintray.com/d1/d18ce3b54b85ffe8a6ea32c6079fbdfcfdd4cda852b32919a ######################################################################## 100.0% ==> Pouring ocaml-4.07.1.high_sierra.bottle.tar.gz 🍺 /usr/local/Cellar/ocaml/4.07.1: 2,113 files, 237.2MB > brew install opam Updating Homebrew... ==> Downloading https://homebrew.bintray.com/bottles/opam-2.0.4.high_sierra.bottle.tar.gz ==> Downloading from https://akamai.bintray.com/36/36febb1c4215e029892bda1fee4ea0414f6694328d286b19f ######################################################################## 100.0% ==> Pouring opam-2.0.4.high_sierra.bottle.tar.gz ==> Caveats OPAM uses ~/.opam by default for its package database, so you need to initialize it first by running: $ opam init Bash completion has been installed to: /usr/local/etc/bash_completion.d zsh completions have been installed to: /usr/local/share/zsh/site-functions ==> Summary 🍺 /usr/local/Cellar/opam/2.0.4: 48 files, 11.3MB
opam init
しろと書いているのでしてみる
> opam init [NOTE] Will configure from built-in defaults. Checking for available remotes: rsync and local, git. - you won't be able to use mercurial repositories unless you install the hg command on your system. - you won't be able to use darcs repositories unless you install the darcs command on your system. <><> Fetching repository information ><><><><><><><><><><><><><><><><><><><> 🐫 [default] Initialised <><> Required setup - please read <><><><><><><><><><><><><><><><><><><><><> 🐫 In normal operation, opam only alters files within ~/.opam. However, to best integrate with your system, some environment variables should be set. If you allow it to, this initialisation step will update your fish configuration by adding the following line to ~/.config/fish/config.fish: source /Users/tambara/.opam/opam-init/init.fish > /dev/null 2> /dev/null; or true Otherwise, every time you want to access your opam installation, you will need to run: eval $(opam env) You can always re-run this setup with 'opam init' later. Do you want opam to modify ~/.config/fish/config.fish? [N/y/f] (default is 'no', use 'f' to choose a different file) y A hook can be added to opam's init scripts to ensure that the shell remains in sync with the opam environment when they are loaded. Set that up? [y/N] y User configuration: Updating ~/.config/fish/config.fish. <><> Creating initial switch (ocaml-system>=4.02.3) <><><><><><><><><><><><> 🐫 <><> Gathering sources ><><><><><><><><><><><><><><><><><><><><><><><><><><> 🐫 <><> Processing actions <><><><><><><><><><><><><><><><><><><><><><><><><><> 🐫 ∗ installed base-bigarray.base ∗ installed base-threads.base ∗ installed base-unix.base ∗ installed ocaml-system.4.07.1 ∗ installed ocaml-config.1 ∗ installed ocaml.4.07.1 Done. # Run eval (opam env) to update the current shell environment
fishまでサポートしてるみたい。私よりfishに詳しいだろうし、お任せする。
起動してみる
> ocaml OCaml version 4.07.1 # let a = 1;; val a : int = 1 # let s = "平成から令和";; val s : string = "平成から令和"
とりあえず、インタープリタは動いているし、日本語も大丈夫っぽい