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
{{ message }}
Repository navigation
Commit e72f4c1
Browse filesBrowse the repository at this point in the historyBrowse files
docs: state exceptions, comparers and range costs exactly in ADR 0001
- D6: each function throws what the FSharp.Core function of the
mirrored module throws (`Array` for `FlatList`, `List` for the
sequence-like modules, `Map`, `Set`), with a measured table: `take 0`
is valid, `skip -1` and `truncate -1` count as 0, `item` throws
`IndexOutOfRangeException` for `Array` and `ArgumentException` for
`List`, and so on. `ParamName` and the extras are the deliberate
deviations.
- D8: the contract tests take the expected exception from that same
FSharp.Core function on the same input.
- D5: a transformation keeps each comparer whose type does not change;
`map` and `choose` give the result the default comparer of the new
type. The defaults are `EqualityComparer<'T>.Default` for hash-based
collections and F# generic comparison for sorted ones.
- D5: `ImmutableList.GetRange` builds a new tree; its cost grows with the
length of the range (48 B per element), not with log n.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Removed from the started branch: `iter3`/`iteri3`/`exists3`/`forall3`/`mapi3`/`foldBack3`, `foldi`/`foldi2`/`foldBacki`/
64
65
`foldBacki2`, `findDup`/`findDupBy`, `pickBack`/`tryPickBack`/`chooseBack`, the `From`/`Range` variants of `index*`/
@@ -157,21 +158,52 @@ Consequences for the types: `FlatList` range operations (`take`, `skip`, `trunca
157
158
`chunkBySize`, `windowed`) copy the selected elements. An `ImmutableArray` is a single array reference without an offset or a
158
159
length, so `Slice` allocates and copies unless the range is empty (`Empty` is returned) or covers the whole input (the input
159
160
itself is returned); zero-copy views of a range are available through `asSpan`/`asMemory` and the span's own `Slice`.
160
-
`IndexedList` ranges use `GetRange` (O(log n)). `Stack` reverses only in its constructors: the BCL `ImmutableStack.Create`
161
-
and `CreateRange` push in order and leave the last element on top, so `ofSeq`, `ofArray`, `ofList`, `ofReadOnlySpan` and
162
-
`ofSpan` push from the end instead (`ofSeq [1; 2; 3]` has `1` on top), and every transformation snapshots top-to-bottom,
163
-
applies `Array.*` and rebuilds the same way. `Queue.length`/`Stack.length` are O(n) and say so; map and set transformations preserve the comparers of the
164
-
input (`CreateRange(keyComparer, valueComparer, …)`, `CreateBuilder(keyComparer)`); interface modules preserve the caller's
165
-
implementation through `Clear()` plus `AddRange`/`Enqueue`/`Push`; `FrozenMap.keys`/`values` and `FrozenSet.toFlatList`
166
-
return the underlying `ImmutableArray` in O(1).
161
+
`IndexedList` ranges use `GetRange`, which builds a new tree from the selected elements: its work and allocation grow with
162
+
the length of the range (48 B per element in a measurement), not with log n. `Stack` reverses only in its constructors:
163
+
the BCL `ImmutableStack.Create` and `CreateRange` push in order and leave the last element on top, so `ofSeq`, `ofArray`,
164
+
`ofList`, `ofReadOnlySpan` and `ofSpan` push from the end instead (`ofSeq [1; 2; 3]` has `1` on top), and every
165
+
transformation snapshots top-to-bottom, applies `Array.*` and rebuilds the same way. `Queue.length`/`Stack.length` are O(n) and say so. Interface modules keep the
166
+
caller's implementation in same-type transformations through `Clear()` plus `AddRange`/`Enqueue`/`Push`.
167
+
`FrozenMap.keys`/`values` and `FrozenSet.toFlatList` return the underlying `ImmutableArray` in O(1).
168
+
169
+
**Comparers.** A transformation keeps each comparer whose type does not change. The key comparer of a map is always kept,
170
+
because the keys keep their type (`CreateRange(keyComparer, …)`, `CreateBuilder(keyComparer)`). The value comparer of a map
171
+
and the element comparer of a set are kept by `filter`, `partition` and set algebra. `map` and `choose` change the value or
172
+
element type, so their result gets the default comparer of the new type. The interface modules cannot read the comparers
173
+
of their input, so their type-changing transformations return concrete collections with default comparers. The defaults,
174
+
which creation functions without a comparer argument also use, are `EqualityComparer<'T>.Default` for hash-based
175
+
collections, as ADR 0002 uses for equality, and the order of F# generic comparison
176
+
(`LanguagePrimitives.FastGenericComparer<'T>`) for sorted collections. Thus `SortedSet<string>` is ordinal by default, as
177
+
F# `Set<string>` is.
167
178
168
179
### D6. Exceptions mirror FSharp.Core
169
180
170
-
Exception types and message texts follow FSharp.Core (`FSCore.resx`): `ArgumentException` for an empty input to `head`,
0 commit comments