| Crates.io | overengineered_hkts |
| lib.rs | overengineered_hkts |
| version | 0.1.1 |
| created_at | 2025-11-24 19:12:16.273014+00 |
| updated_at | 2025-11-24 19:28:23.598426+00 |
| description | Expiremental crate of higher-kinded types integrated with lifetimes and matching function types and optional cloning and supporting no_std. |
| homepage | |
| repository | https://github.com/ArsenalAlex108/overengineered_hkt |
| max_upload_size | |
| id | 1948443 |
| size | 279,656 |
Expiremental crate of higher-kinded types integrated with lifetimes and matching function types and optional cloning and supporting no_std.
There 4 base Hkts with the base root as an example:
/// `'t` is some arbitrary bound that always outlive every other bound in the hkt so that it can be used as a bound in some places where `'static` is the only other option
pub trait UnsizedHkt<'t>: 't {
/// Definition: F<'a, A: 't>: 'a (where 't: 'a is logical but maybe unnecessary)
///
/// Requirements:
/// - Invariant over 'a and A and 't
type UnsizedF<'a, A: 'a>: 'a + ?Sized
where
't: 'a;
}
Each can be succintly described as:
Beware that although all type implementing these traits but share the same Self::F<'a, A> between implementations, that invariant is currently not enforced at compile time between hkts where A is ?Sized and ones where A is Sized.
Out of the 4 traits, Hkt receives the most attention for obvious reasons.
Here's an example of a type implementing all traits:
pub struct BoxT<TInner = IdHkt>(Infallible, PhantomData<TInner>);
impl<'t, TInner: UnsizedHkt<'t>> Hkt<'t> for BoxT<TInner> {
type F<'a, A: 'a>
= Box<TInner::UnsizedF<'a, A>>
where
't: 'a;
}
impl<'t, TInner: UnsizedHktUnsized<'t>> HktUnsized<'t> for BoxT<TInner> {
type FUnsized<'a, A: 'a + ?Sized>
= Box<TInner::UnsizedFUnsized<'a, A>>
where
't: 'a;
}
impl<TInner> HktClassification for BoxT<TInner> {
type Choice = hkt_classification::OuterHkt;
}
The hkt being generic over the inner hkt allows hkt stacking to describe pretty any types as Self::F<'a, A>. Implementing HktClassification with Choice = hkt_classification::OuterHkt will add blanket implementations of UnsizedHkt and UnsizedHktUnsized too - though the other Choice types are currently unused.
TODO
Due to how Rust memory layout is implemented, transmuting between Self::F<'a, A> and Self::F<'a, B> is not safe even if A can be transmuted to B due to different layout monomorphisation. However transmutation is always safe if it is known at compile time that A == B, since objects of the same Sized type obviously have the same memory layout.
TODO
This library was inspired by the C# library language-ext. Some implementations were transcribed from their C# implementation since I can't read Haskell.