liquidsoap
liquidsoap copied to clipboard
Add univ type annotation
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 touniv(a)
. I think usinguniv
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
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?...
Looks pretty good to me:
I don't find this particularly readable... Given that we have many universal variables, can we think of some shorter syntax?