« Premiers pas en OCaml/Structures de données » : différence entre les versions

Contenu supprimé Contenu ajouté
Ligne 171 :
=== Les variants comme constructeurs ===
 
Les variants peuvent également être utilisés pour regrouper des types de données hétérogènes.
''à écrire''
 
Définition :
 
<source lang="ocaml">
# type points =
| Point2D_real of float * float
| Point3D_real of float * float * float
| Point2D_discrete of int * int
| Point3D_discrete of int * int * int
;;
type points =
Point2D_real of float * float
| Point3D_real of float * float * float
| Point2D_discrete of int * int
| Point3D_discrete of int * int * int
</source>
 
Utilisation :
 
<source lang="ocaml">
# Point2D_discrete (3, 4) ;;
- : points = Point2D_discrete (3, 4)
</source>
 
== Les enregistrements ==