tvectorspace.nim 291 B

12345678910111213141516
  1. type VectorSpace[K] = concept x, y
  2. x + y is type(x)
  3. zero(type(x)) is type(x)
  4. -x is type(x)
  5. x - y is type(x)
  6. var k: K
  7. k * x is type(x)
  8. proc zero(T: typedesc): T = 0
  9. static:
  10. assert float is VectorSpace[float]
  11. # assert float is VectorSpace[int]
  12. # assert int is VectorSpace