BSD-3-Clause licensed by José Pedro Magalhães
Maintained by [email protected]
This version can be pinned in stack with:linear-generics-0.2.3@sha256:3ef7d555f239a10254b61d9debdb24aa2d77529f791818db80f7030039792c62,6285

Module documentation for 0.2.3

Used by 1 package in nightly-2024-09-15(full list with versions):

linear-generics: Generic programming library with linearity support

Hackage Hackage Dependencies Haskell Programming Language BSD3 License Build Status

This package offers a version of GHC.Generics with two important improvements:

  1. The to, from, to1, and from1 methods have multiplicity-polymorphic types, allowing them to be used with either traditional Haskell code or linearly typed code.

  2. The representations used for Generic1 are modified slightly.

    • Composition associates to the left in the generic representation. As a result, to1 and from1 never need to use fmap. This can greatly improve performance, and it is necessary to support multiplicity polymorphism, as discussed here.
    • Generic representations no longer use Rec1 f, they use Par1 :.: f instead, as proposed by spl. This way you no longer need to write Rec1 instances for your derivers.

    For more details, see the Generics.Linear documentation.

This library is organized as follows:

  • Generics.Linear defines the core functionality for generics. This includes:

    • multiplicity polymorphic Generic and Generic1 classes,
    • a replacement for the :.: composition type, and
    • an MP1 type for nonlinear and multiplicity polymorphic fields.
  • Generics.Linear.TH implements Template Haskell functionality for deriving instances of Generic(1).

  • Generics.Linear.Unsafe.ViaGHCGenerics offers DerivingVia targets to derive both Generic and Generic1 instances from GHC.Generics.Generic. Because these instances necessarily use unsafe coercions, their use will likely inhibit full optimization of code using them (see this wiki page for more on the GHC internals, along with commentary in Unsafe.Coerce).

Educational code: the educational modules exported by generic-deriving have been copied into the tests/Generic/Deriving directory in this repository, with the very few modifications required to accommodate the differences between the Generic1 representations here and in base. All the same caveats apply as in the originals; see that package’s README.

Changes

next [????.??.??]

0.2.3

  • Support building with template-haskell-2.21.* (GHC 9.8).

0.2.2

  • Produce an orderly error message if someone gives us type data.
  • Produce an error message much more eagerly when someone tries to use GHCGenerically1 with an improperly shaped type.
  • Place INLINE [1] pragmas on from and to implementations when types don’t have too many constructors or fields, following the heuristics GHC has used for Generic deriving since version 9.2.

0.2.1

  • Add a Generic instance for Data.Void.Void.

0.2

  • The Generic1 instance for Generically1 no longer uses GHC.Generics.Generic1; it now uses GHC.Generics.Generic instead. This allows far more instances to be derived.

0.1.0.1

  • Make Generic1 deriving properly polykinded. There was an old kind check that has not been valid for a long time.

  • Improve error handling slightly.

  • Adjust README.

  • Refactor code in Generics.Linear.TH

  • Improve comments.

0.1.0.0

  • Initial fork from generic-deriving.