3 ms·
To add to what everyone else is saying, higher kinded types (HKTs) are what make monadic code really reusable. It lets you write code that is polymorphic over a
by ianhorn 6y ago
To add to what everyone else is saying, higher kinded types (HKTs) are what make monadic code really reusable. It lets you write code that is polymorphic over a variable kind of monad, rather than code that works for a specific monad like a list. Without HKTs, you might have a polymorphic type signature List[<T>] of a list of some variable kind of elements, or a Set[<T>], or a Maybe[<T>]. In haskell syntax it's List a, Set a, Maybe a.
When you write code that operates on something like a monad, without caring about what the monad is, you want code that has a type like <T1>[<T2>]. In haskell syntax, it's m a. <T1> (or m) in this case is a type that takes another type as an argument to complete a concrete type. AFAIK, rust doesn't have type variables that take type variables (or types) as arguments like that.