泛型

Generic programming centers around the idea of abstracting from concrete, efficient algorithms to obtain generic algorithms that can be combined with different data representations to produce a wide variety of useful software. — Musser, David R.; Stepanov, Alexander A., Generic Programming

泛型允许在强类型程序设计语言中编写代码时使用一些以后才指定的类型 (实例化时作为参数指明)

  • Originally coined by David Musser and Alexander Stepano, to describe a programming paradigm whereby fundamental requirements on types are abstracted from across concrete examples of algorithms and data structures and formalized as concepts, with generic functions implemented in terms of these concepts, typically using language genericity mechanisms as described above.
  • although the best known example is the Standard Template Library (stl), which developed a theory of iterators that is used to decouple sequence data structures and the algorithms operating on them.
  • ML 编程语言在 1973 年首创
  • Ada、Delphi、Eiffel、Java、C#、F#、Swift 和 Visual Basic .NET 称之为泛型(generics)
  • ML、Scala 和 Haskell 称之为参数多态(parametric polymorphism)
  • C++ 和 D 称之为模板

Refs