learnxinyminutes-docs icon indicating copy to clipboard operation
learnxinyminutes-docs copied to clipboard

Collection Instanciation Error : OCaml

Open lokasku opened this issue 7 months ago • 1 comments

I noticed an error in the Records/A collection of values with named fields chapter when instantiating cow variable:

type animal = 
   {
      name: string;
      color: string;
      legs: int;
   }
;;

let cow = 
   {  name: "cow";
      color: "black and white";
      legs: 4; 
   }
;;
val cow : animal

cow.name ;;
- : string = "cow"

This should be replaced by

type animal = 
   {
      name: string;
      color: string;
      legs: int;
   }
;;

let cow = 
   {  name = "cow";
      color = "black and white";
      legs = 4; 
   }
;;

(*
val cow : animal

cow.name ;;
- : string = "cow"
*)

lokasku avatar Jul 19 '24 11:07 lokasku