17205, "bradcray", "Feature request (CG): A way to compose interfaces", "2021-02-19T20:38:47Z"
In thinking about using Chapel's interfaces to describe arrays, I realize that I think of arrays as having a number of reasonably independent properties that I might want to tease into distinct interfaces such as "indexable", "iteratable", "sliceable", "rank changeable", etc. where a full-blown array would support all of these things. However, for a given library routine I might only want to assert a subset of these interfaces without requiring an argument to support everything that's part of an array's nature. For example "the argument to this routine must be indexable and iteratable" (but I don't care about all of that other stuff).
I think that, today, I'd have to write this using something like:
proc foo(x: ?t) where t implements iteratable && t implements indexable
which seems like a mouthful.
This issue asks how such interfaces could be composed. For example, perhaps I could write something like:
interface indexAndIter {
implements indexable;
implements iterable;
}
and then:
proc foo(x: indexAndIter) { ... }
Or perhaps there ought to be a way to compose interfaces directly within a formal type as a shorthand for the long where clause, like:
proc foo(x: iterable && indexable) { ... }
though I don't think &&
is the right syntax, and I'm concerned that there may not be a syntax that is sufficiently clear and compact (but I haven't thought about it very hard).