generics-sop
Generic Programming using True Sums of Products
| Version on this page: | 0.5.0.0@rev:1 |
| LTS Haskell 24.16: | 0.5.1.4@rev:2 |
| Stackage Nightly 2025-10-23: | 0.5.1.4@rev:2 |
| Latest on Hackage: | 0.5.1.4@rev:2 |
generics-sop-0.5.0.0@sha256:d5f3c4b0d3a68dc42f87d7b3b38b724e8db9115b475331bafbe7d41b1994ee83,5552Module documentation for 0.5.0.0
- Generics
A library to support the definition of generic functions. Datatypes are viewed in a uniform, structured way: the choice between constructors is represented using an n-ary sum, and the arguments of each constructor are represented using an n-ary product.
The module Generics.SOP is the main module of this library and contains
more detailed documentation.
Since version 0.4.0.0, this package is now based on
sop-core. The core package
contains all the functionality of n-ary sums and products, whereas this
package provides the datatype-generic programming support on top.
Examples of using this library are provided by the following packages:
basic-sopbasic examples,pretty-sopgeneric pretty printing,lens-sopgenerically computed lenses,json-sopgeneric JSON conversions.
A detailed description of the ideas behind this library is provided by the paper:
Edsko de Vries and Andres Löh. True Sums of Products. Workshop on Generic Programming (WGP) 2014.
Changes
0.5.0.0 (2019-05-09)
-
Add strictness info to the metadata. This means that code directly using the
ADTconstructor has to be modified because it now has a new fourth argument. (See #76 and #87.) -
Depend on
sop-core-0.5.0.*which changes the definition ofSameShapeAsto improve compiler performance and adds “ejections”.
0.4.0.1 (2018-10-23)
- Remove
GHC.Eventimport inGenerics.SOP.Instancesto fix build on Windows.
0.4.0.0 (2018-10-20)
-
Split into
sop-coreandgenerics-soppackages. -
Drop support for GHC < 8.0.2, bump
basedependency to>= 4.9and remove dependency ontransformers. -
Simplify
All2 ctoAll (All c)and simplifySListI xstoAll Top xs, and some implied refactoring. -
Add
SemigroupandMonoidinstances for various datatypes. -
Add specialised conversion functions for product types, enumeration, and wrapped types.
-
Add benchmark suite.
-
Fix deriving
Genericfor empty datatypes. -
Genericis now a superclass ofHasDatatypeInfo. -
More
Genericinstances for datatypes from recent versions ofbase.
0.3.2.0 (2018-01-08)
-
Make TH
deriveGenericFunctionswork properly with parameterized types (note that the more widely usedderiveGenericwas already working correctly). -
Make TH
deriveGenericwork properly with empty types. -
Add
compare_NS,ccompare_NS,compare_SOP, andccompare_SOPto better support comparison of sum structures. -
Add
hctraverse_andhctraverse'as well as their unconstrained variants and a number of derived functions, to support effectful traversals.
0.3.1.0 (2017-06-11)
-
Add
AllZip,htrans,hcoerce,hfromI,htoI. These functions are for converting between related structures that do not have common signatures.The most common application of these functions seems to be the scenario where a datatype has components that are all wrapped in a common type constructor application, e.g. a datatype where every component is a
Maybe. Then we can usehfromIafterfromto turn the generically derivedSOPofIs into anSOPofMaybes (and back). -
Add
IsProductType,IsEnumType,IsWrappedTypeandIsNewtypeconstraint synonyms capturing specific classes of datypes.
0.3.0.0 (2017-04-29)
-
No longer compatible with GHC 7.6, due to the lack of support for type-level literals.
-
Support type-level metadata. This is provided by the
Generics.SOP.Type.Metadatamodule. The two modulesGenerics.SOP.MetadataandGenerics.SOP.Type.Metadataexport nearly the same names, so for backwards compatibility, we keep exportingGenerics.SOP.Metadatadirectly fromGenerics.SOP, whereasGenerics.SOP.Type.Metadatais supposed to be imported explicitly (and qualified).Term-level metadata is still available, but is now usually computed automatically from the type-level metadata which contains the same information, using the function
demoteDatatypeInfo. Term-level metadata is unchanged from generics-sop-0.2, so in most cases, even if your code makes use of metadata, you should not need to change anything.If you use TH deriving, then both type-level metadata and term-level metadata is generated for you automatically, for all supported GHC versions.
If you use GGP deriving, then type-level metadata is available if you use GHC 8.0 or newer. If you use GHC 7.x, then GHC.Generics supports only term-level metadata, so we cannot translate that into type-level metadata. In this combination, you cannot use code that relies on type-level metadata, so you should either upgrade GHC or switch to TH-based deriving.
0.2.5.0 (2017-04-21)
-
GHC 8.2 compatibility.
-
Make
:.:an instance ofApplicative,FoldableandTraversable. -
Add functions
apInjs'_NPandapInjs'_POP. These are variants ofapInjs_NPandapInjs'_POPthat return their result as an n-ary product, rather than collapsing it into a list. -
Add
hexpand(andexpand_NSandexpand_SOP). These functions expand sums into products, given a default value to fill the other slots. -
Add utility functions such as
mapIIormapIKthat lift functions into different combinations of identity and constant functors. -
Add
NFData(and lifted variants) instances for basic functors, products and sums.
0.2.4.0 (2017-02-02)
-
Add
hindex(andindex_NSandindex_SOP). -
Add
hapInjsas a generalization ofapInjs_NPandapInjs_POP. -
Make basic functors instances of lifted classes (such as
Eq1etc).
0.2.3.0 (2016-12-04)
-
Add various metadata getters
-
Add
hdicts. -
Add catamorphisms and anamorphisms for
NPandNS. -
TH compatibility changes for GHC 8.1 (master).
0.2.2.0 (2016-07-10)
-
Introduced
unZto destruct a unary sum. -
Add Haddock
@sinceannotations for various functions.
0.2.1.0 (2016-02-08)
-
Now includes a CHANGELOG.
-
Should now work with ghc-8.0.1-rc1 and -rc2 (thanks to Oleg Grenrus).
-
Introduced
hdandtlto project out of a product, andProjectionandprojectionsas duals ofInjectionandinjections.
0.2.0.0 (2015-10-23)
-
Now tested with ghc-7.10
-
Introduced names
hmap,hcmap,hzipWith,hczipWithforhliftA,hcliftA,hliftA2,hcliftA2, respectively. Similarly for the specialized versions of these functions. -
The constraint transformers
AllandAll2are now defined as type classes, not type families. As a consequence, the partial applicationsAll candAll2 care now possible. -
Because of the redefinition of
AllandAll2, some special cases are no longer necessary. For example,cpure_POPcan now be implemented as a nested application ofpure_NP. -
Because of the redefinition of
AllandAll2, the functionshcliftA'and variants (with prime!) are now deprecated. One can easily use the normal versions instead. For example, the definition ofhcliftA'is now simplyhcliftA' p = hcliftA (allP p) where allP :: proxy c -> Proxy (All c) allP _ = Proxy -
Because
AllandAll2are now type classes, they now have superclass constraints implying that the type-level lists they are ranging over must have singletons.class (SListI xs, ...) => All c xs class (SListI xss, ...) => All2 c xssSome type signatures can be simplified due to this.
-
The
SingItypeclass andSingdatatypes are now deprecated. The replacements are calledSListIandSList. Thesingmethod is now calledsList. The difference is that the new versions reveal only the spine of the list, and contain no singleton representation for the elements anymore.For one-dimensional type-level lists, replace
SingI xs => ...by
SListI xs => ...For two-dimensional type-level lists, replace
SingI xss => ...by
All SListI xss => ...Because All itself implies
SListI xss(see above), this constraint is equivalent to the oldSing xss.The old names are provided for (limited) backward compatibility. They map to the new constructs. This will work in some, but not all scenarios.
The function
lengthSinghas also been renamed tolengthSListfor consistency, and the old name is deprecated. -
All
Proxy carguments have been replaced byproxy cflexible arguments, so that other type constructors can be used as proxies. -
Class-level composition (
Compose), pairing (And), and a trivial constraint (Top) have been added. Type-level map (Map) has been removed. Occurrences such asAll c (Map f xs)should now be replaced with
All (c `Compose` f) xs -
There is a new module called
Generics.SOP.Dictthat contains functions for manipulating dictionaries explicitly. These can be used to prove theorems about non-trivial class constraints such as the ones that get built usingAllandAll2. Some such theorems are provided. -
There is a new TH function
deriveGenericFunctionsthat derives the code of a datatype and conversion functions, but does not create a class instance. (Contributed by Oleg Grenrus.) -
There is a new TH function
deriveMetadataValuethat derives aDatatypeInfovalue for a datatype, but does not create an instance ofHasDatatypeInfo. (Contributed by Oleg Grenrus.) -
There is a very simple example file. (Contributed by Oleg Grenrus.)
-
The function
hcollapseforNSnow results in anarather than anI a, matching the specialized versioncollapse_NS. (Suggested by Roman Cheplyaka.)
0.1.1.2 (2015-03-27)
- Updated version bounds for ghc-prim (for ghc-7.10).
0.1.1.1 (2015-03-20)
-
Preparations for ghc-7.10.
-
Documentation fix. (Contributed by Roman Cheplyaka.)
0.1.1 (2015-01-06)
-
Documentation fixes.
-
Add superclass constraint (TODO).
-
Now derive tuple instance for tuples up to 30 components. (Contributed by Michael Orlitzky.)