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

Type-level _as_int functions for enumerations? #490

Open
martinberger opened this issue Apr 6, 2024 · 5 comments
Open

Type-level _as_int functions for enumerations? #490

martinberger opened this issue Apr 6, 2024 · 5 comments

Comments

@martinberger
Copy link

Enums come with a mapping to other data types, e.g.

enum E with as_int -> int = {
   A => 1,
   B => 4,
   C => 7
}

The mapping between the symbolic name and the corresponding int is available at compile time, so I should be able to do something like this

type T ('n) = { 'n, <constraints>. int('n) }
type TA = T(E_as_int(A))
type TB = T(E_as_int(B))
...

Is this currently possible? There does not seem to be a type-level E_as_int.

@Alasdair
Copy link
Collaborator

Alasdair commented Apr 6, 2024

It's not currently possible. Would need to think about the syntax in types a bit.

@martinberger
Copy link
Author

martinberger commented Apr 6, 2024

It's probably only marginally useful and might not be worth compilcating the language. I have a use case in the implementation of Zc* where that would add more type-safety (or more specifically, let me get away without internal_error(...) in pattern matching).

@martinberger
Copy link
Author

It's not currently possible. Would need to think about the syntax in types a bit.

PS, just to double-check: this is not even possible with the autogenerated map to numbers if the user simply defines enum {A, B, C}?

@Alasdair
Copy link
Collaborator

Alasdair commented Apr 7, 2024

No, we don't lift enumerations to the type level at all.

@Alasdair
Copy link
Collaborator

Alasdair commented Apr 7, 2024

There's no theoretical reason why we couldn't. It might make Coq generation more complicated with more things at the type level, but enumerations are essentially equivalent to a limited set of numbers.

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

No branches or pull requests

2 participants