graph-rewriting 0.5.3 → 0.6.0
raw patch · 5 files changed
+31/−16 lines, 5 filesdep ~basePVP ok
version bump matches the API change (PVP)
Dependency ranges changed: base
API changes (from Hackage documentation)
- GraphRewriting.Pattern: instance Monad (Pattern n)
- GraphRewriting.Pattern: instance MonadPlus (Pattern n)
+ Data.View: instance [overlap ok] View n n
+ GraphRewriting.Graph: Graph :: IntMap n -> IntMap IntSet -> Int -> Graph n
+ GraphRewriting.Graph: data Graph n
+ GraphRewriting.Graph: edgeMap :: Graph n -> IntMap IntSet
+ GraphRewriting.Graph: nextKey :: Graph n -> Int
+ GraphRewriting.Graph: nodeMap :: Graph n -> IntMap n
+ GraphRewriting.Graph.Internal: Edge :: Int -> Port
+ GraphRewriting.Graph.Internal: Graph :: IntMap n -> IntMap IntSet -> Int -> Graph n
+ GraphRewriting.Graph.Internal: Node :: Int -> Node
+ GraphRewriting.Graph.Internal: data Graph n
+ GraphRewriting.Graph.Internal: eKey :: Port -> Int
+ GraphRewriting.Graph.Internal: edgeMap :: Graph n -> IntMap IntSet
+ GraphRewriting.Graph.Internal: instance [overlap ok] Eq Node
+ GraphRewriting.Graph.Internal: instance [overlap ok] Eq Port
+ GraphRewriting.Graph.Internal: instance [overlap ok] MonadReader s (State s)
+ GraphRewriting.Graph.Internal: instance [overlap ok] Ord Node
+ GraphRewriting.Graph.Internal: instance [overlap ok] Ord Port
+ GraphRewriting.Graph.Internal: instance [overlap ok] Show Edge
+ GraphRewriting.Graph.Internal: instance [overlap ok] Show Node
+ GraphRewriting.Graph.Internal: modifyEdgeMap :: (IntMap IntSet -> IntMap IntSet) -> Rewrite n ()
+ GraphRewriting.Graph.Internal: modifyNodeMap :: (IntMap n -> IntMap n) -> Rewrite n ()
+ GraphRewriting.Graph.Internal: nKey :: Node -> Int
+ GraphRewriting.Graph.Internal: newRef :: Rewrite n Int
+ GraphRewriting.Graph.Internal: newtype Node
+ GraphRewriting.Graph.Internal: newtype Port
+ GraphRewriting.Graph.Internal: nextKey :: Graph n -> Int
+ GraphRewriting.Graph.Internal: nodeMap :: Graph n -> IntMap n
+ GraphRewriting.Graph.Internal: readEdge :: MonadReader (Graph n) r => Edge -> r IntSet
+ GraphRewriting.Graph.Internal: readRef :: Monad m => Int -> IntMap a -> m a
+ GraphRewriting.Graph.Internal: type Edge = Port
+ GraphRewriting.Graph.Internal: type Rewrite n = State (Graph n)
+ GraphRewriting.Pattern: instance [overlap ok] Monad (Pattern n)
+ GraphRewriting.Pattern: instance [overlap ok] MonadPlus (Pattern n)
+ GraphRewriting.Pattern: match :: Pattern n a -> Pattern n [(Match, a)]
+ GraphRewriting.Pattern.Internal: Pattern :: (Match -> ReaderT (Graph n) [] (Match, a)) -> Pattern n a
+ GraphRewriting.Pattern.Internal: newtype Pattern n a
+ GraphRewriting.Pattern.Internal: pattern :: Pattern n a -> Match -> ReaderT (Graph n) [] (Match, a)
+ GraphRewriting.Pattern.Internal: type Match = [Node]
+ GraphRewriting.Rule: replace0 :: (View v n, View [Port] n) => [RHS v] -> Rule n
+ GraphRewriting.Rule: replace1 :: (View v n, View [Port] n) => (Edge -> [RHS v]) -> Rule n
+ GraphRewriting.Rule: replace2 :: (View v n, View [Port] n) => (Edge -> Edge -> [RHS v]) -> Rule n
+ GraphRewriting.Rule: replace3 :: (View v n, View [Port] n) => (Edge -> Edge -> Edge -> [RHS v]) -> Rule n
+ GraphRewriting.Rule: replace4 :: (View v n, View [Port] n) => (Edge -> Edge -> Edge -> Edge -> [RHS v]) -> Rule n
+ GraphRewriting.Rule: replace5 :: (View v n, View [Port] n) => (Edge -> Edge -> Edge -> Edge -> Edge -> [RHS v]) -> Rule n
+ GraphRewriting.Rule: replace6 :: (View v n, View [Port] n) => (Edge -> Edge -> Edge -> Edge -> Edge -> Edge -> [RHS v]) -> Rule n
+ GraphRewriting.Rule: replace7 :: (View v n, View [Port] n) => (Edge -> Edge -> Edge -> Edge -> Edge -> Edge -> Edge -> [RHS v]) -> Rule n
+ GraphRewriting.Rule: replace8 :: (View v n, View [Port] n) => (Edge -> Edge -> Edge -> Edge -> Edge -> Edge -> Edge -> Edge -> [RHS v]) -> Rule n
+ GraphRewriting.Rule.Internal: join :: [Set] -> [Set]
+ GraphRewriting.Rule.Internal: join1 :: Set -> [Set] -> [Set]
+ GraphRewriting.Rule.Internal: joinEdges :: [[Edge]] -> [[Edge]]
+ GraphRewriting.Rule.Internal: mergeEs :: View [Port] n => [Edge] -> State (Graph n) ()
+ GraphRewriting.Rule.Internal: type Set = IntSet
- Data.View: class View v n
+ Data.View: class View v n where update v = adjust (const v) adjust f n = update (f $ inspect n) n
Files
- Data/View.hs +5/−1
- GraphRewriting/Graph.hs +5/−3
- GraphRewriting/Graph/Write.hs +6/−3
- GraphRewriting/Pattern.hs +10/−5
- graph-rewriting.cabal +5/−4
Data/View.hs view
@@ -1,4 +1,4 @@-{-# LANGUAGE UnicodeSyntax, MultiParamTypeClasses #-}+{-# LANGUAGE UnicodeSyntax, MultiParamTypeClasses, FlexibleInstances #-} -- | The multi-parameter type-class 'View' provides an abstraction @View v n@ of a type @n@ that exposes a value of type @v@. It allows both to 'inspect' and 'update' the value, while hiding the internal structure of the value type (@n@). module Data.View where @@ -10,6 +10,10 @@ update v = adjust (const v) adjust f n = update (f $ inspect n) n++instance View n n where+ inspect = id+ update = const -- | convenience function that can be used to access record fields of the exposed type examine ∷ View v n ⇒ (v → field) → n → field
GraphRewriting/Graph.hs view
@@ -1,6 +1,6 @@ {-# LANGUAGE UnicodeSyntax #-} -- | Most of the functions for graph scrutinisation ('GraphRewriting.Graph.Read') and modification ('GraphRewriting.Graph.Write') are defined monadically. This module defines functions for extracting these monadic values and a few non-monadic graph scrutinisation/modification functions.-module GraphRewriting.Graph (module GraphRewriting.Graph, module GraphRewriting.Graph.Types) where+module GraphRewriting.Graph (module GraphRewriting.Graph, module GraphRewriting.Graph.Types, Graph (..)) where import GraphRewriting.Graph.Types import GraphRewriting.Graph.Internal@@ -21,11 +21,13 @@ edges g = map lookupNodes $ Map.assocs (edgeMap g) where lookupNodes (e,ns) = (Edge e, map (\n → fromJust $ Map.lookup n $ nodeMap g) $ Set.elems ns) --- | unsafe, as no check for changed edge references is performed+-- | unsafe, since no checks are performed to ensure that the invariants from+-- "GraphRewriting.Graph.Write" are preserved unsafeMapNodes ∷ (n → n') → Graph n → Graph n' unsafeMapNodes f g = g {nodeMap = Map.map f $ nodeMap g} --- | unsafe map that supplies an additional unique key to the mapping function+-- | map that supplies an additional unique key to the mapping function; unsafe+-- in the same way as 'unsafeMapNodes' unsafeMapNodesUnique ∷ (Int → n → n') → Graph n → Graph n' unsafeMapNodesUnique f g = g {nodeMap = Map.mapWithKey f $ nodeMap g}
GraphRewriting/Graph/Write.hs view
@@ -1,9 +1,12 @@ {-# LANGUAGE UnicodeSyntax, FlexibleContexts #-} -- | Functions for modifying the graph. Although the graph structure is entirely expressed by the graph's node collection, for convenience and efficiency the graph representation also comprises a complementary collection of edges, that has to be synchronised with the node collection. Therefore each of the functions below involves a test for whether the graph structure has been changed, and if so, measures are taken to ensure the graph remains consistent.-+-- -- Invariants for graph consistency:--- - ∀n∊N ∀e∊E: n→e ⇔ e→n--- - ∀e∊E ∃n∊N: e→n+--+-- * Every edge attached to some node points back to that node: ∀n∊N ∀e∊E: n→e ⇔ e→n+--+-- * There are no orphaned edges: ∀e∊E ∃n∊N: e→n+ module GraphRewriting.Graph.Write (module GraphRewriting.Graph.Write, module GraphRewriting.Graph.Types, module Data.View) where
GraphRewriting/Pattern.hs view
@@ -10,11 +10,13 @@ import Data.Set as Set (empty, insert, member) +--instance Functor (Pattern n) where+ instance Monad (Pattern n) where return x = Pattern $ \m → return ([],x) p >>= f = Pattern $ \m → do (m1,x) ← pattern p m- (m2,y) ← pattern (f x) (m1 ⧺ m)+ (m2,y) ← pattern (f x) (reverse m1 ⧺ m) return (m1 ⧺ m2, y) fail str = Pattern $ \m → lift [] @@ -56,10 +58,13 @@ -- | probe a pattern returning the matches it has on the graph. You might want to combine this with 'amnesia'. matches ∷ Pattern n a → Pattern n [Match]-matches p = Pattern $ \m → do+matches p = map fst `liftM` match p++-- | probe a pattern returning the matches it has on the graph. You might want to combine this with 'amnesia'.+match ∷ Pattern n a → Pattern n [(Match, a)]+match p = Pattern $ \m → do lma ← liftM (runReaderT $ pattern p m) ask- let matches = map fst lma- return (nub $ concat matches, matches)+ return (nub $ concat $ map fst lma, lma) -- | choice (<|>) ∷ Pattern n a → Pattern n a → Pattern n a@@ -76,7 +81,7 @@ -- | 'fail' if given pattern succeeds, succeed if it fails. requireFailure ∷ Pattern n a → Pattern n ()-requireFailure p = do require . not =<< probe p+requireFailure p = require . not =<< probe p -- | 'fail' when monadic predicate is not met requireM ∷ Monad m ⇒ m Bool → m ()
graph-rewriting.cabal view
@@ -1,5 +1,5 @@ Name: graph-rewriting-Version: 0.5.3+Version: 0.6.0 Copyright: (c) 2010, Jan Rochel License: BSD3 License-File: LICENSE@@ -10,13 +10,13 @@ Build-Type: Simple Synopsis: Monadic graph rewriting of hypergraphs with ports and multiedges Description:- This library provides a monadic EDSL to define your own graph rewrite system in Haskell. Once you have specified the signature of your graph and a set of rewrite rules, you can apply these rules on a graph to effect a graph transformation. The aim of this library is to make it as convenient as possible to define such a system and experiment with it and is not designed as a backend for high-performance computation.+ This library provides a monadic EDSL to define your own port graph rewrite system in Haskell. Once you have specified the signature of your nodes and a set of rewrite rules, you can apply these rules on a graph to effect a graph transformation. The aim of this library is to make it as convenient as possible to define such a system and experiment with it and is not designed as a backend for high-performance computation. Category: Graphs, Data Cabal-Version: >= 1.6 Library Build-Depends:- base >= 4 && < 4.5,+ base >= 4 && < 4.6, base-unicode-symbols >= 0.2 && < 0.3, mtl >= 1.1 && < 1.2, containers >= 0.3 && < 0.5@@ -31,7 +31,7 @@ GraphRewriting.Pattern GraphRewriting.Pattern.InteractionNet GraphRewriting.Rule- Other-Modules:+-- Other-Modules: GraphRewriting.Graph.Internal GraphRewriting.Pattern.Internal GraphRewriting.Rule.Internal@@ -41,4 +41,5 @@ FlexibleInstances TypeSynonymInstances MultiParamTypeClasses+ OverlappingInstances GHC-Options: -fno-warn-duplicate-exports