Suggestion: I modified the input to allow no filename to be given in which case fid is set to 1 (standard output). Nice work though, was giving myself a headache trying to do the recursion through the levels properly!
gives s3.A = a : 101.
i.e. we lose field b. I kind of understand the logic, i.e. that it is now field A that is being overwritten by a new field A, so that a depth=1 merge has occurred, but for anyone looking to do a true merge-style operation, this means needing to loop though each level... any plans to change this?