On 9 Mar 2022, at 6:28, Brian Goetz wrote:

>> Also, i wonder if the external Carrier API should have a way to wrap an 
>> existing record class to see it as a Carrier, so the destructuring pattern 
>> will behave the same way with a record or with the result of a 
>> de-constructor.
>
>  Having records be their own carrier is an optimization we anticipate wanting 
> to make, but I don’t think it is needed for Carrier to be involved in the 
> deception. We’ll need a higher-level representation of a pattern (e.g., 
> PatternHandle), which will exposes MHs for “try to match, return a carrier if 
> it matches” and MHs for deconstructing the carrier.  A PH could use the 
> record itself as the carrier, and the record’s accessor MHs as the component 
> accessors, and not use Carrier at all, and the PH client can’t tell the 
> difference.
>
>  So Carrier here is intended to be the lowest level of the stack; a building 
> block for aggregating tuples, nothing more.  We can then build pattern 
> matching atop that (which can use Carrier or not, as it sees fit) and switch 
> dispatch atop that.

I hereby dub this optimization (of using the original record instead of an 
anonymously-typed copy) as “BYOC”, or Bring Your Own Carrier.

Whether the Carrier API needs to know about it depends on one factor:  Whether 
Carrier (or CarrierBindings or CarrierHandles) is a quasi-reflective object 
that helpfully combines the constructor and list-of-component-accessors.  If 
so, the BYOC use case suggests an external constructor for that little record.  
In fact, it’s probably exactly and only a little record, and we are done.

But if we manage to avoid introducing such a little record (of ctor+acsors) 
then we push that job upward (out of the Carrier API) and at that point BYOC 
happens in the context of BYOCHR (Bring Your Own Carrier Handles Record).

I’m not super happy about BYOCHR; it seems like an invitation to duplicate 
effort.

Perhaps there should be a type Carrier.Handles which is exactly that 
simple-as-can-be record.  It’s what the carrier factory (now there’s just one 
static factory, keyed by MethodType?) returns.  But as a Record, it can also be 
used (trivially) for BYOC, if some user has other handles that would be nicer.

Something to consider.

— John

Reply via email to