dfs package:search-algorithms

dfs next found initial performs a depth-first search over a set of states, starting with initial and generating neighboring states with next. It returns a depth-first path to a state for which found returns True. Returns Nothing if no path is possible.

Example: Simple directed graph search

>>> import qualified Data.Map as Map
>>> graph = Map.fromList [(1, [2, 3]), (2, [4]), (3, [4]), (4, [])]
>>> dfs (graph Map.!) (== 4) 1
Just [3,4]
dfsM is a monadic version of dfs: it has support for monadic next and found parameters.