interface GenOrderTuning : Name -> Type A magic interface for tuning the order of generation in derived generators
This interface defines a function `isConstructor` which can be implemented only by calling a macro `itIsConstructor`.
If the argument of the implementation is not a name of a constructor, you will get a compilation error at this point.
`deriveFirst` function gets some information about given arguments in the current derivation task,
and returns constructor's arguments that must be generated first in the derived generator, in order.
If given arguments require some other arguments to be derived before them, these arguments would be generated appropriately.
Any repetitions, mentions of already given arguments and mentions of arguments that will be generated by arguments earlier in the list
will be simply ignored.
Constructor arguments can be given by their number or their name (using name literals).
Typical usage is the following:
```idris
data X : Nat -> Nat -> Type where
X1 : (n, m : Nat) -> n `LT` m => X n m
X2 : X n n
GenOrderTuning "X1".dataCon where
isConstructor = itIsConstructor
deriveFirst gt gc = [`{m}, 2] -- 2 is the `LT` argument
```
---
This interface can be used for fine tuning when derivator could determine order not optimally.
For example, consider the following type:
```idris
data Y : Type where
MkY : (first : Z (f n) a b) -> (second : Z (f n) b c) -> Y
```
If for some reason we know that argument `b` is better to be generated with the argument `second` rather than with the argument `first`,
we can implement the following tuning for `MkY`:
```idris
GenOrderTuning "MkY".dataCon where
isConstructor = itIsConstructor
deriveFirst _ _ = [`{second}]
```
Please notice that there is no need to mention argument `first`,
and argument `n` before argument `second` despite it is needed for its generation.
Derivator will automatically understand arguments really needed to be generated before the given in by the `deriveFirst` function,
and after that it will decide the order of the rest arguments using its usual algorithm.
Parameters: n
Methods:
isConstructor : (con : IsConstructor n ** GenuineProof con) deriveFirst : List (Fin ((((isConstructor .fst) .typeInfo) .args) .length)) -> List (Fin ((((isConstructor .fst) .conInfo) .args) .length)) -> List (ConArg ((isConstructor .fst) .conInfo))
isConstructor : GenOrderTuning n => (con : IsConstructor n ** GenuineProof con)- Totality: total
Visibility: public export deriveFirst : {auto __con : GenOrderTuning n} -> List (Fin ((((isConstructor .fst) .typeInfo) .args) .length)) -> List (Fin ((((isConstructor .fst) .conInfo) .args) .length)) -> List (ConArg ((isConstructor .fst) .conInfo))- Totality: total
Visibility: public export interface ProbabilityTuning : Name -> Type- Parameters: n
Constructor: MkProbabilityTuning
Methods:
0 isConstructor : (con : IsConstructor n ** GenuineProof con) tuneWeight : Nat1 -> Nat1
0 isConstructor : ProbabilityTuning n => (con : IsConstructor n ** GenuineProof con)- Totality: total
Visibility: public export tuneWeight : ProbabilityTuning n => Nat1 -> Nat1- Totality: total
Visibility: public export tuneProbability : {default Public _ : Visibility} -> a -> (Nat1 -> Nat1) -> Elab () A function for tuning probability of a particular constructor relative to the default value or giving an absolute value.
This function takes a constructor to tweak and a function taking a default weight of a constuctor returning a final one.
Typical usage, considering that we want to have constructor `B` fire twice as often as the others, is the following.
```idris
data X = A | B | C
%runElab tuneProbability B (*2)
```
One can use both constructor itself, or its name, e.g.
```idris
%runElab tuneProbability B (*2)
-- or --
%runElab tuneProbability "B" (*2)
-- or --
%runElab tuneProbability `{B} (*2)
```
Each variant is fine, but, surely, only one is allowed for each constructor.
Please notice that this tuning will be actually used in derivation only when the result of this function
(which is an implementation of a special interface called `ProbabilityTuning`)
is visible at the site of calling to derivation.
Please also notice that the body of the given function must be computable *at compile-time* at the site of call to derivation.
Totality: total
Visibility: exportinterface TuneProbabilityArgs : Type -> Type- Parameters: r
Methods:
doTuneProbabilities : Visibility -> Elab () -> r
Implementations:
TuneProbabilityArgs (Elab ()) TuneProbabilityArgs r => TuneProbabilityArgs (a -> (Nat1 -> Nat1) -> r)
doTuneProbabilities : TuneProbabilityArgs r => Visibility -> Elab () -> r- Totality: total
Visibility: export tuneProbabilities : {default Public _ : Visibility} -> TuneProbabilityArgs r => r A function for tuning probabilities of several constructors relative.
This function takes constructors to tweak and functions taking a default weight of a constuctor returning a final one.
Typical usage, considering that we want to have constructor `B` fire twice as often, and `C` thrice as often as the other, is the following.
```idris
data X = A | B | C
%runElab tuneProbabilities
B (*2)
C (*3)
```
Please refer to notices in the documentation of a function `tuneProbability`, they apply here too.
Totality: total
Visibility: export