F#

1 program Added 2025-10-22T09:35:14Z Model: anthropic/claude-3.5-sonnetTemp: 0.4 Evidence Report issue View issues
Aliases: FSharp, F Sharp
Provenance: commit 092527805f · authored 2025-10-22T11:35:14+02:00 · model anthropic/claude-3.5-sonnet

Sources mentioning this language

8 sources · pl_id: pl/f-sharp
LLM (this repo) · 1PldbLinguistPygmentsWikipediaHyperpolyglotRosettacodeWikidata · Q648619

Wikipedia infobox

Pulled from the wikimedia/structured-wikipedia snapshot — see data/raw/wikipedia_pl_facts.*.jsonl and pl_fact.csv for the long-table provenance.

Paradigmsmulti-paradigm: functional · imperative · object-oriented · agent-oriented · metaprogramming · reflective · concurrent
Typingstatic, strong, inferred
Designed byMicrosoft · The F# Software Foundation · Don Syme · Microsoft Research
First appeared2005
Influenced byC# · Erlang · Haskell · ML · OCaml · Python · Scala
LicenseMIT
Homepagehttps://fsharp.org/

Extensions claimed by this language

10 claims. Each row is one upstream assertion with its strength. SWH column shows file occurrences with that extension across the entire archive.
ExtensionSourceStrengthSWH
.fslinguistprimary2.4M files
.fspygmentsprimary2.4M files
.fswikidataprimary2.4M files
.fsiwikidataprimary41.4K files
.fsscriptwikidataprimary363 files
.fsxwikidataprimary237.4K files
.fsilinguistsecondary41.4K files
.fsipygmentssecondary41.4K files
.fsxlinguistsecondary237.4K files
.fsxpygmentssecondary237.4K files

Related languages

A# (0.29)P# (0.25)X# (0.25)C# (0.24)SML# (0.23)

LLM-contributed programs

Conway's Game of Life in F#

Provenance: commit 092527805f · authored 2025-10-22T11:35:14+02:00 · model anthropic/claude-3.5-sonnet · Temp 0.4
code.fs · license: MIT · added: 2025-10-22T09:35:14Z
open System

type Cell = Alive | Dead
type Grid = Cell[,]

let initGrid size =
    let r = Random()
    Array2D.init size size (fun _ _ -> if r.Next(2) = 0 then Dead else Alive)

let countNeighbors (grid: Grid) row col =
    let size = Array2D.length1 grid
    let mutable count = 0
    for r in (max 0 (row-1))..(min (size-1) (row+1)) do
        for c in (max 0 (col-1))..(min (size-1) (col+1)) do
            if not (r = row && c = col) && grid.[r,c] = Alive then
                count <- count + 1
    count

let nextGeneration (grid: Grid) =
    let size = Array2D.length1 grid
    Array2D.init size size (fun r c ->
        match grid.[r,c], countNeighbors grid r c with
        | Alive, (2 | 3) -> Alive
        | Dead, 3 -> Alive
        | _ -> Dead)

let printGrid (grid: Grid) =
    let size = Array2D.length1 grid
    for r in 0..size-1 do
        for c in 0..size-1 do
            printf "%s" (if grid.[r,c] = Alive then "█" else " ")
        printfn ""
    printfn ""

let rec gameLoop grid =
    Console.Clear()
    printGrid grid
    System.Threading.Thread.Sleep(100)
    gameLoop (nextGeneration grid)

[<EntryPoint>]
let main argv =
    gameLoop (initGrid 20)
    0

Real programs from Software Heritage

1 sample mined from derived_datasets/<date>/contents/*.parquet, byte-verified against the SWH archive. Citation-grade qualified SWHIDs preserved.
ExprEquiv.fs · 7773 B · ext .fs · seen 379× in SWH
via heuristicrule h/linguist/.fs/1
swh:1:cnt:c88ae7180607d3650959a6cd946de3f27af7b250;origin=https://github.com/septract/starling-tool;anchor=swh:1:rev:cfbaf8489ba4b0425e6ad47d552ae853c86cb9ff;path=/ExprEquiv.fs
Open in SWH · Raw bytes (SWH) · GitHub raw
Show source
/// <summary>
///     Heavyweight expression equivalence checks.
///
///     <para>
///         Unlike normal expression checks, these produce <c>Equiv</c>
///         values, which must be passed to <c>runEquiv</c> to check.
///     </para>
///
///     <para>
///         These are farmed out to Z3.  As such, they are not likely to
///         execute quickly.  Use with caution.
///     </para>
/// </summary>
module Starling.Core.ExprEquiv

open Microsoft
open Starling.Core.Expr
open Starling.Core.Var
open Starling.Core.Z3


/// <summary>
///     Type for equivalence checks.
/// </summary>
type Equiv<'var> = ('var -> string) -> Z3.Context -> Z3.BoolExpr

/// <summary>
///     Runs an equivalence check.
/// </summary>
/// <param name="toVar">
///     A function converting variables in the check to <c>Var</c>s.
///     The vars must be unique to their origin variables across the
///     equivalence.
/// </param>
/// <param name="e">
///     The equivalence check to run.
/// </param>
/// <typeparam name="var">
///     Meta-type of variables inside the equivalence-checked expressions.
/// </typeparam>
/// <returns>
///     True if the equivalence check definitely succeeded.
///     False otherwise (including if the check was undecideable).
/// </returns>
let equivHolds
  (toVar : 'var -> Var)
  (e : Equiv<'var>) =
    (* The tactic here is the same as the Starling one:
       negate the equivalence and try to falsify it. *)
    use ctx = new Z3.Context ()
    let term = ctx.MkNot (e toVar ctx)
    match (Run.runTerm ctx term) with
    | Z3.Status.UNSATISFIABLE -> true
    | _ -> false

/// <summary>
///     Or-disjoins two equivalence checks.
/// </summary>
/// <param name="x">
///     The first equivalence check to disjoin.
/// </param>
/// <param name="y">
///     The second equivalence check to disjoin.
/// </param>
/// <typeparam name="var">
///     Meta-type of variables inside the equivalence-checked expressions.
/// </typeparam>
/// <returns>
///     The or-disjunction of the two, which will return true only if
///     (but not necessarily if!) at least one equivalence holds.
/// </returns>
let orEquiv (x : Equiv<'var>) (y : Equiv<'var>) : Equiv<'var> =
    fun toVar (ctx : Z3.Context) ->
        ctx.MkOr [| x toVar ctx ; y toVar ctx |]

/// <summary>
///     And-conjoins two equivalence checks.
/// </summary>
/// <param name="x">
///     The first equivalence check to conjoin.
/// </param>
/// <param name="y">
///     The second equivalence check to conjoin.
/// </param>
/// <typeparam name="var">
///     Meta-type of variables inside the equivalence-checked expressions.
/// </typeparam>
/// <returns>
///     The and-conjunction of the two, which will return true only if
///     (but not necessarily if!) both equivalences hold.
/// </returns>
let andEquiv (x : Equiv<'var>) (y : Equiv<'var>) : Equiv<'var> =
    fun toVar (ctx : Z3.Context) ->
        ctx.MkAnd [| x toVar ctx ; y toVar ctx |]

/// <summary>
///     Returns true if two expressions are definitely equivalent to each
///     other.
///
///     <para>
///         This is sound, but not complete.  It should only be used for
///         optimisations.
///     </para>
/// </summary>
/// <param name="x">
///     The first expression to check.
/// </param>
/// <param name="y">
///     The second expression to check.
/// </param>
/// <typeparam name="var">
///     Meta-type of variables inside the equivalence-checked expressions.
/// </typeparam>
/// <returns>
///     An equivalence check returning true only if (but not if!)
///     <paramref name="x" /> and <paramref name="y" /> are equivalent.
/// </returns>
/// <remarks>
///     This function calls into Z3, and is thus likely to be slow.
///     Use with caution.
/// </remarks>
let equiv (x : BoolExpr<'var>) (y : BoolExpr<'var>) : Equiv<'var> =
    fun toVar ctx ->
        let sx = Expr.boolToZ3 false toVar ctx (normalBool (simp x))
        let sy = Expr.boolToZ3 false toVar ctx (normalBool (simp y))
        ctx.MkIff (sx, sy)

/// <summary>
///     Returns true if two expressions are definitely negations of each
///     other.
///
///     <para>
///         This is sound, but not complete.  It should only be used for
///         optimisations.
///     </para>
/// </summary>
/// <param name="x">
///     The first expression to check.
/// </param>
/// <param name="y">
///     The second expression to check.
/// </param>
/// <typeparam name="var">
///     Meta-type of variables inside the equivalence-checked expressions.
/// </typeparam>
/// <returns>
///     An equivalence check returning true only if (but not if!)
///     <paramref name="x" /> and <paramref name="y" /> negate each other.
/// </returns>
/// <remarks>
///     This function calls into Z3, and is thus likely to be slow.
///     Use with caution.
/// </remarks>
let negates (x : BoolExpr<'var>) (y : BoolExpr<'var>) : Equiv<'var> =
    fun toVar ctx -> equiv x (BNot y) toVar ctx


/// <summary>
///     Tests for <c>ExprEquiv</c>.
/// </summary>
module Tests =
    open NUnit.Framework
    open Starling.Utils.Testing
    open Starling.Core.Pretty
    open Starling.Core.Var.Pretty

    /// <summary>
    ///     NUnit tests for <c>ExprEquiv</c>.
    /// </summary>
    type NUnit () =
        /// Test cases for negation checking.
        static member ObviousNegations =
            [ (tcd [| (BTrue : VBoolExpr)
                      (BFalse : VBoolExpr) |])
                .Returns(true)
              (tcd [| (BTrue : VBoolExpr)
                      (BTrue : VBoolExpr) |])
                .Returns(false)
              (tcd [| (BFalse : VBoolExpr)
                      (BFalse : VBoolExpr) |])
                .Returns(false)
              (tcd [| (BTrue : VBoolExpr)
                      (iEq (IInt 5L) (IInt 6L) : VBoolExpr) |])
                .Returns(true)
              (tcd [| (iEq (IVar "x") (IInt 2L))
                      (BNot (iEq (IVar "x") (IInt 2L))) |])
                .Returns(true)
              (tcd [| (iEq (IVar "x") (IInt 2L))
                      (BNot (iEq (IVar "y") (IInt 2L))) |])
                .Returns(false)
              // De Morgan
              (tcd [| (BAnd [ BVar "x" ; BVar "y" ])
                      (BOr [ BNot (BVar "x")
                             BNot (BVar "y") ] ) |] )
                .Returns(true)
              (tcd [| (BAnd [ BVar "x" ; BVar "y" ])
                      (BOr [ BNot (BVar "y")
                             BNot (BVar "x") ] ) |] )
                .Returns(true)
              (tcd [| (BOr [ BVar "x" ; BVar "y" ])
                      (BAnd [ BNot (BVar "x")
                              BNot (BVar "y") ] ) |] )
                .Returns(true)
              (tcd [| (BOr [ BVar "x" ; BVar "y" ])
                      (BAnd [ BNot (BVar "y")
                              BNot (BVar "x") ] ) |] )
                .Returns(true) ]
            |> List.map (
                fun d -> d.SetName(sprintf "%s and %s are %s negation"
                                            (((d.OriginalArguments.[1])
                                              :?> VBoolExpr)
                                             |> printVBoolExpr |> print)
                                            (((d.OriginalArguments.[0])
                                              :?> VBoolExpr)
                                             |> printVBoolExpr |> print)
                                            (if (d.ExpectedResult :?> bool)
                                             then "a" else "not a")))

        /// Checks whether negation checking is sound and sufficiently complete.
        [<TestCaseSource("ObviousNegations")>]
        member x.``negates is sound and sufficiently complete`` a b =
            equivHolds id (negates a b)

Disambiguation rules

Linguist heuristic rules that predict this language when one of its claimed extensions is shared with another.
RuleExtKindPredicates (truncated)
h/linguist/.fs/1.fspredicates[{"kind": "any", "regexes": ["^\\s*(#light|import|let|module|namespace|open|type)"]}]

Contribute — propose a file extension

Tell us where to find evidence about F# (mapped to pl/f-sharp). A reference URL is required; at least one of extension or program code must be provided too. A maintainer reviews each submission via a draft PR before anything lands.
Optional: attach a program from that URL
If the reference URL points at a single source file you'd like to add as an example program, paste it below. The workflow will write it under languages/F#/programs/<sha>/. Keep under ~200 lines.
(or open the pre-filled issue directly)
← F! U! C! K! What do we appreciate! F'juhv iK'tlhUng →