ZoKrates
ZoKrates copied to clipboard
Pass functions as parameters to other functions
Abstract
A feature that could be of great benefit to us is the ability to pass functions as parameters. This would allow us to neatly do a Merkle tree implementations by passing down a hash function.
Motivation
As we use a type-first syntax eg. field f
, we cannot leverage the Rust way of doing this f: fn(i32) -> i32
.
A possible workaround that fits the current syntax would be to define a custom type that represents a function signature:
type sumf = (field, field) -> field
def sum(field a, field b) -> field:
return a + b
def foo(field a, field b, sumf s) -> field:
return s(a, b)
def main() -> field:
return foo(2, 2, sum)
This issue is still open for discussion and is subject to change.
Specification
TBA
Backwards Compatibility
No incompatibilities for now.