Dumping ground for OCAML
Most of this taken from running through the Dan Grossman's tutorial from Washington University, the offical OCAML website and from the learn-x-in-y-minutes website.
(Mostly tested with the online Try OCAML website, but should also work fine with the installed version.)
- comment_examples.ml
- output_examples.ml
- math_examples.ml
- boolean_examples.ml
- string_examples.ml
- explicit_type_examples.ml
- local_variable_examples.ml
- conditional_examples.ml
- loop_examples.ml
- recursion_examples.ml
- anonymous_function_examples.ml
- higher_order_function_examples.ml
- closure_examples.ml
- tuple_examples.ml
- structure_examples.ml
- pattern_matching_examples.ml
- enum_examples.ml
- list_examples.ml
- dictionary_examples.ml
- mutable_examples.ml
- exception_examples.ml
- circular_reference.ml
After a lot of playing around, managed to get Rock, Paper, Scissors working..
Compiling instructions taken from RIP Tutorial website.
Note this section makes use of hello.ml
Use ocamlc
to compile to bytecode:
jdorr@DESKTOP-MF9T345 /cygdrive/c/Users/jdorr/Desktop/Dev/PegSolitaire/src
$ cat hello.ml
let () = print_endline "Hello World!"
jdorr@DESKTOP-MF9T345 /cygdrive/c/Users/jdorr/Desktop/Dev/PegSolitaire/src
$ ocamlc -o hello hello.ml
jdorr@DESKTOP-MF9T345 /cygdrive/c/Users/jdorr/Desktop/Dev/PegSolitaire/src
$ ./hello
Hello World!
Use ocamlopt
to compile to native:
jdorr@DESKTOP-MF9T345 /cygdrive/c/Users/jdorr/Desktop/Dev/PegSolitaire/src
$ cat hello.ml
jdorr@DESKTOP-MF9T345 /cygdrive/c/Users/jdorr/Desktop/Dev/PegSolitaire/src
$ ocamlopt -o hello hello.ml
jdorr@DESKTOP-MF9T345 /cygdrive/c/Users/jdorr/Desktop/Dev/PegSolitaire/src
$ ./hello
Hello World!
Note the resulting executable also runs fine from Windows:
C:\Users\jdorr\Desktop\Dev\PegSolitaire\src>hello.exe
Hello World!