The overloaded-records package

Implementation of Overloaded Record Fields based on current GHC proposal.
It is built on top of functionality that is included in GHC 8.0.1, but it
works on older GHC versions as well. Most importantly, this library provides
Template Haskell functions for automatic deriving of instancess for
HasField and ModifyField type classes. With these instances overloaded
fields can be used directly as getters and lenses.

Maintainer's Corner

Readme for overloaded-records-0.4.2.0

Overloaded Records

Description

Implementation of Overloaded Record Fields based on current GHC proposal. It
is built on top of functionality that is included in GHC 8.0.1, but it works on
older GHC versions as well. Most importantly, this library provides Template
Haskell functions for automatic deriving of instancess for HasField and
ModifyField type classes. With these instances overloaded fields can be used
directly as getters and lenses.

One of the biggest features of Overloaded Records is the possibility to
define functions that do not depend on concrete data types, but on the "fields"
they provide. In example function zeroV3 can be applied to anything that has
fields "x", "y", and "z" that reference values of some Num type:

λ> zeroV3 (V3 1 1 1 :: V3 Int)
V3 {_x = 0, _y = 0, _z = 0}

λ> zeroV3 (V4 1 1 1 1 :: V4 Int)
V4 {_x = 0, _y = 0, _z = 0, _t = 1}

Function zeroV3 can be also defined using operators from
lens library: