graphs
A simple monadic graph library
A \"not-very-Haskelly\" API for calculating traversals of graphs that may be too large to fit into memory.
The algorithms included are inspired by the visitor concept of the
<http://www.boost.org/doc/libs/1_57_0/libs/graph/doc/visitor_concepts.html Boost Graph Library>.
Here is a very simple example of how we might execute a depth-first-search. In this case the visitor simply collects the edges and vertices in the order that the corresponding functions get called. After the necessary imports,
> import Data.Array
> import Data.Monoid
> import Data.Graph.AdjacencyList
> import Data.Graph.Algorithm
> import Data.Graph.Algorithm.DepthFirstSearch
create an adjacency list where the vertices are labeled with integers.
> graph :: Array Int [Int]
> graph = array (0, 3) [(0, [1,2]), (1, [3]), (2, [3]), (3, [])]
<<http://i.imgur.com/Pod1SH0.png>>
We need a data structure that instantiates `Monoid` to combine the results of
our visitor functions.
@
data Orderings = Orderings
  {  enterV :: [Int]
  , enterE :: [(Int, Int)]
  , gray :: [(Int, Int)]
  , exitV :: [Int]
  , black :: [(Int, Int)]
  } deriving Show
instance Monoid Orderings where
 mempty = Orderings [] [] [] [] []
 mappend (Orderings a1 a2 a3 a4 a5)(Orderings b1 b2 b3 b4 b5) =
  Orderings (a1 ++ b1) (a2 ++ b2) (a3 ++ b3) (a4 ++ b4) (a5 ++ b5)
@
The `dfs` function's first argument is of type `GraphSearch` which is
a visitor containing the functions to be run at various times during the search.
The second argument is the starting vertex for the search.
@
orderings :: GraphSearch (AdjacencyList Int) Orderings
orderings = GraphSearch
  (\\v -> return $ mempty {enterV = [v]})
  (\\e -> return $ mempty {enterE = [e]})
  (\\e -> return $ mempty {gray = [e]})
  (\\v -> return $ mempty {exitV = [v]})
  (\\e -> return $ mempty {black = [e]})
