Skip to content

Commit 9d827e1

Browse files
committed
Clean up a few warnings
Turning these into explicit errors, all of which should be impossible.
1 parent 6964a47 commit 9d827e1

File tree

3 files changed

+17
-11
lines changed

3 files changed

+17
-11
lines changed

src/Data/Graph/Haggle/Classes.hs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@ class (Graph g, HasEdgeLabel g, HasVertexLabel g) => InductiveGraph g where
219219
return g'
220220

221221
addEdgeLabel :: (HasEdgeLabel g) => g -> Edge -> (Edge, EdgeLabel g)
222-
addEdgeLabel g e = (e, el)
223-
where
224-
Just el = edgeLabel g e
222+
addEdgeLabel g e =
223+
case edgeLabel g e of
224+
Just el -> (e, el)
225+
Nothing -> error "Expected an edge label for a graph implementation satisfying the HasEdgeLabel constraint"

src/Data/Graph/Haggle/Internal/Adapter.hs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -324,17 +324,19 @@ labeledVertices :: (I.Graph g) => LabeledGraph g nl el -> [(I.Vertex, nl)]
324324
labeledVertices g = map toLabVert $ I.vertices (rawGraph g)
325325
where
326326
toLabVert v =
327-
let Just lab = vertexLabel g v
328-
in (v, lab)
327+
case vertexLabel g v of
328+
Just lab -> (v, lab)
329+
Nothing -> error "Impossible: LabeledGraphs always have vertex labels"
329330

330331
-- | Likewise, we use 'edges' here instead of directly reading from the edge
331332
-- label storage array.
332333
labeledEdges :: (I.Graph g) => LabeledGraph g nl el -> [(I.Edge, el)]
333334
labeledEdges g = map toLabEdge $ I.edges (rawGraph g)
334335
where
335336
toLabEdge e =
336-
let Just lab = edgeLabel g e
337-
in (e, lab)
337+
case edgeLabel g e of
338+
Just lab -> (e, lab)
339+
Nothing -> error "Impossible: LabeledGraphs always have edge labels"
338340

339341
mapEdgeLabel :: LabeledGraph g nl el -> (el -> el') -> LabeledGraph g nl el'
340342
mapEdgeLabel g f = g { edgeLabelStore = V.map f (edgeLabelStore g) }

src/Data/Graph/Haggle/PatriciaTree.hs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,10 @@ instance I.HasEdgeLabel (PatriciaTree nl el) where
7979
labeledEdges gr = map toLabEdge (I.edges gr)
8080
where
8181
toLabEdge e =
82-
let Just lab = I.edgeLabel gr e
83-
in (e, lab)
82+
case I.edgeLabel gr e of
83+
Just lab -> (e, lab)
84+
Nothing -> error "Impossible: PatriciaTree instances always have edge labels"
85+
8486
labeledOutEdges (Gr g) (I.V s) = fromMaybe [] $ do
8587
Ctx _ _ _ ss <- IM.lookup s g
8688
return $ IM.foldrWithKey toOut [] ss
@@ -95,8 +97,9 @@ instance I.HasVertexLabel (PatriciaTree nl el) where
9597
labeledVertices gr = map toLabVert (I.vertices gr)
9698
where
9799
toLabVert v =
98-
let Just l = I.vertexLabel gr v
99-
in (v, l)
100+
case I.vertexLabel gr v of
101+
Just l -> (v, l)
102+
Nothing -> error "Impossible: PatriciaTree instances always have vertex labels"
100103

101104
instance I.Bidirectional (PatriciaTree nl el) where
102105
predecessors (Gr g) (I.V v) = fromMaybe [] $ do

0 commit comments

Comments
 (0)