Skip to content

WIP: Change HasField to support updates

Adam Gundry requested to merge wip/amg/hasfield-2020 into master

This implements GHC proposal 158 (see #16232). That is, it changes GHC.Records.HasField from

class HasField x r a | x r -> a where
  getField :: r -> a

to:

class HasField x r a | x r -> a where
  hasField :: r -> (a -> r, a)

The essence of the implementation is described in Note [Record updaters] and the updated Note [HasField instances]. It follows the approach suggested by @simonpj in #16232, namely generating an updater function alongside the selector function. The Name of this function is stored in DataCon, hence the changes to FieldLabel. I have not changed mkRecSelBind to derive the selector binding from the updater, although in principle this is possible.

The commits are conceptually distinct steps but not individually buildable; I've kept them separate for ease of review/rebasing but I will squash them before merge.

Still to do: update the user docs. Now with user docs!

Edited by Adam Gundry

Merge request reports