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 his article, Datatype-Generic Programming, which is 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
Types parameterized by other types are as follows:
Tree a = Leaf a | Node a (Tree a) – is more generic than TreeI = Leaf Int | Node Int TreeI
Functions parameterized by polymorphic types are as follows:
f :: Tree a → a – is more generic than g :: String → String
Pattern 4 – type-class polymorphism
In the...