Algebraic structures, higher-kinded types and other category theory bad ideas

Overview

Algar

Crates.io Build docs-badge

Algebric structures, higher-kinded types and other category theory bad ideas.

Yes, you'll have generalized functors, applicatives, monads, traversable and much more in Rust at your fingertips. But no, they're not as ergonomic and beautiful as in Haskell, mainly because of the lack of higher-kinded types in Rust type-system.

Why?

I wrote this library for two reasons: first, mainly as a playground for learning Category Theory and Rust, second to see if it was even possible to implement such general abstract nonsense in Rust.

Does category theory make you a better programmer ?

I think it does. Category theory centers around abstraction and composition and I will argue strongly that abstraction and composition are the essence of programming.

Abstraction

Abstraction is essentially the core of computer science and exceptionally important in everyday programming: learning this sort of mathematics allows you to unlock a higher level of abstraction.

Since Category theory is the most abstract branch of math, it's no surprise that it lends itself to great programming abstractions and then to extremely useful programming ideas. Haskell programmers have been tapping this resource for a long time, and the ideas are percolating into other languages.

Composition

All software development is composition. The act of breaking a complex problem down to smaller parts, and then composing those smaller solutions together to form structures and patterns, hence your application, well that's what programming is all about.

We’ve been composing things forever, long before some great engineer came up with the idea of a subroutine. Some time ago the principles of structured programming revolutionized programming because they made blocks of code composable. Then came object oriented programming, which is all about composing objects. Functional programming is not only about composing functions and algebraic data structures — it makes concurrency composable — something that’s virtually impossible with other programming paradigms. -- Bartosz Milewski

Interested in learning more?

I heavely recommend:

Walking through those resources probably won't change your code overnight. Some people call it general abstract nonsense for a reason. That said, it does provide a nice framework for thinking about these abstract ideas, and is a recommended pursuit for all that are curious.

Prior Art

This library draws heavy inspiration from mathematics and other Rust and Elixir libraries: let me mention them here.

The Witchcraft Elixir library is why I started this journey.

Fp-core.rs and higher have been invaluable resources to help me to port category theory concepts in Rust.

The Fantasy Land Spec is a spec for projects such as this one, but targeted at Javascript. It does not come with its own implementation, but provides a helpful chart of class hierarchies.

Obviously the Haskell Prelude deserves mention. Haskell has inspired so many programmers to write clean, declarative, functional code based on principled abstractions.

You might also like...
A set of Zero Knowledge modules, written in Rust and designed to be used in other system programming environments.

Zerokit A set of Zero Knowledge modules, written in Rust and designed to be used in other system programming environments. Initial scope Focus on RLN

Compile-time stuff and other goodies for rustaceans 🦀

🥯 bagel: Always baked, never fried bagel is a collection of macros and other things that we frequently use at Skytable, primarily to get work done at

Rust library for compiling and running other programs.

Exers 💻 Exers is a rust library for compiling and running code in different languages and runtimes. Usage example fn main() { // Imports...

👌 A smol functional language that targets other languages

ditto A small, pure functional language that targets other languages. Syntax highlighting coming soon Elevator pitch ⏱️ Ditto is a mashup of my favour

rust channel benchmarks to keep stat of performance of Kanal library in comparison with other competitors.
rust channel benchmarks to keep stat of performance of Kanal library in comparison with other competitors.

Rust Channel Benchmarks This is a highly modified fork of the crossbeam-channel benchmarks. to keep track of Kanal library stats in comparison with ot

A typemap for a set of known types optionally without heap allocation, and supporting iterating by traits

fixed_typemap docs.rs GitHub Sponsors Implements typemaps that support a lot of extra funcctionality using procedural macros. docs.rs has a lot more t

A library for transcoding between bytes in Astro Notation Format and Native Rust data types.

Rust Astro Notation A library for transcoding between hexadecimal strings in Astro Notation Format and Native Rust data types. Usage In your Cargo.tom

Custom deserialization for fields that can be specified as multiple types.

serde-this-or-that Custom deserialization for fields that can be specified as multiple types. This crate works with Cargo with a Cargo.toml like: [dep

Idiomatic Rust implementations for various Windows string types (like UNICODE_STRING)
Idiomatic Rust implementations for various Windows string types (like UNICODE_STRING)

nt-string by Colin Finck [email protected] Provides idiomatic Rust implementations for various Windows string types: NtUnicodeString (with NtUnicode

Releases(v0.3.0)
Owner
Stefano Candori
Software engineer passionate about open source and everything related to bits and bytes
Stefano Candori
An implementation of a predicative polymorphic language with bidirectional type inference and algebraic data types

Vinilla Lang Vanilla is a pure functional programming language based on System F, a classic but powerful type system. Merits Simple as it is, Vanilla

Zehao Chen 73 Aug 4, 2022
A mobile application platform for tertiary students to communicate, collaborate and share ideas with each other

Qreeket (pronounced "cricket") A mobile application platform for tertiary students to communicate, collaborate and share ideas with each other. As the

Quabynah Bilson Jr. 3 May 15, 2023
Messing around with delimited continuations, fibers, and algebraic effects

A Simple Virtual Machine with Effects Each thread of execution in this VM is called a Fiber. A Fiber is unique, can be sent between threads, but can n

Isaac Clayton 8 Jun 23, 2022
Extending mincaml with "fun" PL ideas.

wowcaml This is a fork of this Rust implementation of mincaml - a compiler for a call-by-value ML-like language, updated to recent versions of craneli

McCoy R. Becker 4 Jul 14, 2022
Bad Apple!! music video on WASM-4

w4-bad-apple Bad Apple!! music video on the WASM-4 fantasy console. Building First, you need to create a frames directory containing an image for each

Mark Carlson 7 Jul 2, 2022
Higher-level toolkit for MSDF text rendering

MSDF Toolkit Higher-level toolkit for MSDF text rendering About MSDF - an abbreviation of Multi-channel Signed Distance Field. In short, an efficient

null 2 Aug 19, 2022
Data structures and algorithms for 3D geometric modeling.

geom3d Data structures and algorithms for 3D geometric modeling. Features: Bezier curve and surface B-Spline curve and surface Spin surface Sweep surf

Junfeng Liu 31 Sep 20, 2022
Library and proc macro to analyze memory usage of data structures in rust.

Allocative: memory profiler for Rust This crate implements a lightweight memory profiler which allows object traversal and memory size introspection.

Meta Experimental 19 Jan 6, 2023
Construct complex structures within single call + simple compile-time meta-inheritance model with mixins.

Introduction constructivism is a Rust sample-library designed to simplify the construction of structured data by defining and manipulating sequences o

polako.rs 5 Oct 24, 2023