(* Simple graph traversal (BFS or DFS) *) let val q: queue = new_queue() (* visited is the set of vertices that have been visited. *) val visited: vertexSet = create_vertexSet() (* Expand the visited set to contain everything v goes to, * and add newly seen vertices to the queue. *) fun expand(v: vertex) = let fun handle_edge(e: edge): unit = let val (v, v') = Graph.edgeInfo(e) in if not (member(visited,v')) then ( add(visited, v'); enqueue(q, v') ) else () end in app handle_edge (Graph.outgoing(v)) end in add(visited, v0); enqueue(q, v0); while (not (empty_queue(q))) do expand(dequeue(q)) end