Re: [julia-users] julia equivalent of python [] (aka list)

2016-05-25 Thread Tom Breloff
And to take that further, it's much better to use AbstractVector (with no
parameters) in method defs as that can accept anything with the right
shape.

On Wednesday, May 25, 2016, Stefan Karpinski  wrote:

> Vector is the type you're looking for – the type which includes Vector{T}
> for any T. Vector{Any} is a vector whose element type is `Any`
> specifically, a much more specific type. We don't yet have a notation for
> Vector{<:T} but it will likely be something like that.
>
> On Wed, May 25, 2016 at 8:08 AM, DNF  > wrote:
>
>>
>>
>> On Wednesday, May 25, 2016 at 11:50:43 AM UTC+2, DNF wrote:
>>>
>>>
>>> This works, however, even though Vector is not a subtype of Vector{Any}:
>>> >> goodbye(v::Vector) = println("bye, bye")
>>> goodbye (generic function with 1 method)
>>> >> goodbye([2,'a'])
>>> bye, bye
>>> >>> goodbye([2,2])
>>> bye, bye
>>>
>>
>> This is a bit backwards. Vector{Any} is a subtype of Vector, of course!
>>
>> Perhaps I was expecting too much. I was envisioning a list containing
>> 'any' sort of elements, and that would include vectors with all types of
>> elements. After checking I see that numpy arrays are not a subclass of
>> list, so Vector{Any} is sort of analogous to python 'list'. It just
>> requires some extra thinking to realize that Vector{'anything'} is not
>> included in that group.
>>
>
>


Re: [julia-users] julia equivalent of python [] (aka list)

2016-05-25 Thread Stefan Karpinski
Vector is the type you're looking for – the type which includes Vector{T}
for any T. Vector{Any} is a vector whose element type is `Any`
specifically, a much more specific type. We don't yet have a notation for
Vector{<:T} but it will likely be something like that.

On Wed, May 25, 2016 at 8:08 AM, DNF  wrote:

>
>
> On Wednesday, May 25, 2016 at 11:50:43 AM UTC+2, DNF wrote:
>>
>>
>> This works, however, even though Vector is not a subtype of Vector{Any}:
>> >> goodbye(v::Vector) = println("bye, bye")
>> goodbye (generic function with 1 method)
>> >> goodbye([2,'a'])
>> bye, bye
>> >>> goodbye([2,2])
>> bye, bye
>>
>
> This is a bit backwards. Vector{Any} is a subtype of Vector, of course!
>
> Perhaps I was expecting too much. I was envisioning a list containing
> 'any' sort of elements, and that would include vectors with all types of
> elements. After checking I see that numpy arrays are not a subclass of
> list, so Vector{Any} is sort of analogous to python 'list'. It just
> requires some extra thinking to realize that Vector{'anything'} is not
> included in that group.
>


Re: [julia-users] julia equivalent of python [] (aka list)

2016-05-25 Thread DNF


On Wednesday, May 25, 2016 at 11:50:43 AM UTC+2, DNF wrote:
>
>
> This works, however, even though Vector is not a subtype of Vector{Any}:
> >> goodbye(v::Vector) = println("bye, bye")
> goodbye (generic function with 1 method) 
> >> goodbye([2,'a'])
> bye, bye 
> >>> goodbye([2,2]) 
> bye, bye
>

This is a bit backwards. Vector{Any} is a subtype of Vector, of course!

Perhaps I was expecting too much. I was envisioning a list containing 'any' 
sort of elements, and that would include vectors with all types of 
elements. After checking I see that numpy arrays are not a subclass of 
list, so Vector{Any} is sort of analogous to python 'list'. It just 
requires some extra thinking to realize that Vector{'anything'} is not 
included in that group. 


Re: [julia-users] julia equivalent of python [] (aka list)

2016-05-25 Thread DNF
I was pointing out that Vector{Any} is not a drop-in replacement for Python 
list, especially for type annotations.
 

> You're hitting type invariance. See 
>
> http://docs.julialang.org/en/latest/manual/types/#parametric-composite-types 
> and look for this term in the mailing list archives. 
>


Re: [julia-users] julia equivalent of python [] (aka list)

