Functional coroutines again, now with Duff's Device style switch-case abuse! (http://www.chiark.greenend.org.uk/~sgtatham/coroutines.html)