< Premiers pas en OCaml < Annexe



Types primitifs

TypeSignificationReprésentation ExemplesNon Non Erreurs
int Entier [1]
ou
[2]
-42
1337
0x539
0o2471
0b10100111001
0x8 : non octal
1. : mauvais type
1073741824 : dépassement entier
float Réel, flottantEntre et -1.
137
0 : mauvais type
0,42 : pas de virgule
0x1. : impossible
char CaractèreEntre '\000' et '\255''c'
'\n'
'0'
'cd' : trop de caractères
string Chaîne de caractèresTableau 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

IntervallePrécision des réels

Opérations arithmétiques

OpérationFonctionType
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éesqrt
float -> float
Puissance**
float -> float -> float
Exponentielleexp
float -> float
Logarithme népérienlog
float -> float
Logarithmelog10
float -> float
Cosinuscos
float -> float
Sinussin
float -> float
Tangentetan
float -> float
Arc cosinusacos
float -> float
Arc sinusasin
float -> float
Arc tangenteatan
float -> float

Fonctions utilitaires

NomFonctionType
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

StructureTypeExemple
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
Cet article est issu de Wikiversity. Le texte est sous licence Creative Commons - Attribution - Partage dans les Mêmes. Des conditions supplémentaires peuvent s'appliquer aux fichiers multimédias.