F# 4.6 adds multiple improvements to the F# language.
Get started
F# 4.6 is available in all .NET Core distributions and Visual Studio tooling. Get started with F# to learn more.
Anonymous records
Anonymous records are a new kind of F# type introduced in F# 4.6. They are simple aggregates of named values that don't need to be declared before use. You can declare them as either structs or reference types. They're reference types by default.
F#
open System
let getCircleStats radius =
let d = radius * 2.0let a = Math.PI * (radius ** 2.0)
let c = 2.0 * Math.PI * radius
{| Diameter = d; Area = a; Circumference = c |}
let r = 2.0let stats = getCircleStats r
printfn "Circle with radius: %f has diameter %f, area %f, and circumference %f"
r stats.Diameter stats.Area stats.Circumference
They can also be declared as structs for when you want to group value types and are operating in performance-sensitive scenarios:
F#
open System
let getCircleStats radius =
let d = radius * 2.0let a = Math.PI * (radius ** 2.0)
let c = 2.0 * Math.PI * radius
struct {| Diameter = d; Area = a; Circumference = c |}
let r = 2.0let stats = getCircleStats r
printfn "Circle with radius: %f has diameter %f, area %f, and circumference %f"
r stats.Diameter stats.Area stats.Circumference
They're quite powerful and can be used in numerous scenarios. Learn more at Anonymous records.
ValueOption functions
The ValueOption type added in F# 4.5 now has "module-bound function parity" with the Option type. Some of the more commonly-used examples are as follows:
F#
// Multiply a value option by 2 if it has valuelet xOpt = ValueSome 99let result = xOpt |> ValueOption.map (fun v -> v * 2)
// Reverse a string if it existslet strOpt = ValueSome "Mirror image"let reverse (str: string) =
match str with
| null
| "" -> ValueNone
| s ->
str.ToCharArray()
|> Array.rev
|> string
|> ValueSome
let reversedString = strOpt |> ValueOption.bind reverse
This allows for ValueOption to be used just like Option in scenarios where having a value type improves performance.
ითანამშრომლეთ ჩვენთან GitHub-ზე
ამ შიგთავსის წყაროს მოძიება GitHub-ზე არის შესაძლებელი, სადაც თქვენ ასევე შეგიძლიათ პრობლემების შექმნა და განხილვა და მოთხოვნების გადმოტანა. დამატებითი ინფორმაციისთვის იხილეთ ჩვენი დამხმარე სახელმძღვანელო.
.NET-(ი)ს უკუკავშირი
.NET არის ღია წყაროს პროექტი. აირჩიეთ ბმული უკუკავშირის გასაგზავნად:
შემოუერთდით Meetup სერიას, რათა შექმნათ მასშტაბური AI გადაწყვეტილებები რეალურ სამყაროში გამოყენების შემთხვევებზე დაყრდნობით თანამემამულე დეველოპერებთან და ექსპერტებთან.
F# is an open-source, cross-platform programming language that makes it easy to write succinct, performant, robust, and practical code. It's a general-purpose language that enables you to create many different types of applications like Web API, Desktop, IoT, Gaming and more.