or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

async-programming.mdcharacter-operations.mdcollections.mdconfiguration.mdcore-infrastructure.mddata-encoding.mddate-time.mdexternal-integration.mdindex.mdnumeric-types.mdreactive-programming.mdstring-operations.mdtype-system.md
tile.json

tessl/dotnet-fable-library

F# runtime library for Fable compiler that provides JavaScript/TypeScript implementations of F# core types and operations

Workspace
tessl
Visibility
Public
Created
Last updated
Describes

pkg:dotnet/fable-library@1.1.x

To install, run

npx @tessl/cli install tessl/dotnet-fable-library@1.1.0

index.mddocs/

Fable Library

Overview

The Fable Library is the F# runtime library for the Fable compiler that provides JavaScript/TypeScript implementations of F# core types and operations. It enables F# code to compile to JavaScript while maintaining strong compatibility with .NET APIs, providing efficient implementations optimized for browser and Node.js environments.

The library contains over 500+ public functions organized into 12 major functional areas, covering everything from basic type operations to advanced asynchronous programming patterns.

Package Information

  • Package Type: F# runtime library that compiles to JavaScript/TypeScript
  • Target Environments: Browser, Node.js
  • Compatibility: .NET Framework/Core API compatibility
  • Module System: ES2015 modules
  • Output: JavaScript with TypeScript declarations

Core Imports

F# Context

In F# code, the library functions are available through standard F# modules:

open System
open System.Collections.Generic
open FSharp.Core

JavaScript/TypeScript Context

When consuming from JavaScript or TypeScript:

// Core utilities and types
import * as Util from "fable-library/Util.js";
import * as Types from "fable-library/Types.js";
import * as Option from "fable-library/Option.js";

// Numeric types
import * as Long from "fable-library/Long.js";
import * as Decimal from "fable-library/Decimal.js";

// Collections
import * as Seq from "fable-library/Seq.js";
import * as Array from "fable-library/Array.js";

// Async programming
import * as Async from "fable-library/Async.js";

Basic Usage

Working with F# Types in JavaScript

import * as Types from "fable-library/Types.js";
import * as Option from "fable-library/Option.js";

// Create F# option values
const someValue = Option.some(42);
const noneValue = null; // F# None becomes null in JS

// Create F# lists
const list = new Types.List(1, new Types.List(2, new Types.List(3, null)));

// Create F# records
class Person extends Types.Record {
    constructor(name, age) {
        super();
        this.name = name;
        this.age = age;
    }
}

Using Sequences and Collections

import * as Seq from "fable-library/Seq.js";

// Create sequences
const numbers = Seq.range(1, 10);
const doubled = Seq.map(x => x * 2, numbers);

// Convert to array
const result = Seq.toArray(doubled);
// [2, 4, 6, 8, 10, 12, 14, 16, 18, 20]

Asynchronous Programming

// F# async workflow
async {
    let! result = someAsyncOperation()
    return result * 2
}
// JavaScript consumption of F# async
import * as Async from "fable-library/Async.js";

const computation = Async.startAsPromise(asyncWorkflow);
computation.then(result => console.log(result));

Architecture

Type System Foundation

The library is built on a sophisticated type system that maps F# types to JavaScript equivalents:

  • SystemObject: Base type for all F# objects
  • Union: Discriminated union base class
  • Record: F# record base class
  • List: Immutable linked list implementation
  • Option: Optional value handling (Some/None)

Numeric Type Hierarchy

Comprehensive numeric type support including:

  • 32/64-bit integers with overflow handling
  • Floating point (single/double precision)
  • Decimal arithmetic via big.js integration
  • BigInteger for arbitrary precision arithmetic
  • Long for 64-bit integer operations

Collection Framework

Multiple collection implementations optimized for different use cases:

  • Immutable collections: List, Set, Map
  • Mutable collections: Array, Dictionary, HashSet
  • Lazy sequences: Seq with deferred evaluation
  • Specialized iterators: Enumerable pattern support

Asynchronous Programming Model

Complete async programming stack:

  • AsyncBuilder: F# async workflow implementation
  • CancellationToken: Cancellation support
  • MailboxProcessor: Actor model implementation
  • Observable/Event: Reactive programming support

Capabilities

Core Infrastructure

Foundation types, utilities, and interfaces that underpin the entire library.

import { IComparer, IEquatable, equals, compare } from "fable-library/Util.js";

