Measures Concepts
GitHub icon

F#

F# - Programming language

< >

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

#65on 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 |> List.map (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} |> Seq.map primeAsync |> Async.Parallel |> Async.RunSynchronously |> Array.filter snd |> Array.map 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 ✓
// https://fsharpforfunandprofit.com/posts/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 ✓
#if VERSION1
let function1 x y =
   printfn "x: %d y: %d" x y
   x + 2 * y
#else
let function1 x y =
   printfn "x: %d y: %d" x y
   x - 2*y
#endif
// 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 · Search · Add Language · Features · Creators · Resources · About · Blog · Acknowledgements · Queries · Stats · Sponsor · Day 605 · feedback@pldb.io · Logout