Graphs and various graph-like combinatorial structures, such as preorders and hypergraphs, are ubiquitous in programming. This paper focuses on representing graphs in a purely functional programming language like Haskell. There are several existing approaches; one of the most recently developed ones is the "algebraic graphs" approach (2017). It uses an algebraic data type to represent graphs and has attracted users, including from industry, due to its emphasis on equational reasoning and making a common class of bugs impossible by eliminating internal invariants. The previous formulation of algebraic graphs did not support edge labels, which was a serious practical limitation. In this paper, we redesign the main algebraic data type and remove this limitation. We follow a fairly standard approach of parameterising a data structure with a semiring of edge labels. The new formulation is both more general and simpler: the two operations for composing graphs used in the previous work can now be obtained from a single operation by fixing the semiring parameter to zero and one, respectively. By instantiating the new data type with different semirings, and working out laws for interpreting the resulting expression trees, we discover an unusual algebraic structure, which we call "united monoids", that is, a pair of monoids whose unit elements coincide. We believe that it is worth studying united monoids in their full generality, going beyond the graphs which prompted their discovery. To that end, we characterise united monoids with a minimal set of axioms, prove a few basic theorems, and discuss several notable examples. We validate the presented approach by implementing it in the open-source *algebraic-graphs* library. Our theoretical contributions are supported by proofs that are included in the paper and have also been machine-checked in Agda. By extending algebraic graphs with support for edge labels, we make them suitable for a much larger class of possible applications. By studying united monoids, we provide a theoretical foundation for further research in this area.
翻译:图表和各种像图形的组合结构,例如预置图和高压图,在编程中无处不在。 本文侧重于以像哈斯凯尔这样的纯功能性编程语言代表图表。 有好几种现有方法; 最近开发的方法之一是“ 镜形图” (2017年) 。 它使用代数数据类型来代表图表, 吸引用户, 包括来自产业的用户, 因为它强调方程推理, 并且通过消除内部变异, 使得常见的错误类别变得不可能。 先前的代数图表的配方不支持边缘标签, 这是一种严重的实用限制。 在本文件中, 我们重新设计主代数数据类型数据类型, 并消除这一限制。 我们采用一种相当标准的参数来参数来代表图表。 新的配法既比较简单, 也比较简单易懂: 先前工作中使用的两种拼图的操作, 通过将最小值参数改为零和一个, 两种值的调法系, 我们用一个全新的数据类型来研究, 以不同的半数级数据类型来解释其直径结构 。 我们用一种正数的极值来解释一个直径, 。