Questions Concepts
GitHub icon


F# - Programming language

< >

F# is an open source programming language created in 2005 by Don Syme.

#65on PLDB 18Years Old

Try now: Riju · Replit

F# (pronounced F sharp) is a strongly typed, multi-paradigm programming language that encompasses functional, imperative, and object-oriented programming methods. F# is most often used as a cross-platform Common Language Infrastructure (CLI) language, but it can also generate JavaScript and graphics processing unit (GPU) code. F# is developed by the F# Software Foundation, Microsoft and open contributors. Read more on Wikipedia...

Example from Compiler Explorer:
module Program let square num = num * num
Example from Riju:
printfn "Hello, world!"
Example from hello-world:
printfn "Hello World"
(* Hello World in F# *) printf "Hello World!\n"
Example from Linguist:
module Sample open System type Foo = { Bar : string } type Baz = interface end let Sample1(xs : int list) : string = xs |> (fun x -> string x) |> String.concat ","
Example from Wikipedia:
/// A simple prime number detector let isPrime (n:int) = let bound = int (sqrt (float n)) seq {2 .. bound} |> Seq.forall (fun x -> n % x <> 0) // We are using async workflows let primeAsync n = async { return (n, isPrime n) } /// Return primes between m and n using multiple threads let primes m n = seq {m .. n} |> primeAsync |> Async.Parallel |> Async.RunSynchronously |> Array.filter snd |> fst // Run a test primes 1000000 1002000 |> Array.iter (printfn "%d")
abstract and atomic as assert asr base begin break checked component const constraint constructor continue class default delegate do done downcast downto elif else end exception eager event external extern false finally for fun function fixed functor global if in include inherit inline interface internal land lor lsl lsr lxor lazy let match member mod module mutable namespace method mixin new not null of open or object override private parallel process protected pure public rec return static sealed struct sig then to true tailcall trait try type upcast use val void virtual volatile when while with yield

Language features

Feature Supported Token Example
Binary Literals
// 0[bB][01][01_]*[uU]?[yslLn]?
// \d[\d_]*[uU]?[yslLnQRZINGmM]?
// -?\d[\d_]*(.[\d_]*)?([eE][+\-]?\d[\d_]*)[fFmM]?
// 0[xX][\da-fA-F][\da-fA-F_]*[uU]?[yslLn]?[fF]?
// 0[oO][0-7][0-7_]*[uU]?[yslLn]?
Access Modifiers
While Loops
Booleans true false
Strings "
MultiLine Comments (* *)
(* A comment
Print() Debugging printfn
Units of Measure
[] type N = kg m/sec^2

let force1 = 5.0    
let force2 = 5.0

force1 = force2 // true
Line Comments //
// A comment
Type Inference
Semantic Indentation
Operator Overloading
namespace Widgets
type MyWidget1 =
   member this.WidgetName = "Widget1"
module WidgetsModule =
   let widgetName = "Widget2"
File Imports
open module-or-namespace-name
open System.IO
open List
open Seq
let function1 x y =
   printfn "x: %d y: %d" x y
   x + 2 * y
let function1 x y =
   printfn "x: %d y: %d" x y
   x - 2*y
// Line directives as source maps can be used when compiling to F#:
#line 25 "C:\\Projects\\MyProject\\MyProject\\Script1"
Doc comments
/// Adds 2 numbers
let rec add x y =
 x + y
Case Insensitive Identifiers X

View source

- Build the next great programming language · Search · Add Language · Features · Creators · Resources · About · Blog · Acknowledgements · Queries · Stats · Sponsor · Traffic · Traffic Today · Day 305 · · Logout