4 ms·
> The return type of methods cannot be specified / enforced. That's true in one sense - typed functions aren't really a thing yet (functor types are, but they'
by thenoether 11y ago
> The return type of methods cannot be specified / enforced.
That's true in one sense - typed functions aren't really a thing yet (functor types are, but they're more clumsy to use in a lot of cases).
With regards to your first point, you can actually specify the types of returned values by utilizing assertions:
julia> h{T}(x::T) = f(g(x))::Complex{T}
h (generic function with 1 method)
Type inference should totally pick up on the return type declared here, and an error is thrown if `f(x)` does not return something of type `Complex{T}`.
Assertions obviously don't address all of the concerns you listed, but I find they still help a lot to address type inference "failures" in some places, and seem to be underutilized in a few cases.
This doesn't help any memory boxing/slowness inherent to `f` or `g`, but downstream methods (e.g. callers of `h`) can definitely benefit from the explicit information.
- thenoether 11y ago> if `f(x)` does not return something of type `Complex{T}` Sorry, meant to say "if `f(g(x)` does not return something of type `Complex{T}`"