A well-known representation of monoids and its application to the function 'vector reverse': Functional Pearl
Publication date
2022
Editors
Advisors
Supervisors
Document Type
Article
Metadata
Show full item recordCollections
License
cc_by
Abstract
Vectors—or length-indexed lists—are classic example of a dependent type. Yet, most tutorials stay clear of any function on vectors whose definition requires non-trivial equalities between natural numbers to type check. This pearl shows how to write functions, such as vector reverse, that rely on monoidal equalities to be type correct without having to write any additional proofs. These techniques can be applied to many other functions over types indexed by a monoid, written using an accumulating parameter, and even be used to decide arbitrary equalities over monoids ‘for free.’
Keywords
Citation
Swierstra, W 2022, 'A well-known representation of monoids and its application to the function 'vector reverse': Functional Pearl', Journal of Functional Programming, vol. 32, pp. 1-16. https://doi.org/10.1017/S0956796822000065