Currently the abstract Generator is parameterized by the type T of the trace that it can generate! into. However, the return type V is not defined. The Generator should also be parameterized by the return type (which is not restrictive because this type parameter can be set to Any). Then the return type of generate is known at compile time: Tuple{T,V}.
This may be relevant for performance optimization.
Some comments specifically for ProbabilisticProgram generators: Currently, the return type is not known at compile-time because the return value of the program can be set in the trace to any value. There is no reason why the ProgramTrace type cannot be parametric on the return value (and have its constructor take the return type as an argument). The intervene! method will not be typed, because the same method is used to intervene on the program's own output as well as any internal addresses. If the user intervenes on the program's return value (using the address ()) with a value of the wrong type, then a type error will be be thrown some time during the generate! call (not during the intervene! call).
Currently the abstract
Generator
is parameterized by the typeT
of the trace that it cangenerate!
into. However, the return typeV
is not defined. TheGenerator
should also be parameterized by the return type (which is not restrictive because this type parameter can be set toAny
). Then the return type ofgenerate
is known at compile time:Tuple{T,V}
.This may be relevant for performance optimization.
Some comments specifically for
ProbabilisticProgram
generators: Currently, the return type is not known at compile-time because the return value of the program can be set in the trace to any value. There is no reason why theProgramTrace
type cannot be parametric on the return value (and have its constructor take the return type as an argument). Theintervene!
method will not be typed, because the same method is used to intervene on the program's own output as well as any internal addresses. If the user intervenes on the program's return value (using the address()
) with a value of the wrong type, then a type error will be be thrown some time during thegenerate!
call (not during theintervene!
call).