JuliaLang/julia — pull request #8712 by JeffBezanson (2014-10-17 22:02:15+00:00)
Title: call overloading, and make constructors use it

Behold, after a week of red Xes, the tests are passing.

This replaces #8008 and also redesigns constructors to use `call` overloading instead of having some types magically also be generic functions.

An inner constructor looks like

```
call{T}(::Type{MyType{T}}, args...) = ...
```

and an outer constructor looks like

```
call{T}(::Type{MyType}, x::T) = MyType{T}(x)
```

Now you can also have things that are in-between, for example this `SubArray` constructor:

```
function call{T,A<:Array,I<:(Any,)}(::Type{SubArray{T,0,A,I}}, p::A, i::(Int,))
new{T,0,A,I}(p, i, (), Int[], i[1])
end
```

Notice `new{...}` has been added and is needed in cases like this.

Of course, you can also define constructors for abstract types which should be helpful in several cases that have come up over time.

An interesting side effect of this change is that this:

```
convert{T}(::Type{T}, x::T) = x
```

now correctly implements "conversions" to supertypes (e.g. `convert(Number, 1)`).

---

This raises several interesting discussion questions that have not been resolved yet:

- How should method reflection work? Do we preserve the illusion that types are "callable"?
- What to do with the `Callable` type? Maybe make `Function` an abstract type instead?
- How do we make `call` fall back to `convert`, and also to `call` in lower-level modules (see https://github.com/JuliaLang/julia/pull/8008#issuecomment-59574788)?
- We can now remove the dreaded "lower-case" conversion functions, but should `Int8(x)` be vectorized?