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

Generic structures #892

Closed
9 tasks done
mihaibudiu opened this issue Oct 2, 2020 · 7 comments · Fixed by #898
Closed
9 tasks done

Generic structures #892

mihaibudiu opened this issue Oct 2, 2020 · 7 comments · Fixed by #898

Comments

@mihaibudiu
Copy link
Contributor

mihaibudiu commented Oct 2, 2020

Personnel

Design

  • document: see below

Implementation

Process

Short description

It would be useful to be able to define structures such as:

struct S<T> {
   T field;
   bool valid;
}
@mihaibudiu
Copy link
Contributor Author

Instantiate struct:

S<bit<32>> s;

@mihaibudiu
Copy link
Contributor Author

mihaibudiu commented Oct 5, 2020

An Option type:

Option<T> = None
          | Some<T> value;

@mihaibudiu
Copy link
Contributor Author

mihaibudiu commented Oct 5, 2020

Either<T, S> = Left<T> 
              | Right<S>

@mihaibudiu
Copy link
Contributor Author

The syntax we went with is different:

union Either<T, S> {
    T left;
    S right;
}

@mihaibudiu
Copy link
Contributor Author

mihaibudiu commented Dec 7, 2020

struct G<T> {
   S<T> s;
   tuple<T, T> t;
}

@mihaibudiu
Copy link
Contributor Author

Control-plane names for these generic types?

@mihaibudiu
Copy link
Contributor Author

I am reopening this issues, since a difficulty showed up in the implementation, handled here: p4lang/p4c#2637

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

Successfully merging a pull request may close this issue.

1 participant