Skip to content

Make prefix more type-stable #121

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ uuid = "7a57a42e-76ec-4ea3-a279-07e840d6d9cf"
keywords = ["probablistic programming"]
license = "MIT"
desc = "Common interfaces for probabilistic programming"
version = "0.11.0"
version = "0.11.1"

[deps]
AbstractMCMC = "80f14c24-f653-4e6a-9b94-39d6b0f70001"
Expand Down
35 changes: 22 additions & 13 deletions src/varname.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1112,19 +1112,28 @@ julia> AbstractPPL.prefix(@varname(x.a), @varname(y[1]))
y[1].x.a
```
"""
function prefix(vn::VarName{sym_vn}, prefix::VarName{sym_prefix}) where {sym_vn,sym_prefix}
function prefix(
vn::VarName{sym_vn,Toptic_vn}, prefix::VarName{sym_prefix,Toptic_prefix}
) where {sym_vn,sym_prefix,Toptic_vn,Toptic_prefix}
optic_vn = getoptic(vn)
optic_prefix = getoptic(prefix)
# Special case `identity` to avoid having ComposedFunctions with identity
if optic_vn == identity
new_inner_optic_vn = PropertyLens{sym_vn}()
else
new_inner_optic_vn = optic_vn ∘ PropertyLens{sym_vn}()
end
if optic_prefix == identity
new_optic_vn = new_inner_optic_vn
else
new_optic_vn = new_inner_optic_vn ∘ optic_prefix
end
return VarName{sym_prefix}(new_optic_vn)
new_optic = (optic_vn ∘ PropertyLens{sym_vn}()) ∘ optic_prefix
return VarName{sym_prefix}(new_optic)
end
function prefix(
::VarName{sym_vn,typeof(identity)}, prefix::VarName{sym_prefix,Toptic_prefix}
) where {sym_vn,sym_prefix,Toptic_prefix}
new_optic = PropertyLens{sym_vn}() ∘ getoptic(prefix)
return VarName{sym_prefix}(new_optic)
end
function prefix(
vn::VarName{sym_vn,Toptic_vn}, ::VarName{sym_prefix,typeof(identity)}
) where {sym_vn,sym_prefix,Toptic_vn}
new_optic = getoptic(vn) ∘ PropertyLens{sym_vn}()
return VarName{sym_prefix}(new_optic)
end
function prefix(
::VarName{sym_vn,typeof(identity)}, ::VarName{sym_prefix,typeof(identity)}
) where {sym_vn,sym_prefix}
return VarName{sym_prefix}(PropertyLens{sym_vn}())
end
Loading