@
Finally `runAdjacencylist` unwraps the function in the `Adjacencylist` newtype and runs
it on `graph`.
> dfsTest :: Orderings
> dfsTest = runAdjacencyList (dfs orderings 0) graph
Running `dfsTest` in ghci will yield:
@
Orderings {enterV = [0,2,3,1], enterE = [(0,2),(2,3),(0,1)], gray = [], exitV = [3,2,1,0], black = [(1,3)]}
@
| version | uploaded | uploader | changes | |
|---|---|---|---|---|
| 0.7.3 | 2025-03-03 11:21 UTC | ryanglscott | +19/−58 lines, 14 filesdep −semigroupsdep ~basedep ~containersPVP: major bump suggested | |
| 0.7.2 | 2022-05-07 23:42 UTC | ryanglscott | 1 revisions | +52/−156 lines, 14 filesdep ~containersdep ~transformersPVP: major bump suggested |
| 0.7.1 | 2018-02-24 20:56 UTC | ryanglscott | 1 revisions | +180/−17 lines, 4 filesdep +semigroupsdep ~basedep ~containersnew-uploaderPVP: major bump suggested |
| 0.7 | 2016-01-17 03:09 UTC | EdwardKmett | 1 revisions | +115/−18 lines, 15 filesdep +transformers-compatdep ~basedep ~transformersPVP ok |
| 0.6.0.1 | 2015-01-10 22:10 UTC | EdwardKmett | +3/−3 lines, 1 filesdep ~arraydep ~transformersPVP ok | |
| 0.6 | 2015-01-10 20:34 UTC | EdwardKmett | +119/−148 lines, 12 files | |
| 0.5.0.1 | 2013-10-13 14:52 UTC | EdwardKmett | +3/−3 lines, 1 filesdep ~arraydep ~void | |
| 0.5 | 2013-09-05 13:53 UTC | EdwardKmett | +46/−9 lines, 8 filesPVP ok | |
| 0.4.1 | 2013-01-07 07:34 UTC | EdwardKmett | +1062/−1054 lines, 28 filesdep ~voidPVP ok | |
| 0.4.0.3 | 2012-05-11 21:52 UTC | EdwardKmett | +6/−2 lines, 2 filesdep ~arrayPVP ok | |
| 0.4.0.1 | 2012-05-08 23:22 UTC | EdwardKmett | +2/−2 lines, 1 filesdep ~containersPVP ok | |
| 0.4 | 2012-04-09 07:49 UTC | EdwardKmett | +8/−18 lines, 4 filesdep −data-defaultdep ~arraydep ~transformersdep ~voidPVP ok | |
| 0.3.2.3 | 2011-08-04 21:01 UTC | EdwardKmett | +5/−5 lines, 1 filesdep ~void | |
| 0.3.2.2 | 2011-07-26 22:14 UTC | EdwardKmett | +5/−1 lines, 1 files | |
| 0.3.2.1 | 2011-07-25 21:44 UTC | EdwardKmett | +2/−2 lines, 1 filesdep ~basePVP ok | |
| 0.3.2 | 2011-05-08 09:17 UTC | EdwardKmett | +2/−2 lines, 1 filesdep ~voidPVP ok | |
| 0.3.1 | 2011-01-25 17:28 UTC | EdwardKmett | +3/−3 lines, 2 filesdep ~basedep ~void | |
| 0.3 | 2011-01-22 12:09 UTC | EdwardKmett | 1 revisions | +5/−2 lines, 2 filesdep ~base |
| 0.2 | 2011-01-21 18:46 UTC | EdwardKmett | +274/−88 lines, 9 files | |
| 0.1 | 2011-01-21 17:39 UTC | EdwardKmett | +954/−0 lines, 16 filesdep +arraydep +basedep +containerssetup-changed |
Dependencies of graphs-0.7.3
array >=0.3 && <0.7 0.5.7.0 → 0.5.8.0
| 2024-09-08 07:13 UTC | 0.5.8.0 | +204/−8 lines, 6 filesdep ~basePVP ok |
| 2024-04-12 14:38 UTC | 0.5.7.0 | +34/−17 lines, 9 filesdep ~basePVP: major bump suggested |
| 2023-07-10 15:24 UTC | 0.5.6.0 | +159/−39 lines, 8 filesdep ~basenew-uploaderPVP ok |
| 2023-02-13 16:01 UTC | 0.5.5.0 | +8/−4 lines, 3 filesdep ~basenew-uploaderPVP ok |
| 2019-09-01 06:48 UTC | 0.5.4.0 | +33/−8 lines, 5 filesdep ~basesetup-changedPVP: major bump suggested |
showing 5 of 18 versions
base >=4.9 && <5 4.22.0.0 → 4.22.1.0
| 2026-12-01 12:38 UTC | 4.22.1.0 | +388/−6 lines, 9 filesdep ~ghc-internalPVP: major bump suggested |
| 2025-12-19 11:52 UTC | 4.22.0.0 | +886/−215 lines, 28 filesdep ~ghc-internalPVP ok |
| 2026-03-27 12:26 UTC | 4.21.2.0 | +10/−3 lines, 4 filesdep ~ghc-internalPVP ok |
| 2025-12-27 10:31 UTC | 4.21.1.0 | +17/−5 lines, 4 filesdep ~ghc-internalPVP ok |
| 2024-12-16 09:24 UTC | 4.21.0.0 | +1170/−396 lines, 39 filesdep ~ghc-internalPVP ok |
showing 5 of 61 versions
containers >=0.3 && <0.9 0.8 → 0.8.1
| 2026-10-04 06:08 UTC | 0.8.1 | +8085/−5169 lines, 39 filesdep +template-haskell-liftdep ~arraydep ~deepseqPVP: major bump suggested |
| 2025-03-01 13:03 UTC | 0.8 | +8447/−7031 lines, 37 filesnew-uploaderPVP ok |
| 2023-09-27 12:15 UTC | 0.7 | +76/−33 lines, 3 filesPVP ok |
| 2023-09-28 04:21 UTC | 0.6.8 | +644/−184 lines, 17 filesdep ~basedep ~deepseqPVP: major bump suggested |
| 2023-02-01 03:11 UTC | 0.6.7 | +783/−229 lines, 20 filesPVP: major bump suggested |
showing 5 of 43 versions
transformers >=0.2.2 && <0.7 0.6.2.0 → 0.6.3.0
| 2026-01-12 12:42 UTC | 0.6.3.0 | +28/−1 lines, 4 filesPVP: major bump suggested |
| 2025-04-06 22:39 UTC | 0.6.2.0 | +41/−42 lines, 8 filesdep ~ghc-primPVP: major bump suggested |
| 2024-09-25 11:37 UTC | 0.6.1.2 | +70/−21 lines, 19 filesPVP: minor bump suggested |
| 2023-08-01 19:13 UTC | 0.6.1.1 | +281/−42 lines, 11 filesPVP ok |
| 2023-02-04 08:15 UTC | 0.6.1.0 | +64/−4 lines, 8 filesPVP ok |
showing 5 of 42 versions
transformers-compat >=0.3 && <1 0.7.2 → 0.8
| 2026-01-11 02:47 UTC | 0.8 | +443/−4269 lines, 16 filesdep −faildep −generic-derivingdep −ghc-primdep ~basedep ~transformersPVP ok |
| 2022-06-26 13:13 UTC | 0.7.2 | +631/−184 lines, 3 filesdep ~basePVP: major bump suggested |
| 2021-10-30 16:41 UTC | 0.7.1 | +248/−3 lines, 5 filesPVP ok |
| 2021-07-25 11:45 UTC | 0.7 | +858/−277 lines, 13 filesdep ~transformersPVP ok |
| 2020-09-30 20:27 UTC | 0.6.6 | +275/−153 lines, 10 filesdep ~basePVP: major bump suggested |
showing 5 of 38 versions
void >=0.5.5.1 && <1 0.7.3 → 0.7.4
| 2025-12-08 12:14 UTC | 0.7.4 | +18/−337 lines, 6 filesdep −deepseqdep −ghc-primdep −hashablePVP ok |
| 2019-05-10 14:01 UTC | 0.7.3 | +198/−92 lines, 5 filesdep +template-haskellnew-uploaderPVP ok |
| 2017-03-25 04:22 UTC | 0.7.2 | +134/−19 lines, 4 filesPVP ok |
| 2015-09-13 18:16 UTC | 0.7.1 | +26/−7 lines, 6 filesdep +deepseqdep ~semigroupsPVP: major bump suggested |
| 2014-12-02 09:57 UTC | 0.7 | +123/−114 lines, 4 filesdep ~basePVP ok |
showing 5 of 27 versions
Reverse dependencies
1 packages depend on graphs