ponylang / ponyc

Pony is an open-source, actor-model, capabilities-secure, high performance programming language
http://www.ponylang.io
BSD 2-Clause "Simplified" License
5.71k stars 415 forks source link

RFC: Copy Idiom #1138

Open SeanTAllen opened 8 years ago

SeanTAllen commented 8 years ago

see: https://github.com/ponylang/rfcs/blob/master/text/0009-copy-idiom.md

Theodus commented 8 years ago

While trying to implement this I encountered the following error when changing the signature of List.from in list.pony#L21 to fun from(that: List[A^] box) =>:

/home/theodus/stuff/ponyc/packages/collections/list.pony:26:12: argument not a subtype of parameter
      push(consume value)
           ^
    Info:
    /home/theodus/stuff/ponyc/packages/collections/list.pony:26:7: A tag is not a subtype of A iso: the subtype has no constraint
          push(consume value)
          ^
    /home/theodus/stuff/ponyc/packages/collections/list.pony:26:7: A box is not a subtype of A trn: the subtype has no constraint
          push(consume value)
          ^
    /home/theodus/stuff/ponyc/packages/collections/list.pony:26:7: A box is not a subtype of A ref: the subtype has no constraint
          push(consume value)
          ^
    /home/theodus/stuff/ponyc/packages/collections/list.pony:529:37: (A tag, A box, A box, A val, A box, A tag) is not a pairwise subtype of (A iso, A trn, A ref, A val, A box, A tag)
      fun values(): ListValues[A, this->ListNode[A]]^ =>

I'm confused about what the problem is and how it can be solved, especially since it works fine when that is a ref instead of a box.

SeanTAllen commented 8 years ago

Is that the only thing you changed @Theodus ?

Theodus commented 8 years ago

It is the only change made to List.

jemc commented 8 years ago

We discussed on the call that there are compiler limitations that prevent this idiom from working as expected.

Action items (as I understand them):

The idea is that the end result will be calling Foo.from(foo) where foo is a Foo ref will yield a Foo ref, and where foo is a Foo val will yield a Foo val, etc.

SeanTAllen commented 8 years ago

@jemc should we have new issues for the above action items?

SeanTAllen commented 2 years ago

@jemc did we ever discuss how:

Adjust the compiler and/or type system to allow constructors to have their cap affected by the type parameter.

would work and what the impact on existing pony code would be? would this be something that should be a request for RFC?

jemc commented 2 years ago

I think this would need a new RFC of its own, yes.