Skip to content

A lightweight, no_std compatible library for emulating higher-kinded types in Rust.

License

Notifications You must be signed in to change notification settings

VoltagedDebunked/rusty-hkt

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

rusty-hkt

A lightweight, no_std compatible library for emulating higher-kinded types in Rust.

Overview

rusty-hkt provides traits and implementations that enable functional programming patterns requiring higher-kinded types, which are not natively supported in Rust's type system.

The library uses a trait-based approach to emulate higher-kinded types, allowing you to write generic code over type constructors such as Option, Result, Vec, and others.

Features

  • No standard library requirement: Works in no_std environments
  • Functional abstractions: Includes Functor, Applicative, and Monad traits
  • Built-in implementations for common Rust types:
    • Option
    • Result
    • Vec (requires the alloc feature)
    • Box (requires the alloc feature)
    • Identity (a simple wrapper type)
  • Zero dependencies beyond the Rust core library

Usage

Add this to your Cargo.toml:

[dependencies]
rusty-hkt = "0.1.0"

Basic Example

use rusty_hkt::{Functor, OptionHKT, map};

fn main() {
    let opt = Some(3);
    let doubled = map::<OptionHKT, _, _, _>(opt, |x| x * 2);
    assert_eq!(doubled, Some(6));
}

Working with Generic Type Constructors

use rusty_hkt::{Functor, HKT};

// A function that works with any Functor
fn double_inside<F: Functor, A>(fa: F::Applied<A>) -> F::Applied<A>
where
    A: std::ops::Mul<Output = A> + Copy,
{
    F::map(fa, |x| x * x)
}

// Can be used with Option, Result, Vec, etc.

License

Licensed under the Apache License, Version 2.0. See the LICENSE file for more info.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Contact

About

A lightweight, no_std compatible library for emulating higher-kinded types in Rust.

Topics

Resources

License

Stars

Watchers

Forks

Languages