algebraic-edge-graphs: A library for algebraic edge-graph construction and transformation

[ algebra, algorithms, data-structures, graphs, library, mit ] [ Propose Tags ] [ Report a vulnerability ]

A library for algebraic construction and manipulation of edge-indexed graphs in Haskell. Based on the theory of algebraic edge graphs.

The top-level module EdgeGraph defines the core data type EdgeGraph.EdgeGraph which is a deep embedding of six graph construction primitives EdgeGraph.empty, EdgeGraph.edge, EdgeGraph.overlay, EdgeGraph.into, EdgeGraph.pits and EdgeGraph.tips. More conventional graph representations can be found in EdgeGraph.AdjacencyMap and EdgeGraph.Incidence.

The type classes defined in EdgeGraph.Class and EdgeGraph.HigherKinded.Class can be used for polymorphic graph construction and manipulation. Also see EdgeGraph.Fold that defines the Boehm-Berarducci encoding of algebraic edge graphs and provides additional flexibility for polymorphic graph manipulation.

This is an experimental library and the API will be unstable until version 1.0.0.


[Skip to Readme]

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

  • No Candidates
Versions [RSS] 0.1.0
Change log CHANGELOG.md
Dependencies array (>=0.5 && <0.8), base (>=4.9 && <5), containers (>=0.5 && <0.8) [details]
Tested with ghc ==9.6.6, ghc ==9.8.4, ghc ==9.10.1, ghc ==9.12.1
License MIT
Copyright Jack Liell-Cock, 2025-2026
Author Jack Liell-Cock <jackliellcock@gmail.com>
Maintainer Jack Liell-Cock <jackliellcock@gmail.com>
Uploaded by jackliellcock at 2026-03-16T19:46:06Z
Category Algebra, Algorithms, Data Structures, Graphs
Home page https://github.com/jacklc3/algebraic-edge-graphs
Bug tracker https://github.com/jacklc3/algebraic-edge-graphs/issues
Source repo head: git clone https://github.com/jacklc3/algebraic-edge-graphs.git
Distributions
Downloads 1 total (1 in the last 30 days)
Rating 2.0 (votes: 1) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2026-03-16 [all 1 reports]

Readme for algebraic-edge-graphs-0.1.0

[back to package description]

algebraic-edge-graphs

A library for algebraic construction and manipulation of edge-indexed graphs in Haskell. See this paper for the motivation behind the library and the underlying theory.

Installation

cabal install algebraic-edge-graphs

Getting started

The core data type is EdgeGraph, built from six primitives:

import EdgeGraph
import EdgeGraph.Class

-- A single edge labelled 1
e1 = edge 1 :: EdgeGraph Int

-- Two edges connected in sequence: 1 flows into 2
p = into (edge 1) (edge 2) :: EdgeGraph Int

-- A path through edges 1, 2, 3
p3 = path [1, 2, 3] :: EdgeGraph Int

-- Overlay places edges side by side (no connection)
disconnected = overlay (edge 1) (edge 2) :: EdgeGraph Int

-- A cycle through edges 1 and 2
c = circuit [1, 2] :: EdgeGraph Int

Folding over graphs

The EdgeGraph.Fold module provides semiring-based path algorithms via the Boehm-Berarducci encoding:

import EdgeGraph
import qualified EdgeGraph.Fold as F

-- Convert to Fold representation
g = into (edge 1) (edge 2) :: EdgeGraph Int
f = toFold g

-- Shortest paths using edge labels as weights
sp = F.shortestPaths id f

-- Widest (bottleneck) paths
wp = F.widestPaths id f

-- Reachability, cycle detection
r  = F.reachable f
ac = F.isAcyclic f

Adjacency map representation

For algorithms like DFS, topological sort, and strongly connected components, convert to AdjacencyMap:

import EdgeGraph
import qualified EdgeGraph.AdjacencyMap as AM

g = path [1, 2, 3] :: EdgeGraph Int
m = AM.fromEdgeGraph g

AM.topSort m   -- Just [1, 2, 3]
AM.dfsForest m -- depth-first search forest
AM.scc m       -- strongly connected components

Key modules

Module Description
EdgeGraph Core data type and graph operations
EdgeGraph.Class Type class for polymorphic graph construction
EdgeGraph.Fold Boehm-Berarducci encoding and semiring path algorithms
EdgeGraph.AdjacencyMap Adjacency map with DFS, topological sort, SCC
EdgeGraph.IntAdjacencyMap Int-specialised adjacency map
EdgeGraph.Incidence Incidence representation for node-level structure
EdgeGraph.HigherKinded.Class Higher-kinded type class for graph construction

Acknowledgements

This project was originally forked from Andrey Mokhov's algebraic-graphs library, the theory of which was provided in this paper. The codebase has changed substantially, but the original work provided the foundation for this project.