HORIZON HASKELLDocslts/ghc-9.14.xd82dee82026-10-12Search names, modules, packages, or :: a typeCtrl K

GHC 9.14.1 · lts/ghc-9.14.x · d82dee8 · 2026-10-12

Modulealgebraic-graphs-0.8Haskell2010

Algebra.Graph.Export.Dot

Alga is a library for algebraic construction and manipulation of graphs in Haskell. See this paper for the motivation behind the library, the underlying theory, and implementation details.

This module defines functions for exporting graphs in the DOT file format.

  • 3 types
  • 5 values

Graph attributes and style

5 declarations
datadata Attribute s
#

An attribute is just a key-value pair, for example "shape" := "box". Attributes are used to specify the style of graph elements during export.

Constructors

datadata Style a s
#

The record Style a s specifies the style to use when exporting a graph in the DOT format. Here a is the type of the graph vertices, and s is the type of string to represent the resulting DOT document (e.g. String, Text, etc.). The only field that has no obvious default value is vertexName, which holds a function of type a -> s to compute vertex names. See the function export for an example.

Constructors

valuedefaultStyle :: Monoid s => (a -> s) -> Style a s
#

Default style for exporting graphs. The vertexName field is provided as the only argument; the other fields are set to trivial defaults.

Export functions

3 declarations
valueexport
  1. :: (IsString s, Monoid s, Ord a, ToGraph g, ToVertex g ~ a)
  2. => Style a s
  3. -> g
  4. -> s
#

Export a graph with a given style.

For example:

style :: Style Int String
style = Style
    { graphName               = "Example"
    , preamble                = ["  // This is an example", ""]
    , graphAttributes         = ["label" := "Example", "labelloc" := "top"]
    , defaultVertexAttributes = ["shape" := "circle"]
    , defaultEdgeAttributes   = mempty
    , vertexName              = \x   -> "v" ++ show x
    , vertexAttributes        = \x   -> ["color" := "blue"   | odd x      ]
    , edgeAttributes          = \x y -> ["style" := "dashed" | odd (x * y)]
    , attributeQuoting        = DoubleQuotes }

> putStrLn $ export style (1 * 2 + 3 * 4 * 5 :: Graph Int)

digraph Example
{
  // This is an example

  graph [label="Example" labelloc="top"]
  node [shape="circle"]
  "v1" [color="blue"]
  "v2"
  "v3" [color="blue"]
  "v4"
  "v5" [color="blue"]
  "v1" -> "v2"
  "v3" -> "v4"
  "v3" -> "v5" [style="dashed"]
  "v4" -> "v5"
}