Skip to content

Instantly share code, notes, and snippets.

Last active August 29, 2015 14:15
What would you like to do?
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