MyNixOS website logo
Description

Generic programming library for generalised deriving.

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.

The implementation is based on the generic-deriving package, first described in the paper

  • A generic deriving mechanism for Haskell. Jose Pedro Magalhaes, Atze Dijkstra, Johan Jeuring, and Andres Loeh. Haskell'10.

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 Generic1 instances from GHC.Generics.GHC.Generics.Generic. 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.

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.

Metadata

Version

0.2.3

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows