See my comment above about getting the correct type of `pinv` (I probably should have put that response here rather than there, sorry).   It seems hard to do in a way that doesn't involve infinitely recursive type parameters.