You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It is also found at the end of the file; this error is present throughout the file where assignment is done with : instead of =.
(*** Mutability ***)(* Records and variables are immutable: you cannot change where a variable points to *)(* However, you can create mutable polymorphic fields *)typecounter = { mutable num : int } ;;
let c = { num: 0 } ;;
c.num ;; (* Gives 0 *)
c.num <-1 ;; (* <- operator can set mutable record fields *)
c.num ;; (* Gives 1 *)(* OCaml's standard library provides a ref type to make single field mutability easier *)type'a ref = { mutable contents : 'a } ;;
let counter =ref0 ;;
!counter ;; (* ! operator returns x.contents *)
counter :=!counter +1 ;; (* := can be used to set contents *)
I noticed an error in the
Records/A collection of values with named fields
chapter when instantiatingcow
variable:This should be replaced by
The text was updated successfully, but these errors were encountered: