Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
L

language-ext

> 数据库
Open source

C# pure functional programming framework - come and get declarative!

7.1K stars0 likes2 views
WebsiteGitHub

About

C# pure functional programming framework - come and get declarative!

C# Functional Programming Language Extensions

This library uses and abuses the features of C# to provide a pure functional-programming framework that, if you squint, can look like extensions to the language itself. The desire here is to make programming in C# much more robust by helping the engineer's inertia flow in the direction of declarative and pure functional code rather than imperative. Using these techniques for large code-bases can bring tangible benefits to long-term maintenance by removing hidden complexity and by easing the engineer's and team's cognitive load. Author on...

  • Blog: Notes from a Small Functional Island
  • Bluesky: @paullouth.bsky.social
  • Mastodon: @[email protected]
  • Github ReadME project: 'Functional programming is finally going mainstream'

Contents

  • Reference
  • Nu-get package
  • Getting started
  • Prologue
  • Features
    • Functional effects and IO
    • Atomic concurrency, shared state, and collections
    • Immutable collections
    • Functional streams
    • Optional and Alternative value monads
    • State managing monads
    • Parser combinators
    • Pretty: Produce nicely formatted text with smart layouts
    • Differencing
    • Traits
    • Value traits
  • Contributing & Code of Conduct

Reference

  • API Reference
  • Issues that contain documentation and examples

Nu-get

Nu-get package Description
LanguageExt.Parsec Port of the Haskell parsec library
LanguageExt.Streaming A set of compositional streaming types
LanguageExt.FSharp F# to C# interop package. Provides interop between the LanguageExt.Core types (like Option, List and Map) to the F# equivalents, as well as interop between core BCL types and F#
LanguageExt.Parsec Port of the Haskell parsec library
LanguageExt.Rx Reactive Extensions support for various types within the Core
LanguageExt.Sys Provides an effects wrapper around the .NET System namespace making common IO operations pure and unit-testable

Getting started

To use this library, simply include LanguageExt.Core.dll in your project or grab it from NuGet. It is also worth setting up some global using for your project. This is the full list that will cover all functionality and bring it into scope:

csharp
global using LanguageExt;
global using LanguageExt.Common;
global using LanguageExt.Traits;
global using LanguageExt.Effects;
global using LanguageExt.Streaming;
global using LanguageExt.Pretty;
global using LanguageExt.Traits.Domain;
global using static LanguageExt.Prelude;

A minimum, might be:

csharp
global using LanguageExt;
global using static LanguageExt.Prelude;

The namespace LanguageExt contains most of the core types; LanguageExt.Prelude contains the functions that bring into scope the prelude functions that behave like standalone functions in ML style functional programming languages; LanguageExt.Traits brings in the higher-kinded trait-types and many extensions; LanguageExt.Common brings in the Error type and predefined Errors.

Prologue

From C# 6 onwards we got the ability to treat static classes like namespaces. This means that we can use static methods without qualifying them first. That instantly gives us access to single term method names that look exactly like functions in ML-style functional languages. i.e.

csharp
    using static System.Console;
    
    WriteLine("Hello, World");

This library tries to bring some of the functional world into C#. It won't always sit well with the seasoned C# OO programmer, especially the choice of camelCase names for a lot of functions and the seeming 'globalness' of a lot of the library.

I can understand that much of this library is non-idiomatic, but when you think of the journey C# has been on, is "idiomatic" necessarily right? A lot of C#'s idioms are inherited from Java and C# 1.0. Since then we've had generics, closures, Func, LINQ, async... C# as a language is becoming more and more like a functional language on every release. In fact, the bulk of the new features are either inspired by or directly taken from features in functional languages. So perhaps it's time to move the C# idioms closer to the functional world's idioms?

My goal with this library is very much to create a whole new community within the larger C# community. This community is not constrained by the dogma of the past or by the norms of C#. It understands that the OOP approach to programming has some problems and tries to address them head-on.

And for those that say "just use F#" or "just use Haskell", sure, go do that. But it's important to remember that C# has a lot going for it:

  • Incredible investment into a state-of-the art compiler
  • Incredible tooling (Visual Studio and Rider)
  • A large ecosystem of open-source libraries
  • A large community of developers already using it
    • This is also very important for companies that hire engineers
  • It is a functional programming language! It has first-class functions, lambdas, etc.
    • And with this library it has a functional-first Base Class Library

A note about naming

One of the areas that's likely to get seasoned C# heads worked up is my choice of naming style. The intent is to try and make something that feels like a functional language rather than following rules of naming conventions (mostly set out by the BCL).

There is, however, a naming guide that will keep you in good stead while reading through this documentation:

  • Type names are PascalCase in the normal way
  • The types all have constructor functions rather than public constructors that you instantiate with new. They will always be PascalCase:
csharp
    Option<int> x = Some(123);
    Option<int> y = None;
    Seq<int> items = Seq(1,2,3,4,5);
    List<int> items = List(1,2,3,4,5);
    HashMap<int, string> dict = HashMap((1, "Hello"), (2, "World"));
    Map<int, string> dict = Map((1, "Hello"), (2, "World"));
  • Any (non-type constructor) static function that can be used on its own by using static LanguageExt.Prelude are camelCase.
csharp
    var x = map(opt, v => v * 2);
  • Any extension methods, or anything "fluent" are PascalCase in the normal way
csharp
    var x = opt.Map(v => v * 2);

Even if you disagree with this non-idiomatic approach, all of the camelCase static functions have fluent variants, so you never actually have to see the non-standard stuff.

Features

Functional effects and IO

Location Feature Description
Core IO<A> A synchronous and asynchronous side-effect: an IO monad
Core Eff<A> A synchronous and asynchronous side-effect with error handling
Core Eff<RT, A> Same as Eff<A> but with an injectable runtime for dependency-injection: a unit testable IO monad

Atomic concurrency and collections

Location Feature Description
Core Atom<A> A lock-free atomically mutable reference for working with shared state
Core Ref<A> An atomic reference to be used in the transactional memory system
Core AtomHashMap<K, V> An immutable HashMap with a lock-free atomically mutable reference
Core AtomSeq<A> An immutable Seq with a lock-free atomically mutable reference
Core VectorClock<A> Understand distributed causality
Core VersionVector<A> A vector clock with some versioned data
Core VersionHashMap <ConflictV, K, V> Distrubuted atomic versioning of keys in a hash-map

Immutable collections

Location Feature Description
Core Arr<A> Immutable array
Core Seq<A> Lazy immutable list, evaluate at-most-once - very, very fast!
Core Iterable<A> [Wrapper around `IEn

Issues· 15 open

View all issuesOpen on GitHub
  • #1558

    yieldAll with source breaks consumer IO

    Updated May 22, 2026
  • #1545

    Idea: ExpressionLens<A, B>

    Updated Apr 3, 2026
  • #1538

    LanguageExt.QueryExtensions.Distinct<T> conflicts with IQueryable.Distinct

    Updated Jan 28, 2026
  • #1535

    MultiListenerPureSourceT doesn't cleanup internal listeners upon repeated invocation of ReduceInternalM

    Updated Jan 12, 2026
  • #1478

    Proposal: add a TakeUntil for Seq

    Updated Jun 17, 2025
  • #1477

    Set repo url in Nuget package

    Updated Jun 9, 2025
  • #1472

    Issues in the blog

    Updated May 21, 2025
  • #924

    Idea: Use Source Generators to rewrite LINQ expressions

    ideav5Updated Oct 24, 2024
  • #1012

    Prelude timeout does not use the HasTime<RT> runtime trait

    enhancementv5v4Updated Oct 24, 2024
  • #1097

    `Atom().Change` fires always

    enhancementv5v4Updated Oct 24, 2024

> Tags

C#ad-hoc-polymorphismapplicativebclc-sharp

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 22, 2026
Category数据库
PricingOpen source

> Related tools

P
PostgreSQL
功能强大的开源关系型数据库
R
Redis
内存数据结构存储,常用作缓存与队列
M
MySQL
广泛使用的开源关系型数据库