Hostname: page-component-6766d58669-wvcvf Total loading time: 0 Render date: 2026-05-21T13:40:34.788Z Has data issue: false hasContentIssue false

How much is in a square? Calculating functional programs with squares

Published online by Cambridge University Press:  26 February 2025

JOSE NUNO OLIVEIRA*
Affiliation:
HASLab - INESC TEC, University of Minho, Gualtar Campus, Building E7, Braga, Portugal (e-mail: jno@di.uminho.pt)
Rights & Permissions [Opens in a new window]

Abstract

Experience in teaching functional programming (FP) on a relational basis has led the author to focus on a graphical style of expression and reasoning in which a geometric construct shines: the (semi) commutative square. In the classroom this is termed the “magic square” (MS), since virtually everything that we do in logic, FP, database modeling, formal semantics and so on fits in some MS geometry. The sides of each magic square are binary relations and the square itself is a comparison of two paths, each involving two sides. MSs compose and have a number of useful properties. Among several examples given in the paper ranging over different application domains, free-theorem MSs are shown to be particularly elegant and productive. Helped by a little bit of Galois connections, a generic, induction-free theory for ${\mathsf{foldr}}$ and $\mathsf{foldl}$ is given, showing in particular that ${\mathsf{foldl} \, {{s}}{}\mathrel{=}\mathsf{foldr}{({flip} \unicode{x005F}{s})}{}}$ holds under conditions milder than usually advocated.

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, provided the original article is properly cited.
Copyright
© The Author(s), 2025. Published by Cambridge University Press
Submit a response

Discussions

No Discussions have been published for this article.