mirror of
https://github.com/Fechin/reference.git
synced 2026-11-20 21:23:11 +03:00
1.1 KiB
1.1 KiB
title, date, background, tags, categories, intro, plugins
| title | date | background | tags | categories | intro | plugins | ||||
|---|---|---|---|---|---|---|---|---|---|---|
| Ocaml | 2024-08-06 00:00:00 | bg-[#eeeee4] |
|
|
The [Ocaml](https://www.ocaml.org/) cheat sheet is a one-page reference sheet for the Ocaml programming language. |
|
Getting Started
hello.ml
let () =
let message = "Hello, World!" in
Printf.printf "%s\n" message
Compile and Run
$ ocamlc -o hello.byte hello.ml
$ ./hello.byte
Build and Run with Dune
$ dune build hello.exe
$ _build/default/hello.exe
Comments
(* A single line comment *)
(* A multi-line comment
* where to explain
* something complex *)
Expressions and Primitive Types
(* an expression *)
50 * 50
(* int *)
5 + 5
(* float *)
3.14 +. 2.72
(* bool *)
let theTruth = true
let untrue = false
(* char *)
'a'
(* string *)
"a string"
Variables
(* data is immutable in ocaml *)
let x = "a string"
let y = 1
let z = [1;2;3]
Functions
let add_two_ints x y =
let sum = x + y in
sum