A purely functional approach to packet processing