Some languages allow for classes and functions with type parameters (such as List<T> where T may be an arbitrary type). For example, you can have a function like:
List<S> Function<S, T>(List<T> list)
Some languages however allow this concept to be extended one level higher, allowing you to have a function with the signature:
K<S> Function<K<_>, S, T>(K<T> arg)
Where K<_> itself is a type like List<_> that has a type parameter. This "partial type" is known as a type constructor.
My question is, why do you need this ability? It makes sense to have a type like List<T> because all List<T> are almost exactly the same, but all the K<_> can be entirely different. You can have an Option<_> and a List<_> that have no common functionality at all.
Aucun commentaire:
Enregistrer un commentaire