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 standard library requirement: Works in
no_std
environments - Functional abstractions: Includes
Functor
,Applicative
, andMonad
traits - Built-in implementations for common Rust types:
Option
Result
Vec
(requires thealloc
feature)Box
(requires thealloc
feature)Identity
(a simple wrapper type)
- Zero dependencies beyond the Rust core library
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.
- GitHub: voltageddebunked
- Email: rusindanilo@gmail.com