Well, not all arrays:

julia> Array{Int}()
0-dimensional Array{Int64,0}:
4544954880


On Wednesday, August 12, 2015 at 11:36:24 AM UTC-4, Mauro wrote:
>
>
>
> On Wed, 2015-08-12 at 17:28, Cedric St-Jean <[email protected] 
> <javascript:>> wrote: 
> > On Wednesday, August 12, 2015 at 12:15:19 AM UTC-4, Stefan Karpinski 
> wrote: 
> >> 
> >> You can't create a value whose concrete type is Tuple{AbstractString, 
> >> AbstractString} but you can create values that are of that type and you 
> can 
> >> create an instance of Vector{Tuple{AbstractString, AbstractString}}: 
> >> 
> >> julia> baz(a::Vector{Tuple{AbstractString, AbstractString}}) = 3 
> >> baz (generic function with 1 method) 
> >> 
> >> julia> baz(Vector{Tuple{AbstractString,AbstractString}}()) 
> >> 3 
> >> 
> >> 
> >> 
> > Interesting. Does that really work in 0.4? I tried to replicate in 0.3 
> with 
> > 
> > Vector{(AbstractMatrix,AbstractMatrix)}() 
> >> type cannot be constructed 
>
> A bit confusingly arrays are not constructed like that: 
>
> julia> Vector{Int}() 
> ERROR: type cannot be constructed 
>
> Instead: 
>
> julia> (AbstractMatrix,AbstractMatrix)[] 
> 0-element Array{(AbstractArray{T,2},AbstractArray{T,2}),1} 
>
> > What kind of object is a Vector{Tuple{AbstractString,AbstractString}}()? 
> > Does it have memory allocated to it? What is that construction good for? 
>
> It can hold any tuple t for which isa(t, (AbstractMatrix,AbstractMatrix)) 
> is true.  For instance: 
>
> julia> push!(a, ([1,2]', speye(3))) 
> 1-element Array{(AbstractArray{T,2},AbstractArray{T,2}),1}: 
>  ( 
> 1x2 Array{Int64,2}: 
>  1  2, 
>
> 3x3 sparse matrix with 3 Float64 entries: 
>         [1, 1]  =  1.0 
>         [2, 2]  =  1.0 
>         [3, 3]  =  1.0) 
>
>
> Under the hood it is an array of pointers pointing to its entries. 
>
> > Cédric 
> >   
> > 
> >> 
> >> 
> >> On Wed, Aug 12, 2015 at 12:09 AM, Cedric St-Jean <[email protected] 
> >> <javascript:>> wrote: 
> >> 
> >>> Is it correct to say that: 
> >>> 
> >>> baz(a::Vector{Tuple{AbstractString, AbstractString}}) = 3 
> >>> 
> >>> is uncallable, since we can't instantiate an AbstractString? Maybe it 
> >>> should trigger an error/warning on definition. 
> >>> 
> >>> Cédric 
> >>> 
> >>> On Tuesday, August 11, 2015 at 4:18:38 PM UTC-4, Stefan Karpinski 
> wrote: 
> >>>> 
> >>>> Same thing – even though 
> >>>> 
> >>>> Tuple{ASCIIString,ASCIIString} <: Tuple{String,String} <: Tuple 
> >>>> 
> >>>> 
> >>>> due to invariance, we still have these: 
> >>>> 
> >>>> !(Vector{Tuple{String,String}} <: Vector{Tuple}) 
> >>>> 
> >>>> !(Vector{Tuple{ASCIIString,ASCIIString}} <: Vector{Tuple}) 
> >>>> !(Vector{Tuple{ASCIIString,ASCIIString}} <: 
> Vector{Tuple{String,String} 
> >>>> }) 
> >>>> 
> >>>> 
> >>>> On Tue, Aug 11, 2015 at 4:13 PM, Seth <[email protected]> 
> wrote: 
> >>>> 
> >>>>> Thanks, Stefan. I understand that causing the problem for baz(), but 
> >>>>> why does this explain bar()'s failure? 
> >>>>> 
> >>>>> On Tuesday, August 11, 2015 at 1:10:27 PM UTC-7, Stefan Karpinski 
> wrote: 
> >>>>>> 
> >>>>>> Parametric typing in Julia is invariant, so 
> >>>>>> 
> >>>>>> !(Vector{Tuple{ASCIIString,ASCIIString}} <: 
> >>>>>> Vector{Tuple{String,String}}) 
> >>>>>> 
> >>>>>> 
> >>>>>> even though 
> >>>>>> 
> >>>>>> Tuple{ASCIIString,ASCIIString} <: Tuple{String,String}. 
> >>>>>> 
> >>>>>> 
> >>>>>> See: 
> >>>>>> 
> http://docs.julialang.org/en/release-0.3/manual/types/#parametric-composite-types
>  
> >>>>>> 
> >>>>>> On Tue, Aug 11, 2015 at 1:26 PM, Seth <[email protected]> 
> wrote: 
> >>>>>> 
> >>>>>>> Consider 
> >>>>>>> 
> >>>>>>> foo(a::Vector) = 1 
> >>>>>>> bar(a::Vector{Tuple}) = 2 
> >>>>>>> baz(a::Vector{Tuple{AbstractString, AbstractString}}) = 3 
> >>>>>>> 
> >>>>>>> 
> >>>>>>> foo(a::AbstractString) = foo([(a,a)]) 
> >>>>>>> bar(a::AbstractString) = bar([(a,a)]) 
> >>>>>>> baz(a::AbstractString) = baz([(a,a)]) 
> >>>>>>> 
> >>>>>>> Results: 
> >>>>>>> 
> >>>>>>> julia> foo("a") 
> >>>>>>> 1 
> >>>>>>> 
> >>>>>>> julia> bar("a") 
> >>>>>>> ERROR: MethodError: `bar` has no method matching 
> >>>>>>> bar(::Array{Tuple{ASCIIString,ASCIIString},1}) 
> >>>>>>>  in bar at none:1 
> >>>>>>> 
> >>>>>>> julia> baz("a") 
> >>>>>>> ERROR: MethodError: `bar` has no method matching 
> >>>>>>> bar(::Array{Tuple{ASCIIString,ASCIIString},1}) 
> >>>>>>>  in baz at none:1 
> >>>>>>> 
> >>>>>>> I understand why foo() works, but why do bar() or baz() both fail? 
> >>>>>>> 
> >>>>>> 
> >>>>>> 
> >>>> 
> >> 
>
>

Reply via email to