HKT

Trait HKT 

Source
pub trait HKT {
    type Type<T>;
}
Expand description

Re-exports the core HKT trait for arity-1 Higher-Kinded Types. Trait for a Higher-Kinded Type (HKT) with one type parameter (arity 1).

This trait is implemented by a concrete “witness” type (e.g., OptionWitness) which serves as a token to refer to a type constructor (e.g., Option<T>). The Type<T> associated type defines the actual type constructor, with <T> representing the single generic parameter that can vary.

§Purpose

Enables writing generic code that can operate over different type constructors (like Option, Vec, Result with a fixed error type) without knowing their concrete inner type. This is a core building block for functional programming abstractions like Functor, Applicative, and Monad in Rust.

§Type Parameters

  • T: The generic type parameter that the type constructor operates on.

Required Associated Types§

Source

type Type<T>

The Generic Associated Type (GAT) that represents the type constructor. The <T> is the “hole” in the type constructor (e.g., Option<T>).

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl HKT for OptionWitness

Source§

type Type<T> = Option<T>

Source§

impl HKT for VecWitness

Source§

type Type<T> = Vec<T>

Source§

impl<E> HKT for ResultWitness<E>

Source§

type Type<T> = Result<T, E>

Source§

impl<E, W> HKT for MyEffectHktWitness<E, W>

Source§

type Type<T> = MyCustomEffectType<T, E, W>

Source§

impl<F1, F2, F3> HKT for MyEffectHktWitness4<F1, F2, F3>

Source§

type Type<T> = MyCustomEffectType4<T, F1, F2, F3>

Source§

impl<F1, F2, F3, F4> HKT for MyEffectHktWitness5<F1, F2, F3, F4>

Source§

type Type<T> = MyCustomEffectType5<T, F1, F2, F3, F4>