HKT2

Trait HKT2 

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

Re-exports the HKT2 trait for arity-2 Higher-Kinded Types. Trait for a Higher-Kinded Type (HKT) with two type parameters (arity 2).

This trait is generic over the first type parameter to be “fixed” (F). This allows the trait to represent a type constructor that is partially applied, leaving one generic parameter (T) open.

§Purpose

Useful for type constructors like Result<T, E> where E (the error type) can be fixed, allowing the Result to behave like an arity-1 HKT over T. This is crucial for integrating such types into functional programming patterns where only one type parameter is expected to vary.

§Type Parameters

  • F: The first generic type parameter that is fixed by the implementing witness.
  • T: The remaining generic type parameter that the type constructor operates on.

§Examples

use deep_causality_haft::{HKT2, Placeholder};

// A witness for Result<T, E> where E is fixed
pub struct ResultWitness<E>(Placeholder, E);

impl<E> HKT2<E> for ResultWitness<E> {
    type Type<T> = Result<T, E>;
}

type MyResult<T> = <ResultWitness<String> as HKT2<String>>::Type<T>;
let ok_value: MyResult<i32> = Ok(20);
assert_eq!(ok_value, Ok(20));

Required Associated Types§

Source

type Type<T>

The GAT that represents the remaining type constructor. The resulting kind is * -> * (one hole <T> remaining).

Example: If the implementing type is Result<(), F> and F is i32, then Type<T> is Result<T, i32>.

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<E> HKT2<E> for ResultWitness<E>

Source§

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