From da66798b3b1e6e5f814f9f7e62c749517d89a0aa Mon Sep 17 00:00:00 2001 From: Grant Smith <57376089+ggsmith842@users.noreply.github.com> Date: Wed, 7 Aug 2024 13:38:56 -0600 Subject: [PATCH] Update ocaml.md --- source/_posts/ocaml.md | 61 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 59 insertions(+), 2 deletions(-) diff --git a/source/_posts/ocaml.md b/source/_posts/ocaml.md index fa5adb8..6479166 100644 --- a/source/_posts/ocaml.md +++ b/source/_posts/ocaml.md @@ -22,9 +22,66 @@ let () = Printf.printf "%s\n" message ``` +Compile and Run + +```bash +$ ocamlc -o hello.byte hello.ml +$ ./hello.byte +``` + +Build and Run with Dune +```bash +$ dune build hello.exe +$ _build/default/hello.exe +``` + +### Comments +```ml +(* A single line comment *) + +(* A multi-line comment +* where to explain +* something complex *) +``` + +### Expressions and Primitive Types +```ml +(* an expression *) +50 * 50 + +(* int *) +5 + 5 + +(* float *) +3.14 +. 2.72 + +(* bool *) +let theTruth = true +let untrue = false + +(* char *) +'a' + +(* string *) +"a string" +``` + + + ### Varaibles ```ml - - +(* data is immutable in ocaml *) +let x = "a string" +let y = 1 +let z = [1;2;3] ``` + +### Functions +```ml +let add_two_ints x y = + let sum = x + y in + sum +``` + +