Skip to content

Tidy up withDict and friends

We are considering (not decided!) to abandon newtype classes: see #20897 (closed).

However the reflection library (important in practice) relies on the current (undocumented) choice that single method classes are implemented by newtypes. But that reliance is no longer necessary. This ticket collects the strands of what we need to do to lift that dependency.

  1. Re-implement withDict: #19915. Status: done in !8249 (merged). This ticket describes a much, much nicer way to handle withDict, and tagToEnum.

  2. Adapt API for GHC.TypeLits and GHC.TypeNats: #15183 (closed). Status: done in !9064 (merged). Exports symbolSing, SSymbol, and related functionality to allow implementing the API in the reflection library without needing unsafeCoerce. This implements Core Libraries Committee proposal #85.

  3. Update reflection library: this reflection ticket. Make the reflection library use withDict, and remove all its uses of unsafeCoerce. There is a reflection ticket about this here.

    This step depends on:

    • Step (2), in order to be able to implement reflection's API without unsafeCoerce
    • Step (5), in order to be able to run reflection's test suite without miscompilations
  4. Add warnings to trigger in other libraries. Add a warning, which complains if you use unsafeCoerce in a way that suggests you are relying on on newtype classes. (As reflection does now.)

  5. Fix withDict interaction with the Specialiser: #21575, especially this comment. Status: partially done by !8241 (closed) and !8594 (merged), but one new issue has surfaced and the ticket remains open.

  6. runExists: #19675. The internals of GHC.TypeLits is a bit of a mess too. #19675 suggests a way to clean it up. Mentioned here for completeness.

Edited by Ryan Scott
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information