mirror of
https://github.com/Fechin/reference.git
synced 2026-11-25 07:04:42 +03:00
Update ocaml.md
This commit is contained in:
1 parent
b49a98fd63
commit
da66798b3b
1 file changed
+59
-2
+59
-2
@@ -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
|
||||
```
|
||||
|
||||
|
||||
Reference in new issue
Block a user