zksecurity / noname

Noname: a programming language to write zkapps
https://zksecurity.github.io/noname/
161 stars 35 forks source link

enum and sum types #129

Open mimoo opened 1 month ago

mimoo commented 1 month ago

this is something we are missing currently, and I think we should aim to support this at some point. It'd be good to see a proposal on that. For example with sum types we could have something like this:

use std::bits;

struct MaybeBinary {
  val: Field,
  bin: Option<[Boolean; 32]>
}

fn MaybeBinary.xor(a: &mut Self, b: &mut Self) -> Self {
  if a.bin.is_none() {
     a.bin = Some(bits::decompose(a, 32));
  }
  if  b.bin.is_none() {
     b.bin = Some(bits::decompose(b, 32));
  }
  // ...
}