title: Functional Breadth First Search
body: <p>Functional depth first search is lovely in directed acyclic graphs.</p>
  
  <p>In graphs with cycles however, how do we avoid infinite recursion? In a procedural language I would mark nodes as I hit them, but let's say I can't do that. </p>
  
  <p>A list of visited nodes is possible, but will be slow because using one will result in a linear search of that list before recurring. A better data structure than a list here would obviously help, but that's not the aim of the game, because I'm coding in ML - lists are king, and anything else I will have to write myself.</p>
  
  <p>Is there a clever way around this issue? Or will I have to make do with a visited list or, god forbid, mutable state?</p>