-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
possible missing promote_type #5588
Comments
There are promotions for instantiated versions of |
I realize that, but the user gave an array of type Rational, and my code was attempting to guess the output type for the array. Even better would be to take advantage of type inference. Can we add the following to Base? macro static_typeof(expr)
Expr(:static_typeof, esc(expr))
end |
I don't think that will help in this case; the lack of a promotion rule for that means type inference also doesn't know what the result should be. For example You really want to avoid |
Currently, I'm simulating |
In this case, at the moment, static_typeof would probably give Any. Happy?
|
static_typeof actually seems to work quite well at not giving Any (assuming this is in a function and N is known -- I don't expect it to be magical). Cases where it seems like it would be useful: Ensuring type-stability of short-circuiting code: function f(x)
if iserror_condition(x)
return oftype(@static_typeof y, 0)
end
y = do_something_complicated(x)
return y
end Initializing loop variables with a best guess type: function g(x)
y = oftype(@static_typeof x/1, 1)
for i = 1:10
y += x/y
end
y
end Preallocating arrays with a best guess type:
|
I think we need a better approach than this. This is first of all ugly, and the first case doesn't work since
Basically indicating that the assignment from 0 should not be taken type-literally. |
Empty type definition I like the idea, to the compiler it would mean: "ignore this line in computing type information for this variable, then use For the first case, we might want something like the following, which would cause a call to function f(x)
if iserror_condition(x)
return::ANY 0
end
y = do_something_complicated(x)
return y
end I don't know how to express the third option here. But two out of three seems like a huge gain. |
came up in vtjnash/Polynomial.jl#12
The text was updated successfully, but these errors were encountered: