Is it possible in Julia?: Support a limited type inference version in order to decide whether a function is defined or not

But traits are solution to that problem that just work fine already — framing this as “forcing” is a bit of a stretch.

FWIW, for the reasons discussed in this topic, I don’t think that conditioning code paths on whether they would error is a solution that meshes well with how Julia works (and I don’t know about any language that would support this well). Effectively you want to use errors for control flow, which is already a code smell, and rely on the compiler to predict them, which it is not designed for (not all errors are “type stable” in the sense that the method signature is enough to predict them).

Also, from a practical perspective, MethodErrors can happen down the line even when a particular function was intended to be defined, but there is a bug in the code (it is probably in the top 5 for trivial coding mistakes).

2 Likes