// Equality and comparison operations
const isEqual = equals(obj1, obj2);
const comparison = compare(value1, value2);

Numeric Types

Comprehensive numeric type system with full arithmetic operations.

import * as Long from "fable-library/Long.js";
import * as Decimal from "fable-library/Decimal.js";

// 64-bit integer arithmetic
const bigNum = Long.fromString("9223372036854775807");
const doubled = Long.multiply(bigNum, Long.fromNumber(2));

// Decimal arithmetic
const precise = Decimal.fromString("123.456789");
const result = Decimal.multiply(precise, Decimal.fromNumber(2));

String Operations

Rich string manipulation capabilities with .NET String API compatibility.

import * as String from "fable-library/String.js";
import * as RegExp from "fable-library/RegExp.js";

// String manipulation
const result = String.replace("Hello World", "World", "Fable");
// "Hello Fable"

// Regular expressions
const matches = RegExp.matches("test123", "\\d+");
// ["123"]

Date and Time

Complete date and time handling with timezone support.

import * as Date from "fable-library/Date.js";
import * as TimeSpan from "fable-library/TimeSpan.js";

// Date operations
const now = Date.now();
const tomorrow = Date.addDays(now, 1);

// Time spans
const duration = TimeSpan.fromHours(2.5);
const totalMinutes = TimeSpan.totalMinutes(duration); // 150

Collections

Extensive collection operations with functional programming support.

import * as Seq from "fable-library/Seq.js";
import * as Array from "fable-library/Array.js";

// Sequence operations
const filtered = Seq.filter(x => x > 5, Seq.range(1, 10));
const mapped = Seq.map(x => x * x, filtered);
const result = Seq.toArray(mapped);

// Array operations with F# semantics
const arr = [1, 2, 3, 4, 5];
const folded = Array.fold((acc, x) => acc + x, 0, arr); // 15

Reactive Programming

Observable pattern and event system implementation.

import * as Observable from "fable-library/Observable.js";
import * as Event from "fable-library/Event.js";

// Observable operations
const mapped = Observable.map(x => x * 2, source);
const filtered = Observable.filter(x => x > 10, mapped);

// Event handling
const event = new Event();
event.Add(value => console.log(value));
event.Trigger("Hello");

Asynchronous Programming

Complete async programming infrastructure with cancellation support.

import * as Async from "fable-library/Async.js";
import { MailboxProcessor } from "fable-library/MailboxProcessor.js";

// Async operations
const computation = Async.sleep(1000);
const promise = Async.startAsPromise(computation);

// Actor model
const processor = MailboxProcessor.Start(async mailbox => {
    while (true) {
        const msg = await mailbox.Receive();
        console.log(`Received: ${msg}`);
    }
});
processor.Post("Hello Actor");

Data Encoding

Text encoding and binary data conversion utilities.

import * as Encoding from "fable-library/Encoding.js";
import * as BitConverter from "fable-library/BitConverter.js";

// Text encoding
const bytes = Encoding.toBytes("Hello World");
const text = Encoding.toString(bytes);

// Binary conversion
const intBytes = BitConverter.getBytesInt32(42);
const value = BitConverter.toInt32(intBytes, 0);

Type System

Runtime type information and reflection capabilities.

import * as Reflection from "fable-library/Reflection.js";

// Type construction
const stringType = Reflection.string_type;
const listType = Reflection.list(Reflection.int32_type);

// Type information
const fullName = Reflection.fullName(listType);
const generics = Reflection.getGenerics(listType);

External Integration

Integration with external JavaScript libraries and type definitions.

// BigDecimal support via big.js
import { Big } from "fable-library/lib/big.js";

const decimal1 = new Big("123.456");
const decimal2 = new Big("789.012");
const result = decimal1.plus(decimal2); // "912.468"

Character Operations

Unicode character classification and manipulation.

import * as Char from "fable-library/Char.js";

// Character classification
const isLetter = Char.isLetter("A"); // true
const isDigit = Char.isDigit("5"); // true
const category = Char.getUnicodeCategory("A"); // Letter category

// Case conversion
const upper = Char.toUpper("hello"); // "HELLO"

Configuration

Build configuration and module splitting setup for optimal JavaScript output.

{
  "compilerOptions": {
    "target": "ES2015",
    "module": "ES2015",
    "outDir": "../../build/fable-library",
    "strict": true
  }
}