Use a ReaderT in TcDeriv to avoid some tedious plumbing
authorRyan Scott <ryan.gl.scott@gmail.com>
Tue, 15 Aug 2017 00:56:04 +0000 (20:56 -0400)
committerBen Gamari <ben@smart-cactus.org>
Tue, 15 Aug 2017 01:32:17 +0000 (21:32 -0400)
commited7a830de6a2ea74dd6bb81f8ec55b9fe0b52f28
tree92ea6e1712349f85b7e7292ed591d2082686201e
parentddb870bf7055ccc8ff8b86c161f31aad81d01add
Use a ReaderT in TcDeriv to avoid some tedious plumbing

Addresses point (2) of https://phabricator.haskell.org/D3337#107865.

Before, several functions in `TcDeriv` and `TcDerivInfer` which compute
an `EarlyDerivSpec` were manually threading through about 10 different
arguments, which contribute to quite a lot of clutter whenever they need
to be updated. To minimize this plumbing, and to make it clearer which
of these 10 values are being used where, I refactored the code in
`TcDeriv` and `TcDerivInfer` to use a new `DerivM` type:

```lang=haskell
type DerivM = ReaderT DerivEnv TcRn
```

where `DerivEnv` contains the 10 aforementioned values. In addition to
cleaning up the code, this should make some subsequent changes planned
for later less noisy.

Test Plan: ./validate

Reviewers: austin, bgamari

Subscribers: rwbarton, thomie

Differential Revision: https://phabricator.haskell.org/D3846
compiler/typecheck/TcDeriv.hs
compiler/typecheck/TcDerivInfer.hs
compiler/typecheck/TcDerivUtils.hs