Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add structProvable #276

Open
wants to merge 2 commits into
base: v1
Choose a base branch
from
Open

Add structProvable #276

wants to merge 2 commits into from

Conversation

mrmr1993
Copy link
Member

This PR introduces structProvable, an easy way to build a GenericProvable for an object with fields only.

Compiling example:

type MyType<X, Y, Z> = {
    x: X,
    y: Y,
    z: Z,
}

type MyVarType<X, Y, Z> = {
    x: X,
    y: Y,
    z: Z,
}

function myTyp<X, XValue, Y, YValue, Z, ZValue, Field>(
    xtyp: GenericProvable<X, XValue, Field>,
    ytyp: GenericProvable<Y, YValue, Field>,
    ztyp: GenericProvable<Z, ZValue, Field>) {
    structProvable<MyVarType<X, Y, Z>, MyType<XValue, YValue, ZValue>, Field>({x: xtyp, y: ytyp, z: ztyp});
};

type MyRecord = {
    x: [],
    y: [],
    z: [],
}

type MyVarRecord = {
    x: [],
    y: [],
    z: [],
}

function EmptyListType(): GenericProvable<[], [], []> { throw new Error("TODO"); }

let myRecordTyp : GenericProvable<MyRecord, MyVarRecord, []> = structProvable({x: EmptyListType(), y: EmptyListType(), z: EmptyListType()});

Idealised example assuming supporting GenericProvables for the fields:

type MyVarStructure = {
    b: boolean,
    i: Int32,
}
type MyValueStructure = {
    b: Boolean,
    i: Int32,
}

let myStructureTyp : GenericProvable<MyVarStructure, MyValueStructure, Field> =
  structProvable({b: booleanTyp, i: int32Typ});

Copy link
Collaborator

@mitschabaude mitschabaude left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this already exists as provable() (on which Struct is based) in ./provable-generic.ts

provable() is much more general though, handles arrays and singleton types as well, as well as nested structs / arrays

}
return fields;
},
toAuxiliary: (x? /* Why is this nullable?! */) => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's supposed to be called without argument, and return a default value, when we're in compilation mode

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants