ponylang / rfcs

RFCs for changes to Pony
https://ponylang.io/
59 stars 48 forks source link

Type parameter constraint syntax for safe matches. #105

Open jemc opened 6 years ago

jemc commented 6 years ago

As discussed on today's sync call, due to @Theodus finding a standard library breakage in the planned fix for https://github.com/ponylang/ponyc/issues/2182#issuecomment-335878405, I think that adding syntax to our constraint language to fix that issue is a higher priority than previously thought.

Specifically, we need an RFC for new syntax that can be used in a type parameter constraint to require that the type parameter is safe to put in a match expression against some other type.

So, for ListNode, it might look like this (with a more elegant syntax):

class ListNode[A: canbematchedagainst None]

This would imply that a match expression containing the right-side operand type and the type argument would not be subject to the error "this match violates capabilities".

jemc commented 6 years ago

Note that this probably needs a bit more thought, but I'm just filing this ticket here to capture the discussion so far.

Praetonus commented 6 years ago

I'm currently investigating a proposal for this, based on a relative complement type set operator.

shelby3 commented 5 years ago

Pointing out that I’m positing in #2182 that the problem might be more fundamental in the design choices for Pony’s type system. And that adding “hacks” for corner cases caused by design choices is probably not going to end well. If my hypothesis is correct, then perhaps redesigning Pony’s type system from the ground up is the real solution.