OCamlの環境構築
#OCaml
OCaml環境を構築した時のメモ。
以下を見ながらインストールを行う。
https://ocaml.org/docs/up-and-running
インストール
Macの場合
$ brew install opam
$ opam init
$ opam install dune utop ocaml-lsp-server ocamlformat
Ubuntuの場合
$ sudo apt update
$ sudo apt install opam
$ opam init
$ opam install dune utop ocaml-lsp-server
opam init の中で .zshrc へ以下が追加される
code:~/.zshrc
# opam configuration
! -r /Users/thata/.opam/opam-init/init.zsh || source /Users/thata/.opam/opam-init/init.zsh > /dev/null 2> /dev/null
~/.opam の下にOCamlがインストールされている。
code:sh
$ which ocaml
/Users/thata/.opam/default/bin/ocaml
対話環境 utop
utopコマンドで起動。
code:sh
$ utop
https://gyazo.com/cc5d94f9a403281cb7fe19b457a1a1f0
Dune Build System
Duneを使ったサンプルプログラム。
code:sh
$ cd ~/src
$ dune init proj helloworld
$ cd helloworld
$ dune build
$ dune exec helloworld
Hello, World!
生成された実行ファイルの本体はこちら。
code:sh
$ ./_build/default/bin/main.exe
Hello, World!
Duneの詳細はこちら
https://dune.readthedocs.io/en/stable/
VSCodeセットアップ
以下の拡張をインストールする
OCaml Platform
参考
京都大学工学部専門科目「プログラミング言語処理系」講義資料
https://kuis-isle3sw.github.io/IoPLMaterials/
Get Up and Running With OCaml
https://ocaml.org/docs/up-and-running