19239, "stonea", "Should we deprecate "is type subtype of" querying operators?", "2022-02-11T17:42:32Z"
Currently types can be compared using the <
, <=
, and >
, and >=
operators to see if one type is a subtype of another.
On the one hand, using operators to express this seems kind of clever but on the other it may not be clear to end-users what these operators do. I think we should deprecate these operators in favor of using functions. The types module already has isSubtype
and isProperSubtype
functions and spelling it out seems clearer to me.
@mppf brought to my attention that one context to think about is using these operators in a where
clause for a generic function (where maybe we want things to be more concise):
It used to be that you could write
proc f(arg: integral)
or procf(arg: ?t) where t:integral
but at some point I needed:
to behave as the usual cast in a where clause so deprecated that. When I did, I changed these toproc f(arg: ?t) where t <= integral
. Arguably having to writeproc f(arg: ?t) where isSubtype(t, integral)
is wordy for this use case. One thing to note is that certain PL theorists would think this is the only reasonable way to write a generic function (they don't think of generic types and concrete types as the same category of thing).