linear-generics: Generic programming library for generalised deriving.

[ bsd3, generics, library ] [ Propose Tags ]

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. As a result, to1 and from1 never need to use fmap. This can greatly improve performance, and it is necessary to support multiplicity polymorphism. A smaller change, approximately as proposed by spl, reduces the number of instances that must be written to actually use Generic1 for deriving instances of other classes.

For more details, see the Generics.Linear documentation.

This library is organized as follows:

  • Generics.Linear defines the core functionality for generics, including the multiplicity-polymorphic Generic(1) classes and a replacement for the :.: composition type.

  • Generics.Linear.TH implements Template Haskell functionality for deriving instances of Generic(1).

  • Generics.Linear.Unsafe.ViaGHCGenerics offers DerivingVia targets to derive Generic and (some) Generic1 instances from their GHC.Generics counterparts. Because these instances necessarily use unsafe coercions, their use will likely inhibit full optimization of code using them.

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.


[Skip to Readme]

Modules

[Index] [Quick Jump]

Downloads

Maintainer's Corner

For package maintainers and hackage trustees

Candidates

  • No Candidates
Versions [RSS] 0.1.0.0, 0.1.0.1, 0.2 (info)
Change log CHANGELOG.md
Dependencies base (>=4.15 && <5), containers (>=0.5.9 && <0.7), ghc-prim (<1), template-haskell (>=2.16 && <2.19), th-abstraction (>=0.4 && <0.5) [details]
License BSD-3-Clause
Copyright 2011-2013 Universiteit Utrecht, University of Oxford, Ryan Scott, 2021 David Feuer
Author José Pedro Magalhães
Maintainer David.Feuer@gmail.com
Category Generics
Home page https://github.com/linear-generics/linear-generics
Bug tracker https://github.com/linear-generics/linear-generics/issues
Source repo head: git clone https://github.com/linear-generics/linear-generics
Uploaded by dfeuer at 2021-10-12T02:28:51Z
Distributions NixOS:0.2, Stackage:0.2
Downloads 258 total (23 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs uploaded by user [build log]
All reported builds failed as of 2021-10-12 [all 2 reports]

Readme for linear-generics-0.1.0.1

[back to package description]

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 Generic and (some) Generic1 instances from their GHC.Generics counterparts. 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.