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
## Struct Representations for Partial Active Patterns
136
165
137
-
By default, partial active patterns return an `option` value, which will involve an allocation for the `Some` value on a successful match. Alternatively, you can use a [value option](value-options.md) as a return value through the use of the `Struct` attribute:
166
+
By default, if a partial active pattern returns an `option`, this will involve an allocation for the `Some` value on a successful match. To avoid it, you can use a [value option](value-options.md) as a return value through the use of the `Struct` attribute:
Copy file name to clipboardExpand all lines: docs/fsharp/language-reference/byrefs.md
+2Lines changed: 2 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -179,6 +179,8 @@ A "`byref`-like" struct in F# is a stack-bound value type. It is never allocated
179
179
* They cannot be static or instance members of a class or normal struct.
180
180
* They cannot be captured by any closure construct (`async` methods or lambda expressions).
181
181
* They cannot be used as a generic parameter.
182
+
* Starting with F# 9, this restriction is relaxed if the generic parameter is defined in C# using the allows ref struct anti-constraint. F# can instantiate such generics in types and methods with byref-like types. As a few examples, this affects BCL delegate types (`Action<>`, `Func<>`), interfaces (`IEnumerable<>`, `IComparable<>`) and generic arguments with a user-provided accumulator function (`String.string Create<TState>(int length, TState state, SpanAction<char, TState> action)`).
183
+
* It is impossible to author generic code supporting byref-like types in F#.
182
184
183
185
This last point is crucial for F# pipeline-style programming, as `|>` is a generic function that parameterizes its input types. This restriction may be relaxed for `|>` in the future, as it is inline and does not make any calls to non-inlined generic functions in its body.
Copy file name to clipboardExpand all lines: docs/fsharp/language-reference/compiler-directives.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -23,7 +23,7 @@ The following table lists the preprocessor directives that are available in F#.
23
23
|`#else`|Supports conditional compilation. Marks a section of code to include if the symbol used with the previous `#if` is not defined.|
24
24
|`#endif`|Supports conditional compilation. Marks the end of a conditional section of code.|
25
25
|`#`[line]*int*,<br/>`#`[line]*int**string*,<br/>`#`[line]*int**verbatim-string*|Indicates the original source code line and file name, for debugging. This feature is provided for tools that generate F# source code.|
26
-
|`#nowarn`*warningcode*|Disables a compiler warning or warnings. To disable a warning, find its number from the compiler output and include it in quotation marks. Omit the "FS" prefix. To disable multiple warning numbers on the same line, include each number in quotation marks, and separate each string by a space. <br/> For example: `#nowarn "9" "40"`|
26
+
|`#nowarn`*warningcode*|Disables a compiler warning or warnings. To disable multiple warning numbers on the same line, separate each string by a space. <br/> For example: `#nowarn 9 42`|
27
27
28
28
The effect of disabling a warning applies to the entire file, including portions of the file that precede the directive.|
Copy file name to clipboardExpand all lines: docs/fsharp/language-reference/computation-expressions.md
+8-4Lines changed: 8 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -440,17 +440,21 @@ You can define a custom operation on a computation expression and use a custom o
440
440
441
441
If you already have a builder class, its custom operations can be extended from outside of this builder class. Extensions must be declared in modules. Namespaces cannot contain extension members except in the same file and the same namespace declaration group where the type is defined.
442
442
443
-
The following example shows the extension of the existing `FSharp.Linq.QueryBuilder` class.
443
+
The following example shows the extensions of the existing `FSharp.Linq.QueryBuilder` class.
444
444
445
445
```fsharp
446
446
open System
447
447
open FSharp.Linq
448
448
449
449
type QueryBuilder with
450
450
451
-
[<CustomOperation("existsNot")>]
452
-
member _.ExistsNot (source: QuerySource<'T, 'Q>, predicate) =
453
-
System.Linq.Enumerable.Any (source.Source, Func<_,_>(predicate)) |> not
451
+
[<CustomOperation>]
452
+
member _.any (source: QuerySource<'T, 'Q>, predicate) =
Custom operations can be overloaded. For more information, see [F# RFC FS-1056 - Allow overloads of custom keywords in computation expressions](https://github.com/fsharp/fslang-design/blob/main/FSharp-6.0/FS-1056-allow-custom-operation-overloads.md).
Copy file name to clipboardExpand all lines: docs/fsharp/language-reference/fsharp-collection-types.md
+15Lines changed: 15 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -97,6 +97,21 @@ This section compares the functions that are available on F# collection types. T
97
97
|partition|O(N)|O(N)|-|O(N)|O(N)|Splits the collection into two collections. The first collection contains the elements for which the given predicate returns `true`, and the second collection contains the elements for which the given predicate returns `false`.|
98
98
|permute|O(N)|O(N)|-|-|-|Returns an array with all elements permuted according to the specified permutation.|
99
99
|pick|O(N)|O(N)|O(N)|O(log(N))|-|Applies the given function to successive elements, returning the first result where the function returns Some. If the function never returns Some, `System.Collections.Generic.KeyNotFoundException` is raised.|
100
+
|randomChoice|O(1)|O(1)|O(1)|-|-|Returns a random element from the given collection.|
101
+
|randomChoiceBy|O(1)|O(1)|O(1)|-|-|Returns a random element from the given collection with the specified `randomizer` function.|
102
+
|randomChoiceWith|O(1)|O(1)|O(1)|-|-|Returns a random element from the given collection with the specified `Random` instance.|
103
+
|randomChoices|O(count)|O(count)|O(count)|-|-|Returns a collection of random elements from the given collection, each element can be selected multiple times.|
104
+
|randomChoicesBy|O(count)|O(count)|O(count)|-|-|Returns a collection of random elements from the given collection with the specified `randomizer` function, each element can be selected multiple times.|
105
+
|randomChoicesWith|O(count)|O(count)|O(count)|-|-|Returns a collection of random elements from the given collection with the specified `Random` instance, each element can be selected multiple times.|
106
+
|randomSample|O(count)|O(count)|O(count)|-|-|Returns a random sample of elements from the given collection, each element can be selected only once.|
107
+
|randomSampleBy|O(count)|O(count)|O(count)|-|-|Returns a random sample of elements from the given colleciton with the specified `randomizer` function, each element can be selected only once.|
108
+
|randomSampleWith|O(count)|O(count)|O(count)|-|-|Returns a random sample of elements from the given collection with the specified `Random` instance, each element can be selected only once.|
109
+
|randomShuffle|O(N)|O(N)|O(N)|-|-|Return a new collection shuffled in a random order.|
110
+
|randomShuffleBy|O(N)|O(N)|O(N)|-|-|Return a new collection shuffled in a random order with the specified `randomizer` function.|
111
+
|randomShuffleWith|O(N)|O(N)|O(N)|-|-|Return a new collection shuffled in a random order with the specified `Random` instance.|
112
+
|randomShuffleInPlace|O(N)|-|-|-|-|Sorts input array in a random order by mutating the array in-place.|
113
+
|randomShuffleInPlaceBy|O(N)|-|-|-|-|Sorts input array in a random order using the specified `randomizer` function by mutating the array in-place.|
114
+
|randomShuffleInPlaceWith|O(N)|-|-|-|-|Sorts input array in a random order with the specified `Random` instance by mutating the array in-place.|
100
115
|readonly|-|-|O(N)|-|-|Creates a sequence object that delegates to the given sequence object. This operation ensures that a type cast can't rediscover and mutate the original sequence. For example, if given an array, the returned sequence will return the elements of the array, but you can't cast the returned sequence object to an array.|
101
116
|reduce|O(N)|O(N)|O(N)|-|-|Applies a function to each element of the collection, threading an accumulator argument through the computation. This function starts by applying the function to the first two elements, passes this result into the function along with the third element, and so on. The function returns the final result.|
102
117
|reduceBack|O(N)|O(N)|-|-|-|Applies a function to each element of the collection, threading an accumulator argument through the computation. If the input function is f and the elements are i0...iN, this function computes f i0 (...(f iN-1 iN)).|
Copy file name to clipboardExpand all lines: docs/fsharp/tools/fsharp-interactive/index.md
+4-2Lines changed: 4 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -243,15 +243,17 @@ The `#r` and `#load` directives seen previously are only available in F# Interac
243
243
|`#help`|Displays information about available directives or documentation for specific functions.|
244
244
|`#I`|Specifies an assembly search path in quotation marks.|
245
245
|`#quit`|Terminates an F# Interactive session.|
246
-
|`#time "on"` or `#time "off"`|By itself, `#time` toggles whether to display performance information. When it is `"on"`, F# Interactive measures real time, CPU time, and garbage collection information for each section of code that is interpreted and executed.|
246
+
|`#time on` or `#time off`|By itself, `#time` toggles whether to display performance information. When it is `on`, F# Interactive measures real time, CPU time, and garbage collection information for each section of code that is interpreted and executed.|
247
247
248
248
[^1]: More about [F# Interactive extensions](https://aka.ms/dotnetdepmanager).
249
249
250
250
When you specify files or paths in F# Interactive, a string literal is expected. Therefore, files and paths must be in quotation marks, and the usual escape characters apply. You can use the `@` character to cause F# Interactive to interpret a string that contains a path as a verbatim string. This causes F# Interactive to ignore any escape characters.
251
251
252
+
For other cases, quotation marks are optional, starting with F# 9.
253
+
252
254
### Extended #help directive
253
255
254
-
The `#help` directive now supports displaying documentation for specific functions. You can pass the name of the function directly (without quotes) to retrieve details.
256
+
The `#help` directive now supports displaying documentation for specific functions. You can pass the name of the function directly to retrieve details.
0 commit comments