Skip to main content

F#

Pronunciation
EF-SHARP
Updated 2 min read

Share this page

Send the link, quote the definition with a link back, or show it as a card on your own site.

https://softwaredictionary.org/terms/fsharp

In short

F# is a functional-first, statically typed language for .NET that pairs concise, type-inferred code with full access to the .NET ecosystem and C# libraries.

What is F#?

F# is a general-purpose programming language designed by Don Syme at Microsoft Research and first released in 2005. It belongs to the ML family of languages and was strongly influenced by OCaml. F# runs on .NET, is open source and cross-platform, and is developed by Microsoft together with the F# Software Foundation community.

F# is functional-first, meaning values are immutable and functions are the main building blocks by default, but it also supports classes, interfaces and mutable state when needed. Type inference is strong enough that most code has no type annotations at all, yet everything is checked at compile time. Indentation defines blocks, the pipe operator |> chains transformations, and discriminated unions with pattern matching make it easy to model data that can take one of several shapes, such as a payment that is either a card, a bank transfer or cash.

F# is used for financial modeling, data analysis, scientific computing, domain-heavy backend services and scripting with .fsx files. Because it compiles to the same intermediate language as C#, an F# project can use any .NET library and be called from C# code. Features such as units of measure, which let the compiler catch mistakes like adding meters to seconds, show its focus on correctness.

F# is most often compared with C#, its sibling on .NET. C# is object-oriented first, with functional features added over time, and has a much larger community, while F# is functional first, more concise and makes immutability and exhaustive pattern matching the default. F# is also compared with Haskell: both are statically typed functional languages, but F# evaluates eagerly and allows side effects anywhere, which makes it more pragmatic and easier to mix with existing .NET code.

Key takeaways

  • F# is a functional-first, statically typed language that runs on .NET.
  • Strong type inference means most code needs no type annotations.
  • Discriminated unions and pattern matching model data clearly and safely.
  • It interoperates fully with C# and the rest of the .NET ecosystem.
  • Units of measure let the compiler catch unit mix-ups in calculations.

Example

Discriminated unions and pipes in F#fsharp
// A discriminated union: a payment is exactly one of these cases
type Payment =
    | Card of number: string
    | BankTransfer of iban: string
    | Cash

let describe payment =
    match payment with
    | Card n -> sprintf "Card ending in %s" (n.Substring(n.Length - 4))
    | BankTransfer iban -> sprintf "Transfer from %s" iban
    | Cash -> "Paid in cash"

[ Card "0000111122223333"; Cash ]
|> List.map describe
|> List.iter (printfn "%s")   // Card ending in 3333, then Paid in cash

Readers ask

What is the difference between F# and C#?

Both run on .NET and can use the same libraries. C# is object-oriented first with a C-style syntax, while F# is functional first, uses indentation instead of braces, and makes immutability, type inference and pattern matching the default style.

Is F# still maintained?

Yes. F# is open source, ships with the .NET SDK and receives a new version alongside each major .NET release.

Can I use F# and C# in the same solution?

Yes. They compile to the same .NET intermediate language, so an F# project can reference C# projects and the other way around, which lets teams use F# for specific parts such as domain logic or data processing.

See also

Spotted a mistake or something missing on this page?Suggest an edit

Read a random page
Open today's review
Switch to the dark theme
Read this page in Türkçe

More

Settings