PLDB
Languages Features Calendar About Lists Add Language
GitHub icon

F#

F#

F# is a programming language created in 2005 by Don Syme.

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...

Try now: Riju ยท Replit

#50on PLDB 17Years Old 4.3kUsers

Example code from Riju:

printfn "Hello, world!"

Example code from hello-world:

printfn "Hello World"

Example code from the Hello World Collection:

(* Hello World in F# *) printf "Hello World!\n"

Example code 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 code 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")

Keywords in F#

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 Example Token
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
//
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"
Comments โœ“

Trending F# repos on GitHub

repo stars description
fsharp 1919 "The F# compiler FSharp.Core library and tools for F#"

Article source

PLDB - Build the next great programming language. v5.0.0 - Acknowledgements ยท Email ยท GitHub