From fa1a39d1daacd14a37a0c47b4834a39ddad4466d Mon Sep 17 00:00:00 2001 From: hi Date: Fri, 15 Aug 2025 10:10:20 +0000 Subject: [PATCH] verify graph path search --- Logic/Graph.hs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/Logic/Graph.hs b/Logic/Graph.hs index c45b3cd..ad86164 100644 --- a/Logic/Graph.hs +++ b/Logic/Graph.hs @@ -35,3 +35,21 @@ Just ["succ","succ","succ","succ","succ","succ","succ","succ","succ","succ"] ghci> bfs 13 0 (\x -> [("double", x+x), ("add", x+1)]) Just ["add","double","add","double","double","add"] -} + +data VerifyPathError vertex edge + = NoSuchEdge vertex edge + +verifyPath + :: (Eq vertex, Ord vertex, Eq edge) + => GetEdges vertex edge + -> vertex + -> vertex + -> [edge] + -> Either (VerifyPathError vertex edge) Bool +verifyPath getEdges goal start path = + case path of + [] -> Right $ start == goal + (thisEdge:nextEdges) -> + case map fst $ filter (\(next, realEdge) -> realEdge == thisEdge) $ getEdges start of + [] -> Left $ NoSuchEdge start thisEdge + (next:_) -> verifyPath getEdges goal next nextEdges