HORIZON HASKELLDocslts/ghc-9.10.xc74966e2026-09-27Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · c74966e · 2026-09-27

Moduleghc-9.10.3GHC2021

GHC.Data.Graph.Inductive.Graph

Static and Dynamic Inductive Graphs

Code is from Hackage fgl package version 5.7.0.3

  • 17 types
  • 2 classes
  • 65 values
  • Packageghc-9.10.3
  • Exports84
  • LanguageGHC2021
  • LicenceBSD-3-Clause
  • SourceGraph.hs

General Type Defintions

0 declarations

Node and Edge Types

Types Supporting Inductive Graph View

typetype Adj b = [(b, Node)]
#

Labeled links to or from a Node.

typetype Context a b = (Adj b, Node, a, Adj b)
#

Links to the Node, the Node itself, a label, links from the Node.

In other words, this captures all information regarding the specified Node within a graph.

newtypenewtype LPath a
#

Labeled path

Constructors

Instances3Eq, Ord, Show
  • Eq a => Eq (LPath a)Defined in ghc-9.10.3 · GHC.Data.Graph.Inductive.Graph
  • Ord a => Ord (LPath a)Defined in ghc-9.10.3 · GHC.Data.Graph.Inductive.Graph
  • Show a => Show (LPath a)Defined in ghc-9.10.3 · GHC.Data.Graph.Inductive.Graph

Graph Type Classes

2 declarations

We define two graph classes:

Graph: static, decomposable graphs. Static means that a graph itself cannot be changed

DynGraph: dynamic, extensible graphs. Dynamic graphs inherit all operations from static graphs but also offer operations to extend and change graphs.

Each class contains in addition to its essential operations those derived operations that might be overwritten by a more efficient implementation in an instance definition.

Note that labNodes is essentially needed because the default definition for matchAny is based on it: we need some node from the graph to define matchAny in terms of match. Alternatively, we could have made matchAny essential and have labNodes defined in terms of ufold and matchAny. However, in general, labNodes seems to be (at least) as easy to define as matchAny. We have chosen labNodes instead of the function nodes since nodes can be easily derived from labNodes, but not vice versa.

classclass Graph (gr :: Type -> Type -> Type) where
#

Minimum implementation: empty, isEmpty, match, mkGraph, labNodes

Methods

Instances1Graph
  • Graph GrDefined in ghc-9.10.3 · GHC.Data.Graph.Inductive.PatriciaTree
classclass Graph gr => DynGraph (gr :: Type -> Type -> Type) where
#

Methods

  • (&) :: Context a b -> gr a b -> gr a b

    Merge the Context into the DynGraph.

    Context adjacencies should only refer to either a Node already in a graph or the node in the Context itself (for loops).

    Behaviour is undefined if the specified Node already exists in the graph.

Instances1DynGraph
  • DynGraph GrDefined in ghc-9.10.3 · GHC.Data.Graph.Inductive.PatriciaTree

Operations

2 declarations
valuesize :: Graph gr => gr a b -> Int
#

The number of edges in the graph.

Note that this counts every edge found, so if you are representing an unordered graph by having each edge mirrored this will be incorrect.

If you created an unordered graph by either mirroring every edge (including loops!) or using the undir function in Data.Graph.Inductive.Basic then you can safely halve the value returned by this.

Graph Folds and Maps

valueufold :: Graph gr => (Context a b -> c -> c) -> c -> gr a b -> c
#

Fold a function over the graph by recursively calling match.

valuenmap :: DynGraph gr => (a -> c) -> gr a b -> gr c b
#

Map a function over the Node labels in a graph.

valueemap :: DynGraph gr => (b -> c) -> gr a b -> gr a c
#

Map a function over the Edge labels in a graph.

valuenemap :: DynGraph gr => (a -> c) -> (b -> d) -> gr a b -> gr c d
#

Map functions over both the Node and Edge labels in a graph.

Graph Projection

Graph Construction and Destruction

valuedelEdge :: DynGraph gr => Edge -> gr a b -> gr a b
#

Remove an Edge from the Graph.

NOTE: in the case of multiple edges, this will delete all such edges from the graph as there is no way to distinguish between them. If you need to delete only a single such edge, please use delLEdge.

valuedelLEdge :: (DynGraph gr, Eq b) => LEdge b -> gr a b -> gr a b
#

Remove an LEdge from the Graph.

NOTE: in the case of multiple edges with the same label, this will only delete the first such edge. To delete all such edges, please use delAllLedge.

Subgraphs

valuenfilter :: DynGraph gr => (Node -> Bool) -> gr a b -> gr a b
#

Returns the subgraph only containing the nodes which satisfy the given predicate.

valuelabnfilter :: Graph gr => (LNode a -> Bool) -> gr a b -> gr a b
#

Returns the subgraph only containing the labelled nodes which satisfy the given predicate.

valuelabfilter :: DynGraph gr => (a -> Bool) -> gr a b -> gr a b
#

Returns the subgraph only containing the nodes whose labels satisfy the given predicate.

valuesubgraph :: DynGraph gr => [Node] -> gr a b -> gr a b
#

Returns the subgraph induced by the supplied nodes.

Graph Inspection

valuelsuc :: Graph gr => gr a b -> Node -> [(Node, b)]
#

Find all Nodes that are linked from the given Node and the label of each link.

valuelpre :: Graph gr => gr a b -> Node -> [(Node, b)]
#

Find all Nodes that link to the given Node and the label of each link.

valuehasEdge :: Graph gr => gr a b -> Edge -> Bool
#

Checks if there is a directed edge between two nodes.

Context Inspection

Pretty-printing

2 declarations
valueprettify :: (DynGraph gr, Show a, Show b) => gr a b -> String
#

Pretty-print the graph. Note that this loses a lot of information, such as edge inverses, etc.

Ordering of Graphs

1 declaration
newtypenewtype OrdGr (gr :: k -> k1 -> Type) (a :: k) (b :: k1)
#

OrdGr comes equipped with an Ord instance, so that graphs can be used as e.g. Map keys.

Constructors

Instances4Eq, Ord, Read, Show
  • (Graph gr, Ord a, Ord b) => Eq (OrdGr gr a b)Defined in ghc-9.10.3 · GHC.Data.Graph.Inductive.Graph
  • (Graph gr, Ord a, Ord b) => Ord (OrdGr gr a b)Defined in ghc-9.10.3 · GHC.Data.Graph.Inductive.Graph
  • Read (gr a b) => Read (OrdGr gr a b)Defined in ghc-9.10.3 · GHC.Data.Graph.Inductive.Graph
  • Show (gr a b) => Show (OrdGr gr a b)Defined in ghc-9.10.3 · GHC.Data.Graph.Inductive.Graph