On Thursday, May 1, 2014 9:59:08 AM UTC+1, Oliver Woodford wrote:
>
> On Wednesday, April 30, 2014 9:13:50 PM UTC+1, Stefan Karpinski wrote:
>>
>> Back to the original subject, because I think there's some value in
>> summarizing it.
>>
>> 1. Variance. It is somewhat unintuitive to a lot of newcomers that in
>> Julia Array{Real} is a concrete type and Array{Int} is not a subtype of it.
>> It might be possible to make parametric types in Julia covariant by
>> default, but then one must either come up with a different way of writing
>> the concrete type currently known as Array{Real} or allow concrete
>> parametric types like Array{Real} to have subtypes, namely Array{T} for
>> each T <: Real.
>>
>
>> 2. Restricting type parameters to concrete types. The variance issue was
>> a bit of a red herring. What Oliver was really after, it seems (correct me
>> if I'm wrong), was being able to ensure that the T in Array{T} is always a
>> concrete type.
>>
>
> Well, that would certainly be a solution. You could have a type modifier,
> say Concrete(Real), which returns the union of all concrete types which are
> subtypes of Real (or whatever). Then you could use:
> frob{T<:Concrete(Real)}(x:Array{T})
> to assert that input arrays are homogeneous.
>
> What I would really like is to be able to write:
> frob(x:Array{Concrete(Real)})
> instead, because the static parameter seems as redundant to a beginner as
> it does in frob{T<:Real}(x::T). However, I understand that the two are
> different in the case of arrays/parameterized types, as the latter also
> encompasses some heterogeneous array types, and that that won't change
> unless the variance of Julia is changed. I'm not in a position to advocate
> such a thing.
>
In fact, under the current type system frob(x:Array{Concrete(Real)}) is
exactly equivalent to frob(x:Array{Real}). Julia could have a different
type system, where "Concrete()" implies covariance, such that
frob(x:Array{Concrete(Real)}) enforces arrays to be homogeneous (i.e.
frob(x:Array{Concrete(Real)}) and frob(x:Array{Real}) are different),
without losing the ability to describe any current array types. Just
throwing it out there. Possibly more confusing than enabling.