2016-05-25 Thread Mauro
On Wed, 2016-05-25 at 11:50, DNF  wrote:
> Is ::Array{Any, 1} the correct annotation?
>>> hello(v::Vector{Any}) = println("Hello")
>>> hello([2,'a'])
> Hello
>>> hello([2,2])
> ERROR: MethodError: no method matching hello(::Array{Int64,1})
> in eval(::Module, ::Any) at /usr/local/Cellar/julia/HEAD/lib/julia/sys.dylib:-
> 1
>
>
> It only works for vectors that are specifically of type Vector{Any}. Vector
> {Int64} is not a subtype of Vector{Any}.

This is co-/contravariance: Vector{Int} (say) is not a subtype of
Vector{Any} even though Int<:Any.

Write
hello{T}(v::Vector{T}) = println("Hello")

but if T<:Any then your goodbye function is fine.  If some tighter
constraints are needed then, e.g.

hello{T<:Integer}(v::Vector{T}) = println("Hello")


> This works, however, even though Vector is not a subtype of Vector{Any}:
>
>>> goodbye(v::Vector) = println("bye, bye")
> goodbye (generic function with 1 method)
>>> goodbye([2,'a'])
> bye, bye
 goodbye([2,2])
> bye, bye
>
> On Tuesday, May 24, 2016 at 7:22:53 PM UTC+2, Tamas Papp wrote:
>
> You are mixing up the constructor and the type syntax. Just use
> Vector{Any} in the type definition.
>
> On Tue, May 24 2016, Andreas Lobinger wrote:
>
> > I tend to agree with you, however...
> >
> > julia> d = Any[]
> > 0-element Array{Any,1}
> >
> > julia> type d1
> >name::AbstractString
> >content::Any[]
> >end
> > ERROR: TypeError: d1: in type definition, expected Type{T}, got Array
> {Any,1}
> >
> > On Tuesday, May 24, 2016 at 7:11:50 PM UTC+2, Stefan Karpinski wrote:
> >
> > Since Julia 0.4 [] is what you're looking for.
> >
> > On Tue, May 24, 2016 at 1:06 PM, Andreas Lobinger 
> wrote:
> >
> > Hello colleagues,
> >
> > it really feels strange to ask this, but what is the julia equivalent of
> python's list?
> >
> > So.
> >
> > 1 can by initialised empty
> > 2 subject of append and extend
> > 3 accepting Any entry
> > 4 foolproof usage in type definition... (my real problem seems to be
> here)
> >
> > Wishing a happy day,
> >
> > Andreas


Re: [julia-users] julia equivalent of python [] (aka list)

2016-05-25 Thread Milan Bouchet-Valat
Le mercredi 25 mai 2016 à 02:50 -0700, DNF a écrit :
> Is ::Array{Any, 1} the correct annotation?
> >> hello(v::Vector{Any}) = println("Hello")
> >> hello([2,'a']) 
> Hello
> >> hello([2,2]) 
> ERROR: MethodError: no method matching hello(::Array{Int64,1}) 
>  in eval(::Module, ::Any) at
> /usr/local/Cellar/julia/HEAD/lib/julia/sys.dylib:-1
> 
> It only works for vectors that are specifically of type Vector{Any}.
> Vector{Int64} is not a subtype of Vector{Any}.
> 
> This works, however, even though Vector is not a subtype of
> Vector{Any}:
> >> goodbye(v::Vector) = println("bye, bye")
> goodbye (generic function with 1 method) 
> >> goodbye([2,'a'])
> bye, bye 
> >>> goodbye([2,2]) 
> bye, bye
You're hitting type invariance. See
http://docs.julialang.org/en/latest/manual/types/#parametric-composite-types
and look for this term in the mailing list archives.


Regards

> > You are mixing up the constructor and the type syntax. Just use 
> > Vector{Any} in the type definition. 
> > 
> > On Tue, May 24 2016, Andreas Lobinger wrote: 
> > 
> > > I tend to agree with you, however... 
> > > 
> > > julia> d = Any[] 
> > > 0-element Array{Any,1} 
> > > 
> > > julia> type d1 
> > >        name::AbstractString 
> > >        content::Any[] 
> > >        end 
> > > ERROR: TypeError: d1: in type definition, expected Type{T}, got
> > Array{Any,1} 
> > > 
> > > On Tuesday, May 24, 2016 at 7:11:50 PM UTC+2, Stefan Karpinski
> > wrote: 
> > > 
> > >  Since Julia 0.4 [] is what you're looking for. 
> > > 
> > >  On Tue, May 24, 2016 at 1:06 PM, Andreas Lobinger  > .com> wrote: 
> > > 
> > >  Hello colleagues, 
> > > 
> > >  it really feels strange to ask this, but what is the julia
> > equivalent of python's list? 
> > > 
> > >  So. 
> > > 
> > >  1 can by initialised empty 
> > >  2 subject of append and extend 
> > >  3 accepting Any entry 
> > >  4 foolproof usage in type definition... (my real problem seems
> > to be here) 
> > > 
> > >  Wishing a happy day, 
> > > 
> > >          Andreas 
> > 


