Skip to content
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

When is it safe to use toLinear? #430

Open
L-as opened this issue Sep 12, 2022 · 1 comment
Open

When is it safe to use toLinear? #430

L-as opened this issue Sep 12, 2022 · 1 comment

Comments

@L-as
Copy link

L-as commented Sep 12, 2022

Describe the bug
There doesn't seem to be any documentation wrt. this.

@aspiwack
Copy link
Member

aspiwack commented Oct 3, 2022

Sorry, I've been a little unreachable in the past few weeks.

This is a good question, actually. My general rule of thumb is that it is safe to use Unsafe.toLinear when the function “would have been linear if all the primitives were given the appropriate type”. But it may not be very helpful.

There is a more in-depth version of this answer, which is that a function is linear if “whenever its result is consumed exactly once, its argument is also consumed exactly once”. The difficulty with this is that it is a slightly informal definition of linearity, and I don't actually know a way to make it fully precise. That being said, given this definition, you can say that you can use Unsafe.toLinear is the function really is linear (in the consume-exactly-once sense), even if the type system can't figure it out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants