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 res = 0
for u32 i in 0..N do
res = res + a[i]
endfor
return res
def main(field[3] a) -> field:
return sum(a)