Closed colin-mcd closed 2 years ago
In (3), factor FLOAT
either needs to return unit
or have a type, right? Although fail
can have type Unit
, I imagine there are lots of situations where that's not convenient, so it's probably best for it to have a type.
I don't remember the concrete experience to justify it anymore, but I agree that fail
at arbitrary (hence specified) type is good to have. In Hakaru (cue harp music) we indeed had fail
require explicit : TYPE
, and prohibited nullary amb
.
The only reason I see for the extra sample
is that some languages have weak transforms that cannot deal with distributions built with "bind", and sample
distinguishes those distributions that are not built with "bind".
factor FLOAT
(implicitly of type unit
) is nice to have.
I am neutral about whether to provide uniform
.
Unlike (1) and (3), only sample amb : TYPE
(which I would just write as amb : TYPE
) allows someone to express the "flat" "distribution" without caring what TYPE
is. For all they know, TYPE
is a function type, and our nonstandard interpretation of functions kicks in. I don't know that we need to allow this in the implementation.
Maybe it's not great that amb
(as opposed to sample amb
) is equivalent to fail
.
We currently allow both
amb a b ... z
(wherea
,b
, ...,z
all have the same type, and each get weight 1) andsample amb : TYPE
(which assigns weight 1 to all inhabitants of TYPE). But we it would be nice to pick one form of the syntax.Some options/ideas:
amb a b ... z
,uniform a b ... z
,fail : TYPE
sample amb : TYPE
,sample uniform : TYPE
,sample fail : TYPE
amb a b ... z
,factor FLOAT
,fail
(wherefactor
multiplies branch weight by a float, andfail
has typeUnit
)In practice, option (1) has felt nicer to write code with because of how annoying it is if you want to
amb
3 terms:amb a b c
vsif (sample amb : Bool) then a else if (sample amb : Bool) then b else c
. But because we synthesize types, (1) needsfail
to have: TYPE
after it in contrast toamb
anduniform
. @davidweichiang suggested option (3), which seems pretty nice.