Re: [julia-users] type checking arrays

2015-08-18 Thread Mauro
This is invariance striking.  There should probably a FAQ entry for this
as it is often discussed:
https://groups.google.com/forum/#!searchin/julia-users/invariance

Docs:
http://docs.julialang.org/en/release-0.3/manual/types/#parametric-composite-types

On Tue, 2015-08-18 at 09:37, Kevin Kunzmann nl.vekm...@gmail.com wrote:
 Hi guys,

 So, I recently revisited Julia and fooled around a bit with Julia Box. 
 Amazing - this looks like the language I never actually dared dreaming of 
 ;) Keep up the greedy work!

 That being said, my question might be dumb, but I am struggling with the 
 type system of Julia. I want to guarantee that the arguments to a function 
 are numerical arrays of dimension 1 - how would I best do that in Julia? 
 The problem is that

 Array{Number, 1}

 exists as a type, but when I get the type system right it should not have 
 any subtypes except union. Especially

 Array{Float64, 1} : Array{Number, 1}

 evaluates to ' false'. I think I get why this is implemented the way it is, 
 however, would it not be most intuitive to have something like

 function f(x::Array{Number, 1})
 x
 end


 What would be the 'Julian' way of doing this?

function f{T:Number}(x::Array{T, 1})
x
end


[julia-users] type checking arrays

2015-08-18 Thread Kevin Kunzmann
Hi guys,

So, I recently revisited Julia and fooled around a bit with Julia Box. 
Amazing - this looks like the language I never actually dared dreaming of 
;) Keep up the greedy work!

That being said, my question might be dumb, but I am struggling with the 
type system of Julia. I want to guarantee that the arguments to a function 
are numerical arrays of dimension 1 - how would I best do that in Julia? 
The problem is that

Array{Number, 1}

exists as a type, but when I get the type system right it should not have 
any subtypes except union. Especially

Array{Float64, 1} : Array{Number, 1}

evaluates to ' false'. I think I get why this is implemented the way it is, 
however, would it not be most intuitive to have something like

function f(x::Array{Number, 1})
x
end


What would be the 'Julian' way of doing this?

Best,

Kevin


Re: [julia-users] type checking arrays

2015-08-18 Thread Kevin Kunzmann
Great, thanks - that makes so much more sense x)

On Tuesday, 18 August 2015 10:10:40 UTC+2, Milan Bouchet-Valat wrote:

 Le mardi 18 août 2015 à 00:37 -0700, Kevin Kunzmann a écrit : 
  Hi guys, 
  
  So, I recently revisited Julia and fooled around a bit with Julia 
  Box. Amazing - this looks like the language I never actually dared 
  dreaming of ;) Keep up the greedy work! 
  
  That being said, my question might be dumb, but I am struggling with 
  the type system of Julia. I want to guarantee that the arguments to a 
  function are numerical arrays of dimension 1 - how would I best do 
  that in Julia? The problem is that 
  
  Array{Number, 1} 
  
  exists as a type, but when I get the type system right it should not 
  have any subtypes except union. Especially 
  
  Array{Float64, 1} : Array{Number, 1} 
  
  evaluates to ' false'. I think I get why this is implemented the way 
  it is, however, would it not be most intuitive to have something like 
  
  function f(x::Array{Number, 1}) 
  x 
  end 
  
  
  What would be the 'Julian' way of doing this? 
 f{T:Number}(x::Array{T, 1}) or 
 f{T:Number}(x::Vecotr{T}) 

 You're hitting a subtle point which has to do with covariance vs. 
 invariance of types. This part of the manual should make it clearer, 
 but feel free to ask for more explanations: 
 http://docs.julialang.org/en/latest/manual/types/?highlight=covariance# 
 parametric-composite-types 
 http://docs.julialang.org/en/latest/manual/types/?highlight=covariance#parametric-composite-types
  


 Regards 



Re: [julia-users] type checking arrays

2015-08-18 Thread Milan Bouchet-Valat
Le mardi 18 août 2015 à 00:37 -0700, Kevin Kunzmann a écrit :
 Hi guys,
 
 So, I recently revisited Julia and fooled around a bit with Julia 
 Box. Amazing - this looks like the language I never actually dared 
 dreaming of ;) Keep up the greedy work!
 
 That being said, my question might be dumb, but I am struggling with 
 the type system of Julia. I want to guarantee that the arguments to a 
 function are numerical arrays of dimension 1 - how would I best do 
 that in Julia? The problem is that
 
 Array{Number, 1}
 
 exists as a type, but when I get the type system right it should not 
 have any subtypes except union. Especially
 
 Array{Float64, 1} : Array{Number, 1}
 
 evaluates to ' false'. I think I get why this is implemented the way 
 it is, however, would it not be most intuitive to have something like
 
 function f(x::Array{Number, 1})
 x
 end
 
 
 What would be the 'Julian' way of doing this?
f{T:Number}(x::Array{T, 1}) or
f{T:Number}(x::Vecotr{T})

You're hitting a subtle point which has to do with covariance vs.
invariance of types. This part of the manual should make it clearer,
but feel free to ask for more explanations:
http://docs.julialang.org/en/latest/manual/types/?highlight=covariance#
parametric-composite-types


Regards