2017-06-30   ocaml 

OCamlメモ

https://twitter.com/kagamihr/status/880594087606312962

というOCaml推しのツイートをみたので、インストールだけはしてみることに。

brew install ocaml
brew install opam
$ ocaml
        OCaml version 4.04.2

# let sq x = x * x;;
val sq : int -> int = <fun>
# sq 10;;
- : int = 100
# sq (sq 3);;
- : int = 81
# ^D
# let fact n = if n <= 2 then n else n * fact(n-1);;
Error: Unbound value fact
# let rec fact n = if n <= 2 then n else n * fact(n-1);;
val fact : int -> int = <fun>
# fact 3;;
- : int = 6
# fact 10;;
- : int = 3628800
# let s = 12 :: 34 :: 56 :: [] ;;
val s : int list = [12; 34; 56]
# let t = 12::34::56::[];;
val t : int list = [12; 34; 56]
# let u = [12;34;56];;
val u : int list = [12; 34; 56]
# s;;
- : int list = [12; 34; 56]
# t;;
- : int list = [12; 34; 56]
# u;;
- : int list = [12; 34; 56]
# s = t;;
- : bool = true
# t = u;;
- : bool = true

 2017-06-30   ocaml