Replace record projection function with lenses
<p>Almost every time I make a record, I find myself adding <code>makeLenses ''Record</code> (from <a href="https://hackage.haskell.org/package/lens" rel="nofollow">lens</a>) immediately afterwards, and I never end up actually using the projection functions that the record gives me. In fact, looking at what <code>makeLenses</code> produces (with the GHC <code>-ddump-splices</code> flag), it looks like not even it uses those projection functions, except to choose a name for the lenses it produces.</p>

<p>Is there some way, either through <code>TemplateHaskell</code>, or through a preprocessor, or frankly any other magic, that I could get record projection functions to be straight up Van Laarhoven lenses instead? </p>

<p>To be clear, that would mean that</p>

<pre><code>data Record a b = Record { x :: a, y :: b }
</code></pre>

<p>Would generate (with <a href="https://hackage.haskell.org/package/lens-4.14/docs/Control-Lens-Lens.html" rel="nofollow"><code>type Lens s t a b = forall f. Functor f =&gt; (a -&gt; f b) -&gt; s -&gt; f t</code></a>)</p>

<pre><code>x :: forall a b c. Lens (Record a b) (Record c b) a c
x f (Record _x _y) = fmap (\x' -&gt; Record x' _y) (f _x)

y :: forall a b c. Lens (Record a b) (Record a c) b c
y f (Record _x _y) = fmap (\ y' -&gt; Record _x y') (f _y)
</code></pre>

<p>Instead of</p>

<pre><code>x :: forall a b. Record a b -&gt; a
x (Record _x _y) = _x

y :: forall a b. Record a b -&gt; b
y (Record _x _y) = _y
</code></pre>

<p>It would not only get rid of the boilerplate <code>makeLenses</code> but also free up the namespace (since the projection functions wouldn't ever be defined). </p>

<p>This is such a minor thing, but since it's attached to all my records, and records aren't such a rare thing, it is really starting to get on my nerves...</p>