4 ms·
I don’t know if I can do an example in a common enough syntax to make sense. However, the general/basic example for higher kinded types is usually a Collection<
by throwaway17_17 5y ago
I don’t know if I can do an example in a common enough syntax to make sense. However, the general/basic example for higher kinded types is usually a Collection<T> vs a List<T>.
The List take some type T (i.e. int, float, char) and is a list of ‘objects’ of that type. Every ‘object in the list is an int.
A Collection<T> is a collection of some type <T<T2>> (i.e. list<T>, option<U>, vector<V>). This allows for the collection to be composed of ‘objects’ whose types are each some List<T> where each objects T can be different. So a Collection<List<T>> could be a list of [List<int>, List<float>, List<char>].
I think the jargony statement is that higher kinded types allow for a type to abstract over types which take another type as a constructor.
From my perspective the rationale for higher kinded type is usually the drive/goal of having as high a ceiling for abstraction as possible and create ‘reusable’ and generic code over and above what is available without higher kinded types.
- dgb23 5y agoTy! As the user of said collection: Are the underlying objects inferred when I look at them one by one?
- throwaway17_17 5y agoI would not expect the T type in a Collection<List<T>> to be used in a way where inference would be an issue. Typically, the type system would use parametric polymorphism to just deal with the Collection and then probably ‘pattern-match’ on the type inside a list.