Piano Guidance
Photo by Thirdman Pexels Logo Photo: Thirdman

What is F# best for?

F# is a universal programming language for writing succinct, robust and performant code. F# allows you to write uncluttered, self-documenting code, where your focus remains on your problem domain, rather than the details of programming.

learn.microsoft.com - What is F# | Microsoft Learn
How much is a 100 year old player piano worth?
How much is a 100 year old player piano worth?

Today, on the Internet, there are people who are selling 'complete' circa 1920 upright player pianos in unrestored condition for $250.00 to $450.00...

Read More »
What animal can regrow its head?
What animal can regrow its head?

Hydras Scientists want to know how they do it. A new analysis reveals genetic underpinnings of how the aquatic animals regrow their heads after...

Read More »

Table of contents

What is F#

Article

10/13/2022

2 minutes to read

11 contributors Feedback

In this article

F# is a universal programming language for writing succinct, robust and performant code. F# allows you to write uncluttered, self-documenting code, where your focus remains on your problem domain, rather than the details of programming. It does this without compromising on speed and compatibility - it is open-source, cross-platform and interoperable. open System // Gets access to functionality in System namespace. // Defines a list of names let names = [ "Peter"; "Julia"; "Xi" ] // Defines a function that takes a name and produces a greeting. let getGreeting name = $"Hello, {name}" // Prints a greeting for each name! names |> List.map getGreeting |> List.iter (fun greeting -> printfn $"{greeting}! Enjoy your F#")

F# has numerous features, including:

Lightweight syntax

Immutable by default

Type inference and automatic generalization

First-class functions

Powerful data types

Pattern matching

Async programming

A full set of features are documented in the F# language guide.

Rich data types

Types such as Records and Discriminated Unions let you represent your data.

// Group data with Records type SuccessfulWithdrawal = { Amount: decimal Balance: decimal } type FailedWithdrawal = { Amount: decimal Balance: decimal IsOverdraft: bool } // Use discriminated unions to represent data of 1 or more forms type WithdrawalResult = | Success of SuccessfulWithdrawal | InsufficientFunds of FailedWithdrawal | CardExpired of System.DateTime | UndisclosedFailure F# records and discriminated unions are non-null, immutable, and comparable by default, making them very easy to use.

Correctness with functions and pattern matching

F# functions are easy to define. When combined with pattern matching, they allow you to define behavior whose correctness is enforced by the compiler. // Returns a WithdrawalResult let withdrawMoney amount = // Implementation elided let handleWithdrawal amount = let w = withdrawMoney amount // The F# compiler enforces accounting for each case! match w with | Success s -> printfn $"Successfully withdrew %f{s.Amount}" | InsufficientFunds f -> printfn $"Failed: balance is %f{f.Balance}" | CardExpired d -> printfn $"Failed: card expired on {d}" | UndisclosedFailure -> printfn "Failed: unknown :(" F# functions are also first-class, meaning they can be passed as parameters and returned from other functions.

Functions to define operations on objects

F# has full support for objects, which are useful when you need to blend data and functionality. F# members and functions can be defined to manipulate objects. type Set<'T when 'T: comparison>(elements: seq<'T>) = member s.IsEmpty = // Implementation elided member s.Contains (value) =// Implementation elided member s.Add (value) = // Implementation elided // ... // Further Implementation elided // ... interface IEnumerable<'T> interface IReadOnlyCollection<'T> module Set = let isEmpty (set: Set<'T>) = set.IsEmpty let contains element (set: Set<'T>) = set.Contains(element) let add value (set: Set<'T>) = set.Add(value) In F#, you will often write code that treats objects as a type for functions to manipulate. Features such as generic interfaces, object expressions, and judicious use of members are common in larger F# programs. To learn more about a larger set of F# features, check out the F# Tour.

What is the coolest sounding instrument?
What is the coolest sounding instrument?

10 Of The Most Unusual Musical Instruments That Sound Cool As... 3 Hydraulophone. 4 Gameleste. ... 5 Glass Harmonica. ... 6 Array Mbira. ... 7...

Read More »
Why is shifting left important?
Why is shifting left important?

Shift-left speeds up development efficiency and reduces costs by detecting and addressing software defects earlier in the development cycle before...

Read More »

What heart rate is too high by age?

To estimate your maximum age-related heart rate, subtract your age from 220. For example, for a 50-year-old person, the estimated maximum age-related heart rate would be calculated as 220 – 50 years = 170 beats per minute (bpm).

One way of checking physical activity intensity is to determine whether your pulse or heart rate is within the target zone during physical activity. 1 For moderate-intensity physical activity, your target heart rate should be between 64% and 76%1,2 of your maximum heart rate. You can estimate your maximum heart rate based on your age. To estimate your maximum age-related heart rate, subtract your age from 220. For example, for a 50-year-old person, the estimated maximum age-related heart rate would be calculated as 220 – 50 years = 170 beats per minute (bpm). The 64% and 76% levels would be:

64% level: 170 x 0.64 = 109 bpm, and

76% level: 170 x 0.76 = 129 bpm

This shows that moderate-intensity physical activity for a 50-year-old person will require that the heart rate remains between 109 and 129 bpm during physical activity. For vigorous-intensity physical activity, your target heart rate should be between 77% and 93%1,2 of your maximum heart rate. To figure out this range, follow the same formula used above, except change “64 and 76%” to “77 and 93%”. For example, for a 35-year-old person, the estimated maximum age-related heart rate would be calculated as 220 – 35 years = 185 beats per minute (bpm). The 77% and 93% levels would be:

77% level: 185 x 0.77 = 142 bpm, and

93% level: 185 x 0.93 = 172 bpm

This shows that vigorous-intensity physical activity for a 35-year-old person will require that the heart rate remains between 142 and 172 bpm during physical activity.

What is the heaviest song of Slipknot?
What is the heaviest song of Slipknot?

"Solway Firth" is a perfect example of the heaviest end of that spectrum, smashing Slipknot's full range of moods — creepy, cinematic, pummeling,...

Read More »
What key is most hits in?
What key is most hits in?

C major and G major, along with their relative minor counterparts A minor and E minor, are often considered the best key and scales for Pop music....

Read More »
What happened to the German officer in The Pianist?
What happened to the German officer in The Pianist?

The German officer made famous in Roman Polanski's 2002 film “The Pianist” has been posthumously recognized as Righteous Among the Nations. Wilm...

Read More »
Why is music theory so complicated?
Why is music theory so complicated?

Our brains process music hundreds of times faster than it can ever be explained by words and symbols. So it takes a long time to explain. There's...

Read More »