Skip to content

use Typename for constructors with Int, Float32, etcetera #3007

@stevengj

Description

@stevengj

The usual convention in Julia is that the constructor has the same name as the type, e.g. we construct an Array with Array(...) etcetera.

However, some of the bits types don't follow this rule: the constructor for Int is int(...), the constructor for Float64 is float64(...), 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 for Cint. Of course, one could define cint(...) but that is annoying (not to mention polluting the namespace).

Right now, trying to define constructors named Float32 etcetera fails:

julia> import Core.Float32
julia> Float32(x) = float32(x)
ERROR: invalid method definition: not a generic function

I'm not sure if there is any deep technical reason for this limitation?

Metadata

Metadata

Assignees

No one assigned

    Labels

    needs decisionA decision on this change is needed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions