-
-
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
deprecate typealias
in favor of const
assignment or A{B} = ...
#20500
Conversation
When do you have to use |
base/array.jl
Outdated
typealias DenseVector{T} DenseArray{T,1} | ||
typealias DenseMatrix{T} DenseArray{T,2} | ||
typealias DenseVecOrMat{T} Union{DenseVector{T}, DenseMatrix{T}} | ||
AbstractVector{T} = AbstractArray{T,1} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do these not have const?
In function definitions |
I just realized |
I'm all for getting rid of However, I'm skeptical that we want a new abbreviated syntax here. Parameterized typealiases are a lot less common than one-line functions, and every new syntax we add also makes the language more complicated to learn. Can we just do |
I'm fine with allowing |
Ah, fortunately due to sufficiently generic code |
abf6f9b
to
6d6a3c3
Compare
What are the practical differences between saying |
If |
Yes, it's just a normal const vs. non-const binding. |
Thanks. I like the idea of a convenient syntax for the parametric case but am a little worried that the performance subtleties will trip people up if the const is implicit. I'm pretty familiar with Julia, but the parallels between the new syntax ( Julia itself has quite a few typealiases without parameters, so it seems to be a pretty common thing. |
looks like this test Line 701 in 6d6a3c3
&& ? seems kinda unrelated but harmless enough?
edit: should probably run and update any doctests that will have their output changed here |
Agreed; it would really be nice if global bindings could be const by default (and use e.g. |
What about everything being |
That could work. Of course if any code gets compiled before the module closes, it would not be able to take advantage of const-ness. Maybe it could be a per-module property; you can say that a certain module should have non-const-by-default bindings, which would normally only be used by the repl. |
We could keep track of methods that were compiled before the module was closed and which depended on a global. Closing the module would then invalidate their code, forcing them to be recompiled. Confused face was because I don't like the idea of this as a module setting. |
Yes we could do that, but compiling things twice is going to hurt load times even more. |
6d6a3c3
to
c7fc80c
Compare
Ok, I took out the change to |
If a function uses a global while its module is still open, that would be a good heuristic to decide to use an interpreter – if we end up having a full-fledged one. That way compilation would occur:
That way the compilation time wouldn't be affected. |
c7fc80c
to
ba69d93
Compare
ba69d93
to
4467508
Compare
The behaviour with julia> const Foo{Int} = Vector
Array{T,1} where T
julia> Foo
Array{T,1} where T
julia> Foo{Int}
Array{Int64,1} julia> const Bar{Int} = Float64
Float64
julia> Bar
Float64
julia> Bar{Int}
ERROR: TypeError: Type{...} expression: expected UnionAll, got Type{Float64} julia> const Baz{1} = Int
ERROR: syntax: malformed expression Maybe these could use better errors? |
I'll fix the The |
Ah thanks, the first example makes sense now. For the second, is the extra argument being ignored in the definition but not in usage? I would expect that if |
typealias
is now completely redundant, as it is just aconst
assignment of a name to a type. I also added the syntaxin analogy to short-form function definitions.