I do not know what you intent, and I have the feeling that you do not know it 
as well.

With these fixes your code compiles, but of course it does not work already, 
you would have to add code, for example for copying the seq elements.
    
    
    type MyArray*[T: int|float] = ref object
      values*: seq[T]
      size*: int
    
    proc `[]`*[T: int|float](ma: MyArray[T], hs: HSlice): seq[T] =
      result = newSeq[T](hs.b - hs.a + 1)
    
    var ma = MyArray[float]()
    
    let sliceOfMA = ma[5..10]
    
    
    
    Run

Some points that makes no sense from your initial example:

  * Fixed size array -- seq is not fixed size!
  * Your [] proc gets a MyArray and returns a plain seq -- is that intended?
  * newMyArray(...) is not a valid constructor



Generally, why not start without generics, and add generics later? I did that 
for my Delaunay triangulation and for my RTree and MinMaxHeap. Starting fully 
generic is more difficult, but when it works, making it generic is not that 
difficult in Nim.

I hope you have an understanding why we use generics at all in Nim, it is 
related to the fact that Nim is a statically typed language. People knowing 
only dynamically languages like Python often wonder why a seq can not contain 
floats and ints at the same time. I assume that you know that even with 
generics a seq contains only ints or only float, but never both. When you 
define a generic proc, you indeed generate multiple procs, one for the int seq, 
and one for the float seq.

Reply via email to