probcomp / GenExperimental.jl

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

Illustrate a higher-order generator #62

Closed marcoct closed 6 years ago

marcoct commented 6 years ago

There doesn't seem to be anything preventing us from letting generators be higher-order (i.e. writing a generator that returns another generator). We can tag the creation point, and each call site of the created generator. tag directives will always apply to the trace that is the implicit argument to the most immediate enclosing @program.

Example:

@program higher_order_generator() begin
    mu = tag(normal(0, 10), "mu")
    std = tag(gamma(1, 1), "std")

    # returns a generator that is a closure
    @program () begin

        # returns a draw from a normal
        tag(normal(mu, std), "output")
    end
end
generator = tag(higher_order_generator(), "a")
...
tag(generator(), "b1")
tag(generator(), "b2")
marcoct commented 6 years ago

Done in https://github.com/probcomp/Gen.jl/blob/20170713-marcoct-generators/test/program.jl#L234-L242