Could you perhaps change every `head` to a pattern match with `[] -> error "impossible, because..."` to see what impossible happened? It could help when some other impossible happens later. Other than that, located-base that Bryan Richter mentioned looks useful too. Best regards, Marcin Mrotek