// Kinds and higher-kinded type parameters (ADR 0018). trait Functor { fn map :: x: f g: fn(a) -> b / -> f / } impl Functor { fn map :: xs g { lmap xs g } } impl Functor fn incr_all :: x { map x fn n { n + 1 } } //~ TYPE incr_all: fn(a) -> a where Functor fn on_list :: { incr_all [1, 2] } //~ TYPE on_list: fn() -> List pub fn signature :: x: f -> f where Functor { map x show } pub type Twice { Twice(f, f) } //~ TYPE Twice: fn(f, f) -> Twice // The kind of a trait's argument must match its parameter's. impl Functor< Int //~^ ERROR E0213 `Int` with 0 type arguments has kind `Type`, but trait `Functor` expects kind `Type -> Type` here > { fn map :: x _ { x } } impl Functor< Result //~^ ERROR E0213 `Result` with 0 type arguments has kind `Type -> Type -> Type`, but trait `Functor` expects kind `Type -> Type` here > { fn map :: x _ { x } } pub fn wrong_constraint :: x: f -> Int where Show //~^ ERROR E0213 type variable `f` has kind `Type -> Type`, but it is used here with kind `Type` { 0 } pub fn applied_and_not :: x: t y: t -> Int //~^ ERROR E0213 type variable `t` has kind `Type -> Type`, but it is used here with kind `Type` { 0 } pub fn not_applied :: x: List -> Int //~^ ERROR E0201 `List` takes 1 type argument, but 0 were given { 0 } pub fn too_many :: x: Option -> Int //~^ ERROR E0201 `Option` takes 1 type argument, but 2 were given { 0 } // A variable is applied to types only: no `Type -> Type` argument. pub fn higher_order :: x: t -> Int //~^ ERROR E0201 `List` takes 1 type argument, but 0 were given { 0 } pub type Bad { Bad(f, f) //~^ ERROR E0213 type variable `f` has kind `Type -> Type`, but it is used here with kind `Type` } pub fn row_as_type :: x: e -> () / //~^ ERROR E0213 type variable `e` has kind `Type`, but it is used here with kind `Row` { () } pub fn mismatch :: x: Option -> List { map x fn n { n } //~ ERROR E0202 expected `List`, found `Option` } // `p` takes types only, so it cannot match `Twice`, // whose first parameter is a type constructor. trait Bifunctor

{ fn first :: x: p g: fn(a) -> b -> p } pub fn not_bifunctor :: t: Twice -> Int { first t fn x { x } //~ ERROR E0202 found `Twice` //~^ ERROR E0403 cannot tell which type should implement `Bifunctor` 0 } // A derived impl requires the trait only of parameters that are types. @derive Show pub type Wrapped //~ ERROR E0410 field of type `f` { Wrapped(f) } // `f` never matches a function or tuple type. pub fn not_a_constructor :: x: (Int, Int) -> (Int, Int) { map x fn n { n } //~ ERROR E0202 found `(Int, Int)` //~^ ERROR E0403 cannot tell which type should implement `Functor` //~^^ ERROR E0202 expected `(Int, Int)` } // A tuple is a type, not a type constructor. impl Functor< (a, b) //~^ ERROR E0213 a tuple has kind `Type`, but trait `Functor` expects kind `Type -> Type` > { fn map :: x _ { x } }