Lattices over polynomial rings and applications to function fields