Skip to content

Commit d26c04e

Browse files
committed
Rename bind to mbind and deprecate rightarrowtail
Bind has too much naming conflict potential with Base.bind. The rightarrowtail operator looks very similar to the `>=>` "fish" operator (e.g. in Haskell), which is not a monadic bind.
1 parent 8178c55 commit d26c04e

File tree

1 file changed

+29
-16
lines changed

1 file changed

+29
-16
lines changed

src/combinators/bind.jl

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,34 +3,47 @@ struct Bind{M,K} <: AbstractMeasure
33
k::K
44
end
55

6-
export
76

87
"""
9-
If
10-
- μ is an `AbstractMeasure` or satisfies the Measure interface, and
11-
- k is a function taking values from the support of μ and returning a measure
8+
mbind(k, μ)::AbstractMeasure
9+
10+
Given
11+
12+
- a measure μ
13+
- a kernel function k that takes values from the support of μ and returns a
14+
measure
1215
13-
Then `μ ↣ k` is a measure, called a *monadic bind*. In a
14-
probabilistic programming language like Soss.jl, this could be expressed as
16+
The *monadic bind* operation `mbind(k, μ)` returns is a new measure.
1517
16-
Note that bind is usually written `>>=`, but this symbol is unavailable in Julia.
18+
A monadic bind ofen written as `>>=` (e.g. in Haskell), but this symbol is
19+
unavailable in Julia.
1720
1821
```
19-
bind = @model μ,k begin
20-
x ~ μ
21-
y ~ k(x)
22-
return y
22+
μ = StdExponential()
23+
ν = mbind(μ) do scale
24+
pushfwd(Base.Fix1(*, scale), StdNormal())
2325
end
2426
```
25-
26-
See also `bind` and `Bind`
2727
"""
28-
(μ, k) = bind(μ, k)
29-
30-
bind(μ, k) = Bind(μ, k)
28+
mbind(k, μ) = Bind(μ, k)
29+
export mbind
3130

3231
function Base.rand(rng::AbstractRNG, ::Type{T}, d::Bind) where {T}
3332
x = rand(rng, T, d.μ)
3433
y = rand(rng, T, d.k(x))
3534
return y
3635
end
36+
37+
38+
# ToDo: Remove `bind` (breaking).
39+
@noinline function bind(μ, k)
40+
Base.depwarn("`foo(μ, k)` is deprecated, use `mbind(k, μ)` instead.", :bind)
41+
mbind(k, μ)
42+
end
43+
44+
45+
# ToDo: Remove `↣` (breaking): It looks too similar to the `>=>` "fish"
46+
# operator (e.g. in Haskell) that is typically understood to take two monadic
47+
# functions as an argument, while a bind take a monad and a monadic functions.
48+
@deprecate (μ, k) mbind(μ, k)
49+
export

0 commit comments

Comments
 (0)