liquidsoap icon indicating copy to clipboard operation
liquidsoap copied to clipboard

Add univ type annotation

Open toots opened this issue 8 months ago • 3 comments

I was looking at https://github.com/savonet/liquidsoap/issues/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 avatar Nov 12 '23 23:11 toots

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?...

smimram avatar Nov 15 '23 09:11 smimram

Looks pretty good to me:

Screenshot 2023-11-15 at 1 12 38 PM

toots avatar Nov 15 '23 19:11 toots

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

smimram avatar Nov 16 '23 15:11 smimram