Commits

camlspotter committed d684c3d

changed syntax {<..>} => {|..|}

  • Participants
  • Parent commits 7451f8f

Comments (0)

Files changed (3)

 
 Record creation::
 
-   {< field = value; ... >}
+   {| field = value; ... |}
 
 Field access::
 
 
 For simplicity, the poly-record is immutable by itself. If you want to have mutable fields, you must use reference cells explicitly. The field access syntax provides a sugar to update the reference::
 
-   let r = {< x = 1; y = ref None >}   (* x and y are immutable, but y is a ref which is mutable *)
+   let r = {| x = 1; y = ref None |}   (* x and y are immutable, but y is a ref which is mutable *)
    let () = r..y <- Some 2             (* update the ref at y *)
    let () = assert (!(r..y) = Some 2)  (* Accessing the ref content is a bit lousy... *)
 
 
 The type system can forget fields using coercion::
 
-   let r = {< x = 1; y = None >}
+   let r = {| x = 1; y = None |}
    let r' = (r  :>  < x : int > Polyrecord.t)  (* forget about y *)
 
 Limitations

File pa_polyrecord.ml

     ;
 
   expr: LEVEL "simple"
-    [ [ "{<"; lel = TRY [lel = xlabel_expr_list; ">}" -> lel] ->
+    [ [ "{|"; lel = TRY [lel = xlabel_expr_list; "|}" -> lel] ->
 
           let bindings = List.map (fun (l, e) -> <:binding< $lid:l$ = $e$ >>) lel in
           let meths = List.map (fun (l, _) -> 
                   let _o = ($o$ : '$var$) in
                   (Polyrecord.create $list$ : '$var$ Polyrecord.t) >>
 
-      | "{<"; e = TRY [e = expr LEVEL "."; "with" -> e]; lel = xlabel_expr_list; ">}" ->
+      | "{|"; e = TRY [e = expr LEVEL "."; "with" -> e]; lel = xlabel_expr_list; "|}" ->
       
           let bindings = List.map (fun (l, e) -> <:binding< $lid:l$ = $e$ >>) lel in
           let meths = List.map (fun (l, _) -> <:expr< o#$l$ = $lid:l$ >>) lel in
 (* Record creation 
 
-   {< .. >} is a record but all the fields are immutable.
+   {| .. |} is a record but all the fields are immutable.
    If you want to have mutability, use ref explicitly.
 *)
 
-let r = {< x = 1; y = ref None >}
+let r = {| x = 1; y = ref None |}
 
 (* Record access
 
 
 (* Making a copy with 
 
-   {< r with bindings >}
+   {| r with bindings |}
 
 *)
 
-let r2 = {< r with x = 3 >}
+let r2 = {| r with x = 3 |}
 
 (* You cannot add fields at copy. :-(
 
-   let r2 = {< r with z = 3 >} 
+   let r2 = {| r with z = 3 |} 
 
 *)
 
 
 (* Nicely prevents multi uses of a label
 
-  let strange = {< x = 1; x = 1.0 >}
+  let strange = {| x = 1; x = 1.0 |}
 
 *)
 
 (* No pattern matching 
 
    let () = match r with
-     | {< x = 1 >} -> true
+     | {| x = 1 |} -> true
      | _ -> false
 
 *)