Hostname: page-component-77f85d65b8-zzw9c Total loading time: 0 Render date: 2026-04-17T17:41:43.309Z Has data issue: false hasContentIssue false

A well-known representation of monoids and its application to the function ‘vector reverse’

Published online by Cambridge University Press:  08 August 2022

WOUTER SWIERSTRA*
Affiliation:
Utrecht University, Utrecht, Netherlands (e-mail: w.s.swierstra@uu.nl)
Rights & Permissions [Opens in a new window]

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.’

Information

Type
Functional Pearl
Creative Commons
Creative Common License - CCCreative Common License - BY
This is an Open Access article, distributed under the terms of the Creative Commons Attribution licence (https://creativecommons.org/licenses/by/4.0/), which permits unrestricted re-use, distribution, and reproduction in any medium, provided the original work is properly cited.
Copyright
© The Author(s), 2022. Published by Cambridge University Press
Supplementary material: File

Swierstra supplementary material

Swierstra supplementary material
Download Swierstra supplementary material(File)
File 15.2 KB
Submit a response

Discussions

No Discussions have been published for this article.