mirror of
https://github.com/adambard/learnxinyminutes-docs.git
synced 2024-12-23 09:41:36 +00:00
Merge eeb513929b
into b03f9e0257
This commit is contained in:
commit
ca2852a1e5
@ -341,9 +341,9 @@ type animal =
|
|||||||
;;
|
;;
|
||||||
|
|
||||||
let cow =
|
let cow =
|
||||||
{ name: "cow";
|
{ name = "cow";
|
||||||
color: "black and white";
|
color = "black and white";
|
||||||
legs: 4;
|
legs = 4;
|
||||||
}
|
}
|
||||||
;;
|
;;
|
||||||
val cow : animal
|
val cow : animal
|
||||||
@ -488,7 +488,7 @@ filter (fun x -> x < 4) [3; 1; 4; 1; 5] ;; (* Gives [3; 1; 1]) *)
|
|||||||
(* However, you can create mutable polymorphic fields *)
|
(* However, you can create mutable polymorphic fields *)
|
||||||
type counter = { mutable num : int } ;;
|
type counter = { mutable num : int } ;;
|
||||||
|
|
||||||
let c = { num: 0 } ;;
|
let c = { num = 0 } ;;
|
||||||
c.num ;; (* Gives 0 *)
|
c.num ;; (* Gives 0 *)
|
||||||
c.num <- 1 ;; (* <- operator can set mutable record fields *)
|
c.num <- 1 ;; (* <- operator can set mutable record fields *)
|
||||||
c.num ;; (* Gives 1 *)
|
c.num ;; (* Gives 1 *)
|
||||||
|
Loading…
Reference in New Issue
Block a user