An open-source, cross-platform functional language for .NET
Supported on Windows, Linux, and macOS
// 'name' is inferred to be a string based on usage. let printMessage name = printfn "Hello there, %s!\n" name // 'names' is inferred to be a sequence of strings. let printNames names = names |> Seq.iter printMessage let names = [ "Ana"; "Felipe"; "Emillia" ] printNames names
let square x = x * x let isOdd x = x % 2 <> 0 let sumOfOddSquares nums = nums |> List.filter isOdd |> List.sumBy square let numbers = [1; 2; 3; 4; 5] let sum = sumOfOddSquares numbers printfn "The sum of the odd squares in %A is %d" numbers sum
type Shape = | Square of side: double | Rectangle of width: double * length: double let getArea shape = match shape with | Square side -> side * side | Rectangle (width, length) -> width * length let square = Square 2.0 printfn "The area of the square is %f" (getArea square)
type Customer(firstName, middleInitial, lastName) = member this.FirstName = firstName member this.MiddleInitial = middleInitial member this.LastName = lastName member this.SayFullName() = this.FirstName + " " + this.MiddleInitial + " " + this.LastName let customer = Customer("Emillia", "C", "Miller") printfn "Hello, I'm %s!" (customer.SayFullName())
F# is a functional-first language with features and idioms for both functional and object-oriented programming. It has been designed for functional programming on .NET while also offering clean interop with C# and existing codebases.
F# is an open source language and Microsoft is a leading contributor. The independent F# Software Foundation provides a central place for the F# community to grow and learn together.