This doesn't seem to quite fit. It feels to me like you are trying to squeeze just a  little too much into this method. Feel free to leave it, but I feel this fits better into match() (albeit with a couple of lines of duplication), that way scalars, vector_dim and vector_aux all get the same treatment by this function as collections of defns.