Summarize a list of Haskell records <p>Let's say I have a list of records, and I want to summarize it by taking the median. More concretely, say I have</p> <pre><code>data Location = Location { x :: Double, y :: Double } </code></pre> <p>I have a list of measurements, and I want to summarize it into a median <code>Location</code>, so something like:</p> <pre><code>Location (median (map x measurements)) (median (map y measurements)) </code></pre> <p>That is fine, but what if I have something more nested, such as:</p> <pre><code>data CampusLocation = CampusLocation { firstBuilding :: Location ,secondBuilding :: Location } </code></pre> <p>I have a list of <code>CampusLocation</code>s and I want a summary <code>CampusLocation</code>, where the median is applied recursively to all fields. </p> <p>What is the cleanest way to do this in Haskell? Lenses? Uniplate?</p> <p>Edit: Bonus:</p> <p>What if instead of a record containing fields we want to summarize, we had an implicit list instead? For example:</p> <pre><code>data ComplexCampus = ComplexCampus { buildings :: [Location] } </code></pre> <p>How can we summarize a <code>[ComplexCampus]</code> into a <code>ComplexCampus</code>, assuming that each of the <code>buildings</code> is the same length?</p>