Can I create a shader that uses the distance to the first opaque object behind it? I'd like to create a 'haze' shader, which is like a translucent shader but which attenuates the translucency depending on the depth of the scene behind it.  If this were a game engine, I would do it by first drawing all opaque objects in a z-buffer pass and then when I draw the haze shader in a transparent pass, I'd use the distance from the fragment to the stored z-value to calculate the amount of translucency I need.

Is there a way to do this in Blender?
you can get a "haze" effect without material shader nodes. Under composite, you can set a Z pass (or distance to camera pass), and you can then blur it, where the intensity of the blur is controlled by the "distance".
You can consider Z pass as a black to white raster/mask, where black conceals and white reveals, and also where black to white values represent 2.5D information on Z towards the camera. With that in mind, you can manipulate this "mask", or even create it (manually) in third party software (gimp, photoshop, etc.), then import the raster layer, and use this layer as the Z pass.

About haze. Naturally haze is a "blur effect" caused by different compositions and densities in the atmosphere. You can achieve a more natural haze effect with: you set a "domain" for your atmosphere (a big cube or sphere will be enough), then you set the material of this atmosphere object to volumetric. Using the volumetric shader nodes, you will be able to have more control on the "atmosphere".