I came upon this when thinking about the semantics of probabilistic programs. Say you have a generative model
N ~ Poisson()
for n = 1:N
X[i] ~ Normal()
Then the size of X
will stochastically depend on N
. Thinking about this as dependent pairs, I would intuitively write something like
$$ X : \sum_{n \sim \operatorname{Poisson}()} \operatorname{Vect} n $$
Has anyone come up with such a theory of representing stochastic structure by dependent types?
For a bit of context, I am interested in ways how trace types could be extended to more dynamic settings, in the sense of probabilistic programs that would require a trace type whose key space is itself random (i.e., the encountered variables and their shapes can vary in sampling).
bind
is parametrized in the types of its arguments:(rpoisson()::Prob Nat >>= \n -> rnorm(n)::Prob (Pi_{n:Nat} Vect n))::Prob (Sigma_{n:Nat} Vect n)
, or something like that? $\endgroup$X
change size based onN
, so it is dynamic. $\endgroup$