Module lambek::type_app[][src]

Expand description

Traits for the kind of unary type application, Type -> Type.

Higher kinded types (HKT) such as Type -> Type are not natively supported in Rust. As such, we cannot use type constructors such as Vec without applying a specific type as an argument, e.g. Vec<u8>. Although the upcoming generic associated types (GAT) feature will partially solve this issue, the feature is not yet stable and may subject to changes. An alternative approach is to use defunctionalization to encode regular Rust types to have kinds other than Type. TypeApp is one such trait for encoding types of kind Type -> Type.

To promote a type constructor such as Vec to HKT, we define a proxy type VecF and implement TypeCon and TypeApp for them. We then use VecF as the unapplied version of Vec in our code. Inside type signatures, we use App<VecF, X> to apply VecF to a type X. App<VecF, X> is isomorphic to Vec<X>, and we can convert a value xs: App<VecF, X> back into Vec<X> by calling xs.get_applied().

The type App encapsulates the TypeApp constraint using HasTypeApp. With that, type signatures that use App<F, X> do not need to have TypeApp<F, X> in their trait bounds. This makes it significantly easier to perform arbitrary type applications without having to worry about polluting the trait bounds with TypeApp constraints. See Functor for a practical use of App.

Structs

Newtype for a boxed value of HasTypeApp.

App<Const<A>, X> ~ A

App<ResultF<E>, X> ~ Result<E, X>

Enums

App<Identity, X> ~ X

App<OptionF, X> ~ Option<X>

App<VecF, X> ~ Vec<X>

Traits

Encapsulates an applied type into a trait object to prevent TypeApp constraints from propagating to type signatures.

A type F: TypeApp<X> have the associated type Applied as the result of applying a type F of kind Type -> Type to X.

A proxy type F: TypeCon to mark itself as having the kind Type -> Type.

Functions

Wraps a type FX into App in the presence of the TypeApp constraint, allowing subsequent use of App to not depend on TypeApp.

Type Definitions