Skip to content

Commit

Permalink
Document partiality of these functions.
Browse files Browse the repository at this point in the history
Another solution is to make them total by turning them into no-ops in
those cases. I worry that might hide bugs, but I am open to arguments
otherwise.

Closes #98.
  • Loading branch information
athas committed Oct 17, 2023
1 parent 5753deb commit 7a6a57e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
2 changes: 2 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ NEXT
* Data.Graph.Inductive.Graph now only requires Graph, not DynGraph
(issue #100).

* Documented that some functions are partial (issue #98).

5.8.1.1
-------

Expand Down
5 changes: 5 additions & 0 deletions Data/Graph/Inductive/NodeMap.hs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ insMapNode_ m a g =
let (g', _, _) = insMapNode m a g
in g'

-- | Partial function: raises exception if passed nodes that are not in the graph.
insMapEdge :: (Ord a, DynGraph g) => NodeMap a -> (a, a, b) -> g a b -> g a b
insMapEdge m e g =
case mkEdge m e of Just e' -> insEdge e' g
Expand All @@ -122,6 +123,7 @@ delMapNode m a g =
let (n, _) = mkNode_ m a
in delNode n g

-- | Partial function: raises exception if passed nodes that are not in the graph.
delMapEdge :: (Ord a, DynGraph g) => NodeMap a -> (a, a) -> g a b -> g a b
delMapEdge m (n1, n2) g =
case mkEdge m (n1, n2, ()) of Just (n1', n2', _) -> delEdge (n1', n2') g
Expand All @@ -137,6 +139,7 @@ insMapNodes_ m as g =
let (g', _, _) = insMapNodes m as g
in g'

-- | Partial function: raises exception if passed nodes that are not in the graph.
insMapEdges :: (Ord a, DynGraph g) => NodeMap a -> [(a, a, b)] -> g a b -> g a b
insMapEdges m es g =
case mkEdges m es of Just es' -> insEdges es' g
Expand All @@ -147,6 +150,7 @@ delMapNodes m as g =
let ns = P.map fst $ mkNodes_ m as
in delNodes ns g

-- | Partial function: raises exception if passed nodes that are not in the graph.
delMapEdges :: (Ord a, DynGraph g) => NodeMap a -> [(a, a)] -> g a b -> g a b
delMapEdges m ns g =
case mkEdges m $ P.map (\(a, b) -> (a, b, ())) ns of
Expand All @@ -155,6 +159,7 @@ delMapEdges m ns g =
let ns'' = P.map (\(a, b, _) -> (a, b)) ns'
in delEdges ns'' g

-- | Partial function: raises exception if passed a node that is not in the graph.
mkMapGraph :: (Ord a, DynGraph g) => [a] -> [(a, a, b)] -> (g a b, NodeMap a)
mkMapGraph ns es =
let (ns', m') = mkNodes new ns
Expand Down

0 comments on commit 7a6a57e

Please sign in to comment.