| 日時: | 2016-11-06 |
|---|---|
| 作: | @voluntas |
| バージョン: | 0.0.0 |
| URL: | https://voluntas.githu.io/ |
突っ込みは Twitter @voluntas まで。
自社の CTO と技術顧問 が OCaml ハカーなのに、覚えないのは損というのが動機。
普段 Erlang/OTP しかほとんど書いていないので、ここいらでいっちょ覚えてみるかと。
目標としてはまずはコマンドライン系のツール、あとは小さなネットワーク・サーバという感じ。
本番導入はあまり考えていない、ちょっとしたツールを作るくらいに使えるようになると良い。 Python くらい手に馴染んでくれればありがたいところ。
とりあえず二冊を紙で購入した。
- Real World OCaml
- プログラミングの基礎
全ては opam から始まるということで、 opam をインストール。開発環境は Mac です。
まずは opam をいれる、そこからスタート
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
あとで
utop と core をいれる
https://github.com/diml/utop
utop は REPL ということなのでいれておく、また core というライブラリを使うらしいので、とりあえずいれておく。
$ opam install core utop
.ocamlinit ファイルに以下を追加しろと書いてあるので追加する。
~/.ocamlinit:
#use "topfind";; #thread;; #camlp4o;; #require "core.top";; #require "core.syntax";;
これは動かない
# 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 stringCore 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>