Skip to content

Instantly share code, notes, and snippets.

@Deco
Last active August 29, 2015 14:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Deco/cbb3b7f4453604c3d6ff to your computer and use it in GitHub Desktop.
Save Deco/cbb3b7f4453604c3d6ff to your computer and use it in GitHub Desktop.
type MatF[ElementT, PLEASE_HELP] = object
data: array[SOME_VARIABLE_LENGTH_HERE, ElementT]
template matF*(elementT: typedesc; dimensions: varargs[int]): expr =
let dimensionCount = len(dimensions)
let elementCount = foldl(dimensions, a*b)
???
var a = matF(float64, 4, 4)
var b = matF(float64, 4, 4)
# The type of `a` and `b` should be something like:
# MatF[float64, 2, [4, 4]]
# that is:
# MatF[element type, dimension count, dimensions]
a[1,2] = 44
b[1,2] = 55
var c = a+b
echo c[1,2]
# operators would be able to accept generic types
proc `+`*[A implements MatF, B implements MatF](ma: A, mb: B): ?? =
assert that a and b are the same dimensionality and size
# how on earth would you even implement this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment