| Crates.io | rusty-hkt |
| lib.rs | rusty-hkt |
| version | 0.1.0 |
| created_at | 2025-03-01 17:51:21.902756+00 |
| updated_at | 2025-03-01 17:51:21.902756+00 |
| description | Higher-kinded types for Rust |
| homepage | |
| repository | https://github.com/voltageddebunked/rusty-hkt |
| max_upload_size | |
| id | 1573920 |
| size | 22,162 |
A lightweight, no_std compatible library for emulating higher-kinded types in Rust.
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.
no_std environmentsFunctor, Applicative, and Monad traitsOptionResultVec (requires the alloc feature)Box (requires the alloc feature)Identity (a simple wrapper type)Add this to your Cargo.toml:
[dependencies]
rusty-hkt = "0.1.0"
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));
}
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.
Licensed under the Apache License, Version 2.0. See the LICENSE file for more info.
Contributions are welcome! Please feel free to submit a Pull Request.