Functional graphs

The best representation for a graph depends a little on the use case. The Graph type in containers uses an adjacency list and a few basic graph operations are provided.

One unique Haskell library, fgl, for Functional Graph Library, takes a different approach to programming with graphs, by considering graph as an inductive data-type.

One of the core ideas in fgl is contexts and decomposition. A context of a graph node is a triplet of the node's predecessors, successors, and the node itself. All graph manipulations can be expressed as inductive recursions over the contexts of a graph. Furthermore, it's surprisingly efficient.

For reference, here's a very, very small section of the fgl API:

-- module Data.Graph.Inductive.Graph type ...

Get Haskell High Performance Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.