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

allow linear usage by using all fields #11

Open
tjhance opened this issue Dec 15, 2020 · 0 comments
Open

allow linear usage by using all fields #11

tjhance opened this issue Dec 15, 2020 · 0 comments
Labels
enhancement New feature or request

Comments

@tjhance
Copy link
Collaborator

tjhance commented Dec 15, 2020

This would be nice to have, but it's probably complicated, and would likely require a more comprehensive proposal than is here.

It would be nice if I could "use" a linear datatype variable by using all of its fields without having to explicitly destruct it.

Here's a very simple example, with a single-constructor datatype:

linear datatype Foo = Foo(linear a: Bar, linear b: Bar)

method destroy_foo(linear foo: Foo)
{
  destroy_bar(foo.a);
  destroy_bar(foo.b);
}

Support this for a multiple-constructor datatype would be a far more advanced proposal. To see why it's hard, consider this example:

linear datatype Option<V> = Some(linear value: V) | None
method destroy_opt(linear opt: Option<Bar>)
{
  if opt.Some? {
    destroy_bar(opt.value);
  } else {
  }
}

The linear typechecker would need to infer that the None constructor is used implicitly in the else branch, and create a proof obligation that opt.None? is used in the else branch. However, I don't think this feature would be impossible.

@tjhance tjhance added the enhancement New feature or request label Dec 15, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant