Top 1,000 Features Creators Events Podcasts Extensions Blog Explorer CSV Download


< >

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

#67on PLDB 19Years 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]?
Integers โœ“
// \d[\d_]*[uU]?[yslLnQRZINGmM]?
Floats โœ“
// -?\d[\d_]*(.[\d_]*)?([eE][+\-]?\d[\d_]*)[fFmM]?
Hexadecimals โœ“
// 0[xX][\da-fA-F][\da-fA-F_]*[uU]?[yslLn]?[fF]?
Octals โœ“
// 0[oO][0-7][0-7_]*[uU]?[yslLn]?
Conditionals โœ“
Access Modifiers โœ“
Functions โœ“
Constants โœ“
Classes โœ“
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 โœ“
Namespaces โœ“
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
Directives โœ“
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
Comments โœ“
Case Insensitive Identifiers X

View source

- Build the next great programming language ยท About ยท Resources ยท Acknowledgements ยท Part of the World Wide Scroll