Generics
ZoKrates supports code that is generic over constants of the u32
type. No specific keyword is used: the compiler determines if the generic parameters are indeed constant at compile time. Here's an example of generic code in ZoKrates:
def sum<N>(field[N] a) -> field {
field mut res = 0;
for u32 i in 0..N {
res = res + a[i];
}
return res;
}
def main(field[3] a) -> field {
return sum(a);
}