Update ocaml.md

This commit is contained in:
Grant Smith authored and GitHub committed 2024-08-07 13:38:56 -06:00
1 parent b49a98fd63
commit da66798b3b
1 file changed
+59 -2
+59 -2
View File
@@ -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
```