Re: [julia-users] julia equivalent of python [] (aka list)

2016-05-25 Thread DNF
Is ::Array{Any, 1} the correct annotation?
>> hello(v::Vector{Any}) = println("Hello")
>> hello([2,'a']) 
Hello
>> hello([2,2]) 
ERROR: MethodError: no method matching hello(::Array{Int64,1}) 
 in eval(::Module, ::Any) at /usr/local/Cellar/julia/HEAD/lib/julia/sys.
dylib:-1


It only works for vectors that are specifically of type Vector{Any}. 
Vector{Int64} is not a subtype of Vector{Any}.


This works, however, even though Vector is not a subtype of Vector{Any}:
>> goodbye(v::Vector) = println("bye, bye")
goodbye (generic function with 1 method) 
>> goodbye([2,'a'])
bye, bye 
>>> goodbye([2,2]) 
bye, bye


On Tuesday, May 24, 2016 at 7:22:53 PM UTC+2, Tamas Papp wrote:
>
> You are mixing up the constructor and the type syntax. Just use 
> Vector{Any} in the type definition. 
>
> On Tue, May 24 2016, Andreas Lobinger wrote: 
>
> > I tend to agree with you, however... 
> > 
> > julia> d = Any[] 
> > 0-element Array{Any,1} 
> > 
> > julia> type d1 
> >name::AbstractString 
> >content::Any[] 
> >end 
> > ERROR: TypeError: d1: in type definition, expected Type{T}, got 
> Array{Any,1} 
> > 
> > On Tuesday, May 24, 2016 at 7:11:50 PM UTC+2, Stefan Karpinski wrote: 
> > 
> >  Since Julia 0.4 [] is what you're looking for. 
> > 
> >  On Tue, May 24, 2016 at 1:06 PM, Andreas Lobinger  
> wrote: 
> > 
> >  Hello colleagues, 
> > 
> >  it really feels strange to ask this, but what is the julia equivalent 
> of python's list? 
> > 
> >  So. 
> > 
> >  1 can by initialised empty 
> >  2 subject of append and extend 
> >  3 accepting Any entry 
> >  4 foolproof usage in type definition... (my real problem seems to be 
> here) 
> > 
> >  Wishing a happy day, 
> > 
> >  Andreas 
>
>

Re: [julia-users] julia equivalent of python [] (aka list)

2016-05-24 Thread Andreas Lobinger
I tend to agree with you, however...

julia> d = Any[]
0-element Array{Any,1}

julia> type d1
   name::AbstractString
   content::Any[]
   end
ERROR: TypeError: d1: in type definition, expected Type{T}, got Array{Any,1}





On Tuesday, May 24, 2016 at 7:11:50 PM UTC+2, Stefan Karpinski wrote:
>
> Since Julia 0.4 [] is what you're looking for.
>
> On Tue, May 24, 2016 at 1:06 PM, Andreas Lobinger  > wrote:
>
>> Hello colleagues,
>>
>> it really feels strange to ask this, but what is the julia equivalent of 
>> python's list?
>>
>> So.
>>
>>
>>1. can by initialised empty
>>2. subject of append and extend
>>3. accepting Any entry
>>4. foolproof usage in type definition... (my real problem seems to be 
>>here)
>>
>>
>> Wishing a happy day,
>>
>> Andreas
>>
>
>

Re: [julia-users] julia equivalent of python [] (aka list)

2016-05-24 Thread Tamas Papp
You are mixing up the constructor and the type syntax. Just use
Vector{Any} in the type definition.

On Tue, May 24 2016, Andreas Lobinger wrote:

