-
Notifications
You must be signed in to change notification settings - Fork 6k
Add comprehensive documentation for F# 7 and F# 8 features #49119
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
bac84de
6fe9ccd
559b308
4b50da8
3a0bd82
fc8e5e5
707c1ef
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -3,7 +3,158 @@ title: What's new in F# 7 - F# Guide | |||||||||
| description: Find information on the new features available in F# 7. | ||||||||||
| ms.date: 11/17/2023 | ||||||||||
| ms.topic: whats-new | ||||||||||
| ai-usage: ai-assisted | ||||||||||
| --- | ||||||||||
| # What's new in F# 7 | ||||||||||
|
|
||||||||||
| For information on F# 7, please see [Announcing F# 7](https://devblogs.microsoft.com/dotnet/announcing-fsharp-7). | ||||||||||
| F# 7 introduces several enhancements that improve interoperability with .NET, simplify common programming patterns, and enhance developer productivity. This article highlights the major changes in F# 7, developed in the [F# open source code repository](https://github.com/dotnet/fsharp). | ||||||||||
|
|
||||||||||
| F# 7 is available in .NET 7. You can download the latest .NET SDK from the [.NET downloads page](https://dotnet.microsoft.com/download). | ||||||||||
|
|
||||||||||
| ## Static abstract members in interfaces | ||||||||||
|
|
||||||||||
| F# 7 adds support for static abstract members in interfaces, aligning with the feature introduced in C# 11 and .NET 7. This feature enables you to define interfaces that require implementing types to provide static members, which is particularly useful for generic math scenarios and other generic programming patterns. | ||||||||||
|
|
||||||||||
| You can define an interface with static abstract members using the `static abstract` keywords: | ||||||||||
|
|
||||||||||
| ```fsharp | ||||||||||
| type IAddition<'T when 'T :> IAddition<'T>> = | ||||||||||
| static abstract member (+) : 'T * 'T -> 'T | ||||||||||
| static abstract member Zero : 'T | ||||||||||
| ``` | ||||||||||
|
|
||||||||||
| Types can implement these interfaces by providing the required static members: | ||||||||||
|
|
||||||||||
| ```fsharp | ||||||||||
| type Number(value: int) = | ||||||||||
| member _.Value = value | ||||||||||
|
|
||||||||||
| interface IAddition<Number> with | ||||||||||
| static member (+) (x: Number, y: Number) = | ||||||||||
| Number(x.Value + y.Value) | ||||||||||
| static member Zero = Number(0) | ||||||||||
| ``` | ||||||||||
|
|
||||||||||
| This feature enables you to write generic algorithms that work across different types: | ||||||||||
|
|
||||||||||
| ```fsharp | ||||||||||
| let inline addAll (items: 'T list) = | ||||||||||
| items |> List.fold (+) 'T.Zero | ||||||||||
|
Comment on lines
+41
to
+42
|
||||||||||
| let inline addAll (items: 'T list) = | |
| items |> List.fold (+) 'T.Zero | |
| let inline addAll (items: ^T list) = | |
| items |> List.fold (+) ^T.Zero |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @copilot, I think this is for declaring that the type-parameter is a generic type, no?
Uh oh!
There was an error while loading. Please reload this page.