From bb0ca2f30de4bd0a8f041a52af178331e6237eec Mon Sep 17 00:00:00 2001 From: Pavel Tisnovsky Date: Tue, 12 Sep 2023 08:19:24 +0200 Subject: [PATCH] Type + type inference --- docs/ml.md | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/docs/ml.md b/docs/ml.md index ffb9b26..7aa02d6 100644 --- a/docs/ml.md +++ b/docs/ml.md @@ -142,6 +142,40 @@ let rec length([]) = 0 --- +### Types (very simple example) + +``` +type car = { + Color: string; + Model: string; + Manufacturer: string; + Year: int; +} + +let toyota :car = {Color="silver"; Model="Corolla"; Manufacturer="Toyota"; Year=1986};; + +Printf.printf "%A" toyota +``` + +--- + +### Type inference again + +``` +type car = { + Color: string; + Model: string; + Manufacturer: string; + Year: int; +} + +let toyota = {Color="silver"; Model="Corolla"; Manufacturer="Toyota"; Year=1986};; + +Printf.printf "%A" toyota +``` + +--- + ## Is it worth it? * OCaml (Jane Stree + others)