fgl-5.8.3.0: Martin Erwig's Functional Graph Library
Safe HaskellSafe-Inferred
LanguageHaskell98

Data.Graph.Inductive.Query.Monad

Description

Monadic Graph Algorithms

Synopsis

Additional Graph Utilities

mapFst :: (a -> b) -> (a, c) -> (b, c) #

mapSnd :: (a -> b) -> (c, a) -> (c, b) #

(><) :: (a -> b) -> (c -> d) -> (a, c) -> (b, d) infixr 8 #

orP :: (a -> Bool) -> (b -> Bool) -> (a, b) -> Bool #

Graph Transformer Monad

newtype GT (m :: Type -> Type) g a #

Constructors

MGT (m g -> m (a, g)) 

Instances

Instances details
Monad m => Applicative (GT m g) # 
Instance details

Defined in Data.Graph.Inductive.Query.Monad

Methods

pure :: a -> GT m g a #

(<*>) :: GT m g (a -> b) -> GT m g a -> GT m g b #

liftA2 :: (a -> b -> c) -> GT m g a -> GT m g b -> GT m g c #

(*>) :: GT m g a -> GT m g b -> GT m g b #

(<*) :: GT m g a -> GT m g b -> GT m g a #

Monad m => Functor (GT m g) # 
Instance details

Defined in Data.Graph.Inductive.Query.Monad

Methods

fmap :: (a -> b) -> GT m g a -> GT m g b #

(<$) :: a -> GT m g b -> GT m g a #

Monad m => Monad (GT m g) # 
Instance details

Defined in Data.Graph.Inductive.Query.Monad

Methods

(>>=) :: GT m g a -> (a -> GT m g b) -> GT m g b #

(>>) :: GT m g a -> GT m g b -> GT m g b #

return :: a -> GT m g a #

apply :: GT m g a -> m g -> m (a, g) #

apply' :: Monad m => GT m g a -> g -> m (a, g) #

applyWith :: Monad m => (a -> b) -> GT m g a -> m g -> m (b, g) #

applyWith' :: Monad m => (a -> b) -> GT m g a -> g -> m (b, g) #

runGT :: Monad m => GT m g a -> m g -> m a #

condMGT' :: forall (m :: Type -> Type) s a. Monad m => (s -> Bool) -> GT m s a -> GT m s a -> GT m s a #

recMGT' :: forall (m :: Type -> Type) s a b. Monad m => (s -> Bool) -> GT m s a -> (a -> b -> b) -> b -> GT m s b #

condMGT :: Monad m => (m s -> m Bool) -> GT m s a -> GT m s a -> GT m s a #

recMGT :: Monad m => (m s -> m Bool) -> GT m s a -> (a -> b -> b) -> b -> GT m s b #

Graph Computations Based on Graph Monads

Monadic Graph Accessing Functions

getNode :: forall (m :: Type -> Type) gr a b. GraphM m gr => GT m (gr a b) Node #

getContext :: forall (m :: Type -> Type) gr a b. GraphM m gr => GT m (gr a b) (Context a b) #

getNodes' :: forall gr (m :: Type -> Type) a b. (Graph gr, GraphM m gr) => GT m (gr a b) [Node] #

getNodes :: forall (m :: Type -> Type) gr a b. GraphM m gr => GT m (gr a b) [Node] #

sucGT :: forall (m :: Type -> Type) gr a b. GraphM m gr => Node -> GT m (gr a b) (Maybe [Node]) #

sucM :: GraphM m gr => Node -> m (gr a b) -> m (Maybe [Node]) #

Derived Graph Recursion Operators

graphRec :: forall (m :: Type -> Type) gr a b c d. GraphM m gr => GT m (gr a b) c -> (c -> d -> d) -> d -> GT m (gr a b) d #

encapsulates a simple recursion schema on graphs

graphRec' :: forall gr (m :: Type -> Type) a b c d. (Graph gr, GraphM m gr) => GT m (gr a b) c -> (c -> d -> d) -> d -> GT m (gr a b) d #

graphUFold :: forall (m :: Type -> Type) gr a b c. GraphM m gr => (Context a b -> c -> c) -> c -> GT m (gr a b) c #

Examples: Graph Algorithms as Instances of Recursion Operators

Instances of graphRec

graphNodesM0 :: forall (m :: Type -> Type) gr a b. GraphM m gr => GT m (gr a b) [Node] #

graphNodesM :: forall (m :: Type -> Type) gr a b. GraphM m gr => GT m (gr a b) [Node] #

graphNodes :: GraphM m gr => m (gr a b) -> m [Node] #

graphFilterM :: forall (m :: Type -> Type) gr a b. GraphM m gr => (Context a b -> Bool) -> GT m (gr a b) [Context a b] #

graphFilter :: GraphM m gr => (Context a b -> Bool) -> m (gr a b) -> m [Context a b] #

Example: Monadic DFS Algorithm(s)

dfsGT :: forall (m :: Type -> Type) gr a b. GraphM m gr => [Node] -> GT m (gr a b) [Node] #

Monadic graph algorithms are defined in two steps:

  1. define the (possibly parameterized) graph transformer (e.g., dfsGT)
  2. run the graph transformer (applied to arguments) (e.g., dfsM)

dfsM :: GraphM m gr => [Node] -> m (gr a b) -> m [Node] #

depth-first search yielding number of nodes

dfsM' :: GraphM m gr => m (gr a b) -> m [Node] #

dffM :: forall (m :: Type -> Type) gr a b. GraphM m gr => [Node] -> GT m (gr a b) [Tree Node] #

depth-first search yielding dfs forest

graphDff :: GraphM m gr => [Node] -> m (gr a b) -> m [Tree Node] #

graphDff' :: GraphM m gr => m (gr a b) -> m [Tree Node] #