-
-
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
use Typename for constructors with Int, Float32, etcetera #3007
Comments
Curiously, julia> type T
end
julia> Float64(::T) = 1.0
# methods for generic function Float64
Float64(::T) at none:1 Edit: OK, this is very weird. julia> Float64(x) = x
ERROR: error in method definition: function Core.Float64 must be explicitly imported to be extended
julia> import Core.Float64
julia> Float64(x) = x
ERROR: invalid method definition: not a generic function
julia> Float32(x) = x
# methods for generic function Float32
Float32(x) at none:1 |
In the first case, you've created a new function called |
I agree it would be much better not to have these redundant names. |
map? |
What about, for instance, |
Dup of #1470. |
The usual convention in Julia is that the constructor has the same name as the type, e.g. we construct an
Array
withArray(...)
etcetera.However, some of the bits types don't follow this rule: the constructor for
Int
isint(...)
, the constructor forFloat64
isfloat64(...)
, etcetera. This is inconsistent, annoying, and confusing.It is especially annoying because it means that a
typealias
for one of those types also does not have a constructor, e.g. there is no constructor forCint
. Of course, one could definecint(...)
but that is annoying (not to mention polluting the namespace).Right now, trying to define constructors named
Float32
etcetera fails:I'm not sure if there is any deep technical reason for this limitation?
The text was updated successfully, but these errors were encountered: