Safe Haskell | None |
---|---|
Language | Haskell2010 |
generics-eot
tries to be a library for datatype generic programming
that is easy to understand. "eot" stands for "eithers of tuples".
A tutorial on how to use generics-eot
can be found here:
https://generics-eot.readthedocs.io/.
Documentation
An instance (
) allows us toHasEot
a
- convert values of an arbitrary algebraic datatype
a
to and from a generic representation (
) (seeEot
atoEot
andfromEot
). - extract meta information about the type
a
(seedatatype
).
Once an algebraic datatype has an instance for Generic
it
automatically gets one for HasEot
.
Eot
is a type level function that maps arbitrary ADTs to isomorphic
generic representations. Here's an example:
data Foo = A Int Bool | B String
would be mapped to:
Either (Int, (Bool, ())) (Either (String, ()) Void)
These representations follow these rules:
- The choice between constructors is mapped to right-nested
Either
s. - There's always a so-called end-marker
Void
. It's an invalid choice (andVoid
is uninhabited to make sure you don't accidentally create such a value). So e.g.data Foo = A
would be mapped toEither () Void
, and a type with no constructors is mapped toVoid
. - The fields of one constructor are mapped to right-nested tuples.
- Again there's always an end-marker, this time of type
()
. A constructor with three fieldsa
,b
,c
is mapped to(a, (b, (c, ())))
, one fielda
is mapped to(a, ())
, and no fields are mapped to()
(just the end-marker).
These rules (and the end-markers) are necessary to make sure generic functions know exactly which parts of the generic representation are field types and which parts belong to the generic skeleton.
Meta Information
Type for meta information about ADTs.
Datatype | |
|
data Constructor Source #
Type that represents meta information about fields of one constructor.
Selectors [String] | Record constructor, containing the list of the selector names. |
NoSelectors Int | Constructor with fields, but without selector names. The argument gives the number of fields. |
NoFields | Constructor without fields. |
Useful Re-exports
Representable types of kind *. This class is derivable in GHC with the DeriveGeneric flag on.
Generic Bool | |
Generic Ordering | |
Generic () | |
Generic Void | |
Generic Version | |
Generic ExitCode | |
Generic Fixity | |
Generic Associativity | |
Generic SourceUnpackedness | |
Generic SourceStrictness | |
Generic DecidedStrictness | |
Generic [a] | |
Generic (Maybe a) | |
Generic (Par1 p) | |
Generic (Either a b) | |
Generic (V1 k p) | |
Generic (U1 k p) | |
Generic (a, b) | |
Generic (Proxy k t) | |
Generic (Rec1 k f p) | |
Generic (URec k (Ptr ()) p) | |
Generic (URec k Char p) | |
Generic (URec k Double p) | |
Generic (URec k Float p) | |
Generic (URec k Int p) | |
Generic (URec k Word p) | |
Generic (a, b, c) | |
Generic (K1 k i c p) | |
Generic ((:+:) k f g p) | |
Generic ((:*:) k f g p) | |
Generic (a, b, c, d) | |
Generic (M1 k i c f p) | |
Generic ((:.:) k2 k1 f g p) | |
Generic (a, b, c, d, e) | |
Generic (a, b, c, d, e, f) | |
Generic (a, b, c, d, e, f, g) | |
data Proxy k (t :: k) :: forall k. k -> * #
A concrete, poly-kinded proxy type
Generic1 k (Proxy k) | |
Monad (Proxy *) | Since: 4.7.0.0 |
Functor (Proxy *) | Since: 4.7.0.0 |
Applicative (Proxy *) | Since: 4.7.0.0 |
Foldable (Proxy *) | Since: 4.7.0.0 |
Alternative (Proxy *) | Since: 4.9.0.0 |
MonadPlus (Proxy *) | Since: 4.9.0.0 |
Bounded (Proxy k t) | |
Enum (Proxy k s) | Since: 4.7.0.0 |
Eq (Proxy k s) | Since: 4.7.0.0 |
Ord (Proxy k s) | Since: 4.7.0.0 |
Read (Proxy k s) | Since: 4.7.0.0 |
Show (Proxy k s) | Since: 4.7.0.0 |
Ix (Proxy k s) | Since: 4.7.0.0 |
Generic (Proxy k t) | |
Monoid (Proxy k s) | Since: 4.7.0.0 |
type Rep1 k (Proxy k) | |
type Rep (Proxy k t) | |
Uninhabited data type
Since: 4.8.0.0