switch using foldr
rename labelled to goto (probably clearer)