# Documentation

The `Repr`

type class denotes that a type can be decomposed to a representation
built out of pieces for which the `TrieKey`

class defines a generalized trie structure.

It is required that, if `(`

, and `Repr`

a, `Eq`

a)`x, y :: a`

, then `x `

if and only if `==`

y

. It is typically the case that
`toRep`

x `==`

`toRep`

y

, as well, but this is not
strictly required. (It is, however, the case for all instances built into the package.)
`compare`

x y == `compare`

(`toRep`

x) (`toRep`

y)

As an additional note, the `Key`

modifier is used for "bootstrapping" `Repr`

instances,
allowing a type to be used in its own `Repr`

definition when wrapped in a `Key`

modifier.

genRepr :: Name -> Q [Dec]Source

Given the name of a type constructor, automatically generates an efficient `Repr`

instance.
If you have several mutually dependent (or even mutually recursive) types, `genRepr`

will
construct instances for all of them.

`genRepr`

guarantees that any instances it generates are consistent with the ordering that
would be generated by `deriving (`

in the data declaration. That is, if `Ord`

)`genRepr`

generates an instance `Repr a`

, then it is guaranteed that if `x, y :: a`

, and `a`

has a derived `Ord`

instance, then `compare x y == compare (toRep x) (toRep y)`

.

genOptRepr :: Name -> Q [Dec]Source

Given the name of a type constructor, automatically generates an efficient `Repr`

instance.
If you have several mutually dependent (or even mutually recursive) types, `genOptRepr`

will
construct instances for all of them. The instance generated by `genOptRepr`

may, in some
cases, be more efficient than the instance generated by `genRepr`

-- in particular,
arguments common to several constructors may be factored out, reducing the complexity of the
associated `TrieKey`

instance, but leaving an ordering inconsistent with `Ord`

.

Therefore, `genOptRepr`

guarantees that any instances it generates are consistent with the
ordering that would be generated by `deriving (`

in the data declaration. That is, if
`Eq`

)`genOptRepr`

generates an instance `Repr a`

, then it is guaranteed that if `x, y :: a`

, and
`a`

has a derived `Eq`

instance, then `(x == y) == (toRep x == toRep y)`

.