Expressing relationships between the integer parameters to Arrays

61 views
Skip to first unread message

Dylan Tisdall

unread,
Feb 27, 2015, 10:02:06 AM2/27/15
to julia...@googlegroups.com
Hi,

I'm new to Julia, so forgive me if I've missed the documentation for this somewhere. I'm curious how to express the following type relationship properly in Julia:

function foo{T, n} (
  x::Array{T, n},
  y::Array{T, n+1} )
  ### stuff
end

Basically, I want to specify that foo() takes two Arrays, and the second argument always has one more dimension than the first. Is there a way to express this in the types, or do I need to check it at runtime with something like "ndims(x) == ndims(y) - 1"?


Thanks,
Dylan

Jiahao Chen

unread,
Feb 27, 2015, 10:50:11 PM2/27/15
to julia...@googlegroups.com
Arithmetic on type parameters has been discussed but is not yet implemented. See https://github.com/JuliaLang/julia/issues/8322

Jameson Nash

unread,
Feb 27, 2015, 11:20:43 PM2/27/15
to julia...@googlegroups.com
I would generally strongly recommend doing the runtime check over foisting this onto function dispatch, if for no other reason than your users will get a much better error message that specifies what went wrong with their call, rather than a generic no-method error.

Plus, it will generally be constant folded away at compile-time anyways, such that it won't actually need to incur a runtime cost.
Reply all
Reply to author
Forward
0 new messages