-
Notifications
You must be signed in to change notification settings - Fork 35
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
Intersection types in the type language #97
Comments
Yeah! So, what's the way forward? Ideally, we convince the OTP team to include the intersection type in the official type language. My colleage Karol says that he has reported this years back but it has not been prioritized. Until then, we can add it in our type, which we could export in the main interface module, i.e. Then, how should it be represented? I suggest For the syntax (pretty-printing, documentation, etc.), I suggest the semicolon -type t() :: fun((boolean()) -> its_a_bool;
(integer()) -> its_an_int).
-type t() :: fun((boolean()) -> its_a_bool);
fun((integer()) -> its_an_int). If we want to allow -spec foo(boolean() | atom()) -> fun((boolean() -> its_a_bool) ;
fun((atom()) -> its_an_atom) ;
(integer()) -> its_an_int. |
I think intersection with for exampe
We could infer the type of (I think that intersection is most useful during internal type checking and apart from funs we don't necessarily have to allow it for arbitrary types as user definitions (ie no need to include in OTP). However pretty-printing intersection of any two types can be useful if Gradualizer type calculation arrives to such a type) |
I don't have broad knowledge of history and syntax in other languages. Could you explain me why (I understand that in specs If it is the opposite in some sense of union it could be Another question: would it be allowed in fun types for the domains to not be disjoint? (eg. |
A function can have multiple specs, which the documentation calls overloading and whose semantics is intersection types. For instance,
means that
foo
has both the typeboolean() -> its_a_bool
and the typeinteger() -> its_an_int
.We currently handle this for function definitions and explicit calls using the
fun_ty_intersection
return value fromexpect_fun_type
, but not forfun F/A
andfun M:F/A
expressions. To do this we'd need to be able to represent intersection types in the type language.The text was updated successfully, but these errors were encountered: