Ken Wakita (https://wakita.github.io/fp2018/)
Oct. 5, 2017
min-caml
implementationCore (Pervasives) (Plenty)
List (16) — list operations
Str (5) — regular expression
Arg (3) — parsing of command line arguments
min-caml
implementationList.map
)List.fold_left
)# List.fold_left (fun a x -> a + x) 0 [2; 3; 5; 7; 11] (* sum *);;
- : int = 28
# List.fold_left (fun a x -> a * x) 1 [2; 3; 5; 7; 11] (* product *);;
- : int = 2310
# List.fold_left (fun l x -> List.map (function l -> x :: l) ([] :: l))
[] [2; 3; 5; 7; 11];;
- : int list list = [[11]; [11; 7]; [11; 7; 5]; [11; 7; 5; 3]; [11; 7; 5; 3; 2]]
(* suffices of a list *)
ocamlopt
)Benchmark program
$ ocamlc -o tak tak.ml
$ time ./tak
Takeuchi(15, 8, 0) = ... 15
./tak 72.69s user 0.27s system 99% cpu 1:13.56 total
$ ocamlopt -o tak tak.ml
$ time ./tak
Takeuchi(15, 8, 0) = ... 15
./tak 6.46s user 0.04s system 98% cpu 6.564 total
x12 acceleration in ocamlopt!
ocamllex
)ocamlyacc
)