probcomp / GenExperimental.jl

Featherweight embedded probabilistic programming language and compositional inference programming library
MIT License
17 stars 2 forks source link

Declare the return type of Generator #63

Open marcoct opened 6 years ago

marcoct commented 6 years ago

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).