-
Notifications
You must be signed in to change notification settings - Fork 10
Description
Hi @thautwarm ,
In a new version of Soss, I'm trying to really nail down type stability. Using GG I was having lots of trouble getting constructions like
For(n -> Normal(α + β * x[n], σ), 1:N)to be type-stable.
After lots of exploring, I realized this could be solved by putting this function outside of GG:
f(ctx, n) = Normal(ctx.α + ctx.β * ctx.x[n], ctx.σ)
f(ctx::NamedTuple) = Base.Fix1(f, ctx)Then within GG, it could be called as
For(f((;α,β,σ,x)), 1:N)That works great, but it's tricky to automate, since the f needs to be made available separately within the module, and I'd rather not use eval to put it there.
I eventually found this to work:
For(let f = ctx -> Base.Fix1(ctx) do ctx, n
Normal(ctx.α + ctx.β * ctx.x[n], ctx.σ)
end
f((; α, β, σ, x))
end, 1:N)So now, I think I can just rewrite things this way before calling GG. But I wanted to check with you before doing this, since it seems plausible the current Closure approach could be updated to something similar, and maybe it would help other cases with type stability. What do you think?