parametric polymorphism does: a function works for any type T without knowing what T is

Functions can work with any data type without knowing it!

Image: Thomas Kitchin, Public domain, via Wikimedia Commons

parametric polymorphism does: a function works for any type T without knowing what T is

Functions can work with any data type without knowing it!

Imagine writing a recipe that can be used for any dish, not just one specific meal.

Parametric polymorphism lets you write a recipe (function) that can adapt to any dish (type T) without changing the recipe itself.

Example

You write a "bake" function that can bake a cake, a pie, or a loaf of bread, just by changing the ingredients (type T).

Remember this

It's like having a universal recipe that fits any dish!

Related concepts

Swipe through 100 ML concepts daily

Open Pocket Polymath