11
22## Runtime representation
33
4- Below is a description of how OCaml values are encoded in JavaScript,
5- the *internal* description means **users should not rely on its actual
4+ Below is a description of how OCaml values are encoded in JavaScript,
5+ the *internal* description means **users should not rely on its actual
66encoding (and it is subject to change)** . We recommend that you write
77setter/getter functions to manipulate safely OCaml values from JavaScript.
88
@@ -80,7 +80,7 @@ Simple Variants: (Variants with only one non-nullary constructor)
8080[source,ocaml]
8181--------------
8282type tree =
83- \| Leaf
83+ \| Leaf
8484 \| Node of int * tree * tree
8585(* Leaf --> 0 *)
8686(* Node(a,b,c) --> [a,b,c]*)
@@ -90,7 +90,7 @@ Complex Variants: (Variants with more than one non-nullary constructor)
9090
9191[source,ocaml]
9292-------------
93- type u =
93+ type u =
9494 \| A of string
9595 \| B of int
9696(* A a --> [a].tag=0 -- tag 0 assignment is optional *)
@@ -123,29 +123,22 @@ For example:
123123val Js.to_bool: Js.boolean -> bool
124124-----
125125
126- | `'a Js.Null.t` a| either `'a` or `null`
126+ | `'a Js.Null.t` a| either `'a` or `null`. `Js.Null.empty` represents `null` too.
127127
128128[source,ocaml]
129129.Js.Null module
130130--------------
131131val to_opt : 'a t -> 'a option
132-
132+ val from_opt : 'a option -> 'a t
133133val return : 'a -> 'a t
134-
135134val test : 'a t -> bool
136135--------------
137136
138- | `'a Js.Undefined.t` a| either `'a` or `undefined`
139-
140- [source,ocaml]
141- .Js.Undefined
142- --------------
143- val to_opt : 'a t -> 'a option
144- val return : 'a -> 'a t
145- val test : 'a t -> bool
146- --------------
137+ | `'a Js.Undefined.t` a| either `'a` or `undefined`.
138+ Same operations as `'a Js.Null.t`.
147139
148- |`'a Js.Null_undefined.t` a| either `'a`, `null` or `undef`
140+ |`'a Js.Null_undefined.t` a| either `'a`, `null` or `undef`.
141+ Same operations as `'a Js.Null.t`.
149142|==============
150143
151144NOTE: `Js.to_opt` is optimized when the `option` is not escaped
0 commit comments