  In this paper we investigate a ternary generalization of associativity by
defining a diagrammatic calculus of hypergraphs that extends the usual notions
of tensor networks, categories and relational algebras. In doing so we
rediscover the ternary structures known as heaps and are able to give a more
comprehensive treatment of their mergence in the context of dagger categories
and their generalizations. Our key insight is to approach associativity as a
confluence property of hypergraph rewrite systems. This approach allows us to
define a notion of ternary category and heapoid, where morphisms bind three
objects simultaneously, and suggests a systematic study of higher arity forms
of associativity.
