Stream: beginners

Topic: Abilities misunerstanding


view this post on Zulip Kiryl Dziamura (Feb 06 2024 at 12:04):

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

view this post on Zulip Brendan Hansknecht (Feb 06 2024 at 15:53):

For the second one, does wrapping in an explicit lambda fix the issue?

view this post on Zulip Kiryl Dziamura (Feb 06 2024 at 16:05):

added a couple of comments there: https://github.com/wontem/roc-rand/pull/4#discussion_r1480095154

view this post on Zulip Kiryl Dziamura (Feb 06 2024 at 16:08):

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

view this post on Zulip Brendan Hansknecht (Feb 06 2024 at 16:13):

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.

view this post on Zulip Brendan Hansknecht (Feb 06 2024 at 16:13):

In this case failed to specialize on all captured values in the lambda

view this post on Zulip Brendan Hansknecht (Feb 06 2024 at 16:17):

In the unexpected type, using XorShift32.u64 looks wrong to me. Shouldn't it be RngCore.u64?

view this post on Zulip Brendan Hansknecht (Feb 06 2024 at 16:19):

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

view this post on Zulip Brendan Hansknecht (Feb 06 2024 at 16:19):

So type mismatch

view this post on Zulip Brendan Hansknecht (Feb 06 2024 at 16:23):

Said a different way, you are constraining the generator too early.

view this post on Zulip Brendan Hansknecht (Feb 06 2024 at 16:23):

Really is shouldnt be constrained until running the generator

view this post on Zulip Kiryl Dziamura (Feb 06 2024 at 16:24):

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

view this post on Zulip Brendan Hansknecht (Feb 06 2024 at 17:14):

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

view this post on Zulip Brendan Hansknecht (Feb 06 2024 at 17:14):

That said, feels like it shouldn't strictly be needed to constrain the type

view this post on Zulip Brendan Hansknecht (Feb 06 2024 at 17:15):

Hmm...actually in the hasher case, the init function is unique by hasher and complete is generic.

view this post on Zulip Brendan Hansknecht (Feb 06 2024 at 17:16):

So that would be more like the seed function being specific cause it is actually generating a specific RNG implementation.

view this post on Zulip Brendan Hansknecht (Feb 06 2024 at 17:16):

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