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 univ type annotation #3524

Closed
wants to merge 4 commits into from
Closed

Add univ type annotation #3524

wants to merge 4 commits into from

Conversation

toots
Copy link
Member

@toots toots commented Nov 12, 2023

I was looking at #3303 and started wondering about type annotation for universal variables.

This PR changes the following thing:

  • Switch type annotation for universal variables from 'a a-la OCaml to univ(a). I think using univ is much more user-friendly.
  • Add support for universal variables type annotation. Once we switch to univ, it becomes fully parsable! I'm not sure if this has a huge impact but it's nice to have.
  • Cleanup some old code.

Examples:

# x = (1:univ?);;
x : int? = 1
# x + 1;;
At line 2, char 0:

Error 5: this value has type
  int? (inferred at line 1, char 4-13)
but it should be a subtype of
  something that is a number type
  
# x = (1:univ);;
x : int = 1
# x + 1;;
- : int = 2

# def f((x:univ(a)), (y:univ(a)), (z:univ(b))) =
  123
end;;
f : (univ(a), univ(a), univ(b)) -> int = fun (_,_,_) -> 123

# f(1,"aabb",3.14);;
At line 4, char 4-10:

Error 5: this value has type
  string
but it should be a subtype of
  int (inferred at line 4, char 2)

# f("aabb", "ccdd", 123);;
- : int = 123

@toots toots requested a review from smimram November 12, 2023 23:07
@toots toots force-pushed the univ branch 2 times, most recently from 36e3f50 to c4a1f26 Compare November 12, 2023 23:09
@smimram
Copy link
Member

smimram commented Nov 15, 2023

It looks nice, but I am afraid about readability: can you show examples of types functions with many variables (e.g. ffmpeg.filter.audio_video.output), is it still readable?...

@toots
Copy link
Member Author

toots commented Nov 15, 2023

Looks pretty good to me:

Screenshot 2023-11-15 at 1 12 38 PM

@smimram
Copy link
Member

smimram commented Nov 16, 2023

I don't find this particularly readable... Given that we have many universal variables, can we think of some shorter syntax?

@toots toots closed this Jul 15, 2024
@toots
Copy link
Member Author

toots commented Jul 15, 2024

We can revisit later when/if we want to add a more generic type declaration layer.

@toots toots deleted the univ branch July 15, 2024 20:43
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