- 日時
2016-11-06
- 作
@voluntas
- バージョン
0.0.0
- URL
突っ込みは Twitter @voluntas まで。
自社の CTO と技術顧問 が OCaml ハカーなのに、覚えないのは損というのが動機。
普段 Erlang/OTP しかほとんど書いていないので、ここいらでいっちょ覚えてみるかと。
目標としてはまずはコマンドライン系のツール、あとは小さなネットワーク・サーバという感じ。
本番導入はあまり考えていない、ちょっとしたツールを作るくらいに使えるようになると良い。 Python くらい手に馴染んでくれればありがたいところ。
とりあえず二冊を紙で購入した。
- Real World OCaml
- プログラミングの基礎
全ては opam から始まるということで、 opam をインストール。開発環境は Mac です。
まずは opam をいれる、そこからスタート
https://opam.ocaml.org/doc/Install.html#OSX
MacPorts で opam をインストール:
$ sudo port install opam
OCaml は opam 経由で入れられる
間違って 4.02.3 を入れてしまった:
$ opam init --comp 4.02.3
最新版の 4.03.0 に切り替える:
$ opam switch 4.03.0
あとで
https://github.com/realworldocaml/book/wiki/Installation-Instructions
utop と core をいれる
utop は REPL ということなのでいれておく、また core というライブラリを使うらしいので、とりあえずいれておく。
$ opam install core utop
.ocamlinit ファイルに以下を追加しろと書いてあるので追加する。
https://github.com/realworldocaml/book/wiki/Installation-Instructions#setting-up-and-using-utop
~/.ocamlinit:
#use "topfind";;
#thread;;
#camlp4o;;
#require "core.top";;
#require "core.syntax";;
https://realworldocaml.org/v1/en/html/a-guided-tour.html
これは動かない
# let log_entry maybe_time message =
let time =
match maybe_time with
| Some x -> x
| None -> Time.now ()
in
Time.to_sec_string time ^ " -- " ^ message
;;
Error: This expression has type zone:Core.Zone.t -> string
but an expression was expected of type string
Core Time.to_sec_string の引数が変わったらしい
val to_sec_string : t -> string (* before *)
val to_sec_string : t -> zone:Zone.t -> string (* after *)
# let log_entry maybe_time message =
let time =
match maybe_time with
| Some x -> x
| None -> Time.now ()
in
Time.to_sec_string time ~zone:Core.Zone.local ^ " -- " ^ message
;;
val log_entry : Time.t option -> string -> string = <fun>
- OCaml 開発環境について ~ コンパイラに付属しない非公式ツールたち - Oh, you `re no (fun _ → more) <http://d.hatena.ne.jp/camlspotter/20121215/1355577547>_
- VimでOCamlを書くためにmerlinとocp-indentを設定する - Qiita