Automatic data types fusion when deriving generator for constructor #55
Labels
code: enhancement
New feature or improvement
code: heuristics
Involves solution that applied only to a specific case
derive: least-effort
Relates to the `LeastEffort` derivation algorithm
issue: performance
When work takes too much resources
part: derivation
Related to automated derivation of generators
status: feature request
Request for new functionality or improvement
This can be seen as generation-time optimisation by growing the size of derived code. @AlgebraicWolf tested fusion in an ad-hoc example and it gave better results. We can generalise this.
The idea is to generate a data type for each data constructor (which is of a (complex?) dependent type) which would contain all constraints of data types of all constructor parameters. When we generate arguments for this particular constructor, instead of a sequence of subgeneration calls and then assembling it to the constructor's call, we can simply generate that specialised data structure and use it to generate the constructor call.
For example, consider couple of GADTs:
If we derive a generator for data type
Z
defined likewe now make generator for
Z
to be alternatives of generator forZx
and generator forZn
, where generator ofZn
is an alternative between approximatelyand
What is suggested here is to create a special data type
which contains all possible data from all possible arguments of the constructor
Zn
in a fused way. So, there exists a functionzn : ForZn -> Z
which produces all possible calls to constructorZn
:So, generator for
Zn
can simply look likezn <$> genForZn
, and generator forForZn
can be simply derived as usual (it does not contain dependent types in its constructors, so this mechanism should not be applied to it recursively).The text was updated successfully, but these errors were encountered: