Premiers pas en OCaml/Annexe/Synthèse

Leçons de niveau 14
Une page de Wikiversité, la communauté pédagogique libre.
Synthèse
Image logo représentative de la faculté
Annexe 1
Leçon : Premiers pas en OCaml

Annexe de niveau 14.

Précédent :Sommaire
En raison de limitations techniques, la typographie souhaitable du titre, « Annexe : Synthèse
Premiers pas en OCaml/Annexe/Synthèse
 », n'a pu être restituée correctement ci-dessus.




Types primitifs[modifier | modifier le wikicode]

Type Signification Représentation Fait Exemples Non Non Erreurs
int Entier [1]
ou
[2]
-42
1337
0x539
0o2471
0b10100111001
0o8 : non octal
1. : mauvais type
1073741824 : dépassement entier
float Réel, flottant Entre et -1.
137
0 : mauvais type
0,42 : pas de virgule
0x1. : impossible
char Caractère Entre '\000' et '\255' 'c'
'\n'
'0'
'cd' : trop de caractères
string Chaîne de caractères Tableau de mots de
4 octets [1] ou
​ 8 octets [2]
"chaine de caractères"
"c"
"1337"
bool Booléen true
false
unit Unité ()

Précision des réels[modifier | modifier le wikicode]

Intervalle Précision des réels

Opérations arithmétiques[modifier | modifier le wikicode]

Opération Fonction Type
Addition +
 int -> int -> int
+.
float -> float -> float
Soustraction -
 int -> int -> int
-.
float -> float -> float
Multiplication *
 int -> int -> int
*.
float -> float -> float
Division euclidienne /
 int -> int -> int
Division exacte /.
float -> float -> float
Modulo mod
 int -> int -> int
mod_float
 float -> float -> float
Racine carrée sqrt
float -> float
Puissance **
float -> float -> float
Exponentielle exp
float -> float
Logarithme népérien log
float -> float
Logarithme log10
float -> float
Cosinus cos
float -> float
Sinus sin
float -> float
Tangente tan
float -> float
Arc cosinus acos
float -> float
Arc sinus asin
float -> float
Arc tangente atan
float -> float

Fonctions utilitaires[modifier | modifier le wikicode]

Nom Fonction Type
Conversion int_of_float
float -> int
float_of_int
int -> float
(float)
int -> float
int_of_char
char -> int
char_of_int
int -> char
string_of_bool
bool -> string
bool_of_string
string -> bool
int_of_string
string -> int
string_of_int
int -> string
float_of_string
string -> float
string_of_float
float -> string
Lecture read_line
unit -> string
read_int
unit -> int
read_float
unit -> float
Affichage print_char
char -> unit
print_int
int -> unit
print_float
float -> unit
print_string
string -> unit
print_endline
string -> unit
print_newline
unit -> unit
Concaténation ^
string -> string -> string
Argument Sys.argv.(int)
string
Sys.argv
string array

Structures de données[modifier | modifier le wikicode]

Structure Type Exemple
Liste
'a list
[1; 2; 3]
Tableau
'a array
[| 1; 2; 3 |]
Tuple
int * char
(2, 'e')
Variant
type vt = A | B of int
A
B 6
Enregistrements
type person = { name:string; age:int }
{ name="Alphonse"; age=32 }
someone.name