title: Arrays with attributes in Julia
body: <p>I am making my first steps in julia, and I would like to reproduce something I achieved with <code>numpy</code>.</p>
  
  <p>I would like to write a new array-like type which is essentially an vector of elements of arbitrary type, and, to keep the example simple, an scalar attribute such as the sampling frequency <code>fs</code>.</p>
  
  <p>I started with something like</p>
  
  <pre><code>type TimeSeries{T} &lt;: DenseVector{T,}
      data::Vector{T}
      fs::Float64
  end
  </code></pre>
  
  <p>Ideally, I would like:</p>
  
  <p>1) all methods that take a <code>Vector{T}</code> as argument to take on <code>TimeSeries{T}</code>.</p>
  
  <p>e.g.:</p>
  
  <pre><code>ts = TimeSeries([1,2,3,1,543,1,24,5], 12.01)
  median(ts)
  </code></pre>
  
  <p>2) that indexing a <code>TimeSeries</code> always returns a <code>TimeSeries</code>:</p>
  
  <pre><code>ts[1:3]
  </code></pre>
  
  <p>3) built-in functions that return a <code>Vector</code> to return a <code>TimeSeries</code>:</p>
  
  <pre><code>ts * 2
  ts  + [1,2,3,1,543,1,24,5]
  </code></pre>
  
  <p>I have started by implementing <code>size</code>, <code>getindex</code> and so on, but I definitely do not see how it could be possible to match points 2 and 3.</p>
  
  <p><code>numpy</code> has a quite comprehensive way to doing this: <a href="http://docs.scipy.org/doc/numpy/user/basics.subclassing.html" rel="nofollow">http://docs.scipy.org/doc/numpy/user/basics.subclassing.html</a>. <code>R</code> also seems to allow linking attributes <code>attr()&lt;-</code> to arrays.</p>
  
  <p>Do you have any idea about the best strategy to implement this sort of "array with attributes".</p>