While playing with ability-based prngs, I came across multiple problems with abilities/lambda sets. Please help to figure out if it's my misunderstanding or lambda-set bugs? Here are branches with problem reproductions:
there are more problems I encountered but they are most likely just other variants of the ones above
For the second one, does wrapping in an explicit lambda fix the issue?
added a couple of comments there: https://github.com/wontem/roc-rand/pull/4#discussion_r1480095154
so for the wrapped variant without type annotation, the result is the same, but with it - the comilation fails with the same error as in the no lambda set found
example
Ok. For no lamda set found
I am pretty certain it is a compiler bug. It basically means we failed to generate the correctly specialized version of a function.
In this case failed to specialize on all captured values in the lambda
In the unexpected type, using XorShift32.u64
looks wrong to me. Shouldn't it be RngCore.u64
?
Bool wants to return a generator that can be used with any RNG. Then you are forcing it to return a generator that can only be used with xorshift
So type mismatch
Said a different way, you are constraining the generator too early.
Really is shouldnt be constrained until running the generator
Yeah, it already changed in the main branch. But the problem is still there just pops earlier. I’ll add another example a bit later, afk now
You might need the equivalent of Hasher.complete except that in this case it would take a generator and return the final value. https://github.com/roc-lang/roc/blob/d62cc0b1d3e540a42bf58c4e3848c115f614a6c8/crates/compiler/builtins/roc/Hash.roc#L64
That said, feels like it shouldn't strictly be needed to constrain the type
Hmm...actually in the hasher case, the init function is unique by hasher and complete is generic.
So that would be more like the seed function being specific cause it is actually generating a specific RNG implementation.
That said, I would bet you can make the completion function specific instead. Fundamentally it should be one of the two ends
Last updated: Jul 06 2025 at 12:14 UTC