codegen: implement head and tail without proper list