Patterns of generic programming
Jeremy Gibbons describes seven patterns of generic programming, where each pattern is viewed as a different kind of parameterization. For more information, refer to Datatype-Generic Programming (available at http://www.cs.ox.ac.uk/jeremy.gibbons/publications/dgp.pdf).
Patterns 1 and 2 – functions
Functions parameterized by values are more general than functions with hardcoded values. This is the most simple kind of generic programming.
Functions parameterized by functions (higher order functions) represent a more powerful form of genericity.
Pattern 3 – polymorphic types and functions
Polymorphism can also be viewed as a pattern of generic programming. For example, when we parameterize types by other types (type polymorphism):
Tree a = Leaf a | Node a (Tree a) – is more generic than TreeI = Leaf Int | Node Int TreeI
Or when we parameterize functions by types (function polymorphism):
f :: Tree a → a – is more generic than g :: String → String