Safe Haskell | None |
---|---|
Language | Haskell2010 |
The match
function in the typeclass Shaped
allows you to uniformly operate over all the fields in a given piece of
data--for instance, consuming them, iterating over them, counting them,
etc. This module defines a uniform representation to allow this to work.
This is in the nitty-gritty of how StrictCheck works: you do not need to
understand this in order to use StrictCheck, unless you need to declare
custom instances of Shaped
for a type not supported by StrictCheck's
generics mechanism (i.e. GADTs, existential types, abstract types).
Synopsis
- data Flattened d f xs where
- unflatten :: Flattened d f xs -> d f
- mapFlattened :: forall c d f g xs. All c xs => (forall x. c x => f x -> g x) -> Flattened d f xs -> Flattened d g xs
- traverseFlattened :: forall c d f g h xs. (All c xs, Applicative h) => (forall x. c x => f x -> h (g x)) -> Flattened d f xs -> h (Flattened d g xs)
Documentation
data Flattened d f xs where Source #
The Flattened
type contains all the fields in a piece of data
(represented as an n-ary product NP
from Generics.SOP), paired with a way
to re-assemble them into a value of the original datatype.
Flattened d f xs
can be read as "some value of type d f
, which has been
separated into an n-ary product NP f xs
and a function which can reconstruct
a value d h
for any h
, given an n-ary product with matching field types
to the one contained here.
Pay attention to the kinds! d :: (* -> *) -> *
, f :: * -> *
, and
xs :: [*]
.
For types which are literally a collection of fields with no extra information, the reconstruction function merely converts the given list of fields back into a value of the original type. For types which contain extra information in their values (beyond what StrictCheck considers fields), this function should contain that information, and re-attach it to the field values it receives.
unflatten :: Flattened d f xs -> d f Source #
Use the re-assembly close in a Flattened
to yield a value of the original
type from which it was derived.
mapFlattened :: forall c d f g xs. All c xs => (forall x. c x => f x -> g x) -> Flattened d f xs -> Flattened d g xs Source #
If all the fields in a Flattened
satisfy some constraint, map a function
expecting that constraint across all the fields. This may change the functor
over which the Flattened
value is parameterized.
traverseFlattened :: forall c d f g h xs. (All c xs, Applicative h) => (forall x. c x => f x -> h (g x)) -> Flattened d f xs -> h (Flattened d g xs) Source #
traverseFlattened
is to traverse
like mapFlattened
is to fmap
.