> I tend to agree with you, however...
>
> julia> d = Any[]
> 0-element Array{Any,1}
>
> julia> type d1
>name::AbstractString
>content::Any[]
>end
> ERROR: TypeError: d1: in type definition, expected Type{T}, got Array{Any,1}
>
> On Tuesday, May 24, 2016 at 7:11:50 PM UTC+2, Stefan Karpinski wrote:
>
>  Since Julia 0.4 [] is what you're looking for.
>
>  On Tue, May 24, 2016 at 1:06 PM, Andreas Lobinger  wrote:
>
>  Hello colleagues,
>
>  it really feels strange to ask this, but what is the julia equivalent of 
> python's list?
>
>  So.
>
>  1 can by initialised empty
>  2 subject of append and extend
>  3 accepting Any entry
>  4 foolproof usage in type definition... (my real problem seems to be here)
>
>  Wishing a happy day,
>
>  Andreas



Re: [julia-users] julia equivalent of python [] (aka list)

2016-05-24 Thread Isaiah Norton
`Any[]` constructs a list instance. The proper type signature is
`::Array{Any,1}` (or if you don't absolutely need it, you can leave the
member signature out of the type declaration)

On Tue, May 24, 2016 at 1:16 PM, Andreas Lobinger 
wrote:

> I tend to agree with you, however...
>
> julia> d = Any[]
> 0-element Array{Any,1}
>
> julia> type d1
>name::AbstractString
>content::Any[]
>end
> ERROR: TypeError: d1: in type definition, expected Type{T}, got Array{Any,
> 1}
>
>
>
>
>
> On Tuesday, May 24, 2016 at 7:11:50 PM UTC+2, Stefan Karpinski wrote:
>>
>> Since Julia 0.4 [] is what you're looking for.
>>
>> On Tue, May 24, 2016 at 1:06 PM, Andreas Lobinger 
>> wrote:
>>
>>> Hello colleagues,
>>>
>>> it really feels strange to ask this, but what is the julia equivalent of
>>> python's list?
>>>
>>> So.
>>>
>>>
>>>1. can by initialised empty
>>>2. subject of append and extend
>>>3. accepting Any entry
>>>4. foolproof usage in type definition... (my real problem seems to
>>>be here)
>>>
>>>
>>> Wishing a happy day,
>>>
>>> Andreas
>>>
>>
>>


Re: [julia-users] julia equivalent of python [] (aka list)

2016-05-24 Thread Stefan Karpinski
That is an instance not the type itself. The type is Vector{Any}.

On Tue, May 24, 2016 at 1:16 PM, Andreas Lobinger 
wrote:

> I tend to agree with you, however...
>
> julia> d = Any[]
> 0-element Array{Any,1}
>
> julia> type d1
>name::AbstractString
>content::Any[]
>end
> ERROR: TypeError: d1: in type definition, expected Type{T}, got Array{Any,
> 1}
>
>
>
>
>
> On Tuesday, May 24, 2016 at 7:11:50 PM UTC+2, Stefan Karpinski wrote:
>>
>> Since Julia 0.4 [] is what you're looking for.
>>
>> On Tue, May 24, 2016 at 1:06 PM, Andreas Lobinger 
>> wrote:
>>
>>> Hello colleagues,
>>>
>>> it really feels strange to ask this, but what is the julia equivalent of
>>> python's list?
>>>
>>> So.
>>>
>>>
>>>1. can by initialised empty
>>>2. subject of append and extend
>>>3. accepting Any entry
>>>4. foolproof usage in type definition... (my real problem seems to
>>>be here)
>>>
>>>
>>> Wishing a happy day,
>>>
>>> Andreas
>>>
>>
>>


Re: [julia-users] julia equivalent of python [] (aka list)

2016-05-24 Thread Stefan Karpinski
Since Julia 0.4 [] is what you're looking for.

On Tue, May 24, 2016 at 1:06 PM, Andreas Lobinger 
wrote:

> Hello colleagues,
>
> it really feels strange to ask this, but what is the julia equivalent of
> python's list?
>
> So.
>
>
>1. can by initialised empty
>2. subject of append and extend
>3. accepting Any entry
>4. foolproof usage in type definition... (my real problem seems to be
>here)
>
>
> Wishing a happy day,
>
> Andreas
>


[julia-users] julia equivalent of python [] (aka list)

2016-05-24 Thread Andreas Lobinger
Hello colleagues,

it really feels strange to ask this, but what is the julia equivalent of 
python's list?

So.


   1. can by initialised empty
   2. subject of append and extend
   3. accepting Any entry
   4. foolproof usage in type definition... (my real problem seems to be 
   here)


Wishing a happy day,

Andreas