@Toivo:

Thanks! I didn't know you could parametrize type aliases. Ths solution is
exactly what I was looking for. Although I agree the shorthand proposal
would be nice as well.


On Mon, May 26, 2014 at 2:35 PM, John Myles White <johnmyleswh...@gmail.com>
wrote:

> I’ve often thought that Array{T <: Any} would be easier to understand, so
> +1 for this.
>
>  — John
>
> On May 26, 2014, at 12:33 PM, Toivo Henningsson <toivo....@gmail.com>
> wrote:
>
> Or you can use
>
>     typealias FPArray{T<:FloatingPoint} Array{T}
>
>     foo(a::FPArray, b::FPArray) = a+b
>
> to get the same effect (foo will still apply when the element types of a
> and b are different).
>
> Perhaps we could introduce a syntax to create such a covariant typealias
> on the fly, e.g.
>
>     const FPArray2 = Array{<:FloatingPoint}
>
> would work the same as FPArray above (though with an anonymous/hidden
> type parameter).
> Then the example could be written
>
>     foo(a::Array{<:FloatingPoint}, b::Array{<:FloatingPoint}) = a+b
>
> if you don't want to define the typealias first.
>
> On Sunday, 25 May 2014 17:44:26 UTC+2, Pierre-Yves Gérardy wrote:
>>
>> On Sunday, May 25, 2014 5:10:49 PM UTC+2, James Crist wrote:
>>>
>>> Yeah, that's what I've been using. My issue with it is that the
>>> declarations get long for functions with more than 2 arrays. Was hoping
>>> there was a more concise way.
>>>
>>
>> You can use  typealias Fp FloatingPoint , then
>>
>> function foo{T1<:Fp, T2<:Fp}(a::Array{T1}, b::Array{T2})
>>
>>
>

Reply via email to