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

Function overloading #6

Closed
cqcallaw opened this issue Jan 2, 2016 · 3 comments
Closed

Function overloading #6

cqcallaw opened this issue Jan 2, 2016 · 3 comments
Milestone

Comments

@cqcallaw
Copy link
Owner

cqcallaw commented Jan 2, 2016

Note: we must be sure the side-by-side declarations f:= (a:int) -> int and f:= (a:int=2) -> int are handled correctly (they have the same signature, but one has a default value)

@cqcallaw
Copy link
Owner Author

After an extended discussion with @laokaplow, the proposed syntax for this feature has changed.

If we are given

f:= (a:int) -> int { ... }
f:= (a:double) -> int { ... }

allowing the second declaration to overload the first declaration implicitly changes the type of f from (int)->int to a product type of (int)->int AND (double)->int (an sum type--that is, "or"--is not used because f contains values for both types, not just one or the other).

This implicit type re-interpretation can be avoided by requiring all function overloads to be specified as part of a single declaration statement, like so:

f:= (a:int) -> int { ... } & (a:double) -> int { ... }

The ampersand indicates AND, shortened to the ampersand by common convention. This ampersand syntax is the new proposed syntax for function overloading.

Sum types are a significant enough feature to warrant their own issue (#40).

@cqcallaw cqcallaw added this to the 0.1 milestone Nov 5, 2016
@cqcallaw
Copy link
Owner Author

cqcallaw commented Nov 25, 2016

@laokaplow observes that there is no semantic reason to require the same return type for all function variants, since the parameter list uniquely identifies each function variant.

@cqcallaw
Copy link
Owner Author

There is some awkwardness in this implementation: both function and multi-variant function classes still exist. This is primarily because of the necessity to differentiate function specifiers and function declarations (the later has parameter names) for single-variant functions, which is not necessary or desired for multi-variant functions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant