The unpac monorepo manager self-hosting as a monorepo using unpac
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Add documentation for constructing Iarray.t from array literals (#14397)

* add immutable array literal example to apidoc

* manual: add iarray to builtin type list

* manual: add floatarray to builtin type list

* manual: Iarray.t in type-based array literal disambiguation

authored by

am and committed by
GitHub
f8ea2c42 606d69b9

+52 -12
+3
Changes
··· 256 256 257 257 ### Manual and documentation: 258 258 259 + - #14397: Improve documentation of type-directed disambiguation of array 260 + literals (Alicia Michael, review by Olivier Nicole and Florian Angeletti) 261 + 259 262 - #14293: Improve documentation of Runtime_events.Timestamp (Raphaël Proust, 260 263 review by Gabriel Scherer) 261 264
+16
manual/src/library/builtin.etex
··· 82 82 \end{ocamldocdescription} 83 83 84 84 \begin{ocamldoccode} 85 + type 'a iarray 86 + \end{ocamldoccode} 87 + \index{iarray@\verb`iarray`} 88 + \begin{ocamldocdescription} 89 + The type of immutable arrays whose elements have type "'a". 90 + \end{ocamldocdescription} 91 + 92 + \begin{ocamldoccode} 93 + type floatarray 94 + \end{ocamldoccode} 95 + \index{floatarray@\verb`floatarray`} 96 + \begin{ocamldocdescription} 97 + The type of mutable arrays of floats with packed representation. 98 + \end{ocamldocdescription} 99 + 100 + \begin{ocamldoccode} 85 101 type 'a list = [] | :: of 'a * 'a list 86 102 \end{ocamldoccode} 87 103 \index{list@\verb`list`}
+12 -3
manual/src/refman/extensions/arrayliterals.etex
··· 4 4 (Introduced in OCaml 5.4) 5 5 6 6 Since OCaml 5.4, array literal syntax @"[|" e1 ';' e2 ';' ... ';' eN "|]"@ can 7 - be used to denote values of type "floatarray" as well as "'a array", both in 8 - expression and pattern positions. This syntax is also used to display 9 - "floatarray" values in the toplevel. 7 + be used to denote values of type "floatarray" or "'a Iarray.t" as well as "'a 8 + array", both in expression and pattern positions. This syntax is also used to 9 + display "floatarray" and "'a Iarray.t" values in the toplevel. 10 10 11 11 The compiler matches the expected type of the expression or pattern with the 12 12 type of the literal, in a manner analogous to the disambiguation of constructors ··· 21 21 let _ : floatarray = [|42.|];; 22 22 let _ = ([|42.|] : floatarray);; 23 23 let _ = Float.Array.length [|42.|];; 24 + \end{caml_example} 25 + 26 + Immutable arrays (here "int Iarray.t") can be constructed in exactly the same 27 + way: 28 + 29 + \begin{caml_example}{verbatim} 30 + let _ : _ Iarray.t = [|42|];; 31 + let _ = ([|42|] : _ Iarray.t );; 32 + let _ = Iarray.length [|42|];; 24 33 \end{caml_example} 25 34 26 35 The same disambiguation mechanism is used for array literals appearing in
+21 -9
stdlib/iarray.mli
··· 15 15 (* *) 16 16 (**************************************************************************) 17 17 18 - open! Stdlib 18 + (** Immutable array operations. 19 19 20 - (** Operations on immutable arrays. This module mirrors the API of [Array], but 21 - omits functions that assume mutability; in addition to obviously mutating 22 - functions, it omits [copy] along with the functions [make], [create_float], 23 - and [make_matrix] that produce all-constant arrays. The exception is the 24 - sorting functions, which are given a copying API to replace the in-place 25 - one. 20 + This module mirrors the API of [Array], but omits functions that assume 21 + mutability; in addition to obviously mutating functions, it omits [copy] 22 + along with the functions [make], [create_float], and [make_matrix] that 23 + produce all-constant arrays. The exception is the sorting functions, which 24 + are given a copying API to replace the in-place one. 26 25 27 - @since 5.4 28 - *) 26 + Immutable arrays can be constructed from array literals by type-based 27 + disambiguation similar to that used for record fields. For example, when 28 + assigning to a type-annotated binding or parameter binding, or by directly 29 + type-annotating the literal. 30 + 31 + {[ 32 + let a : _ Iarray.t = [|1;2;3|] 33 + let b = let f (a : _ Iarray.t) = a in 34 + f [|1;2;3|] 35 + let c = ([|1;2;3|] : _ Iarray.t) 36 + ]} 37 + 38 + @since 5.4 *) 39 + 40 + open! Stdlib 29 41 30 42 type +'a t = 'a iarray 31 43 (** An alias for the type of immutable arrays. *)