[Swift-devel] Standard library

Mihael Hategan hategan at mcs.anl.gov
Sat Jan 10 23:40:30 CST 2015


On Sat, 2015-01-10 at 22:57 -0600, Tim Armstrong wrote:
> > Am I missing something?
> >
> I think the problem I was thinking of is the combination of function
> overloading and keyword arguments - then you have a number of possible
> function signatures that grows exponentially with the number of optional
> arguments.  It's not so bad if it's purely positional arguments since then
> you can just treat a function with n optional arguments as n + 1 overloads
> of the function.

I'm not sure. You should be able to statically determine which keyword
arguments are passed in a given call, fill the missing ones with nulls
or default values, sort, and generate a call to a single purely
positional underlying implementation.

> 
> It might take a bit of implementation work to get to work with the other
> function type checking logic in Swift/T, but it seems tractable.  It's
> already a bit complicated trying to work out the input types of the
> function arguments when there's the possibility of type variables, option
> types, etc.

Shouldn't polymorphism come before fancy type stuff? :)

> 
> There are some weird corner cases.  For example, which implementation of
> avg would this call?
> avg([]);

Unless there is some mechanism that can ensure that it doesn't matter,
or a mechanism allowing you to overload based on specific values (like
pattern matching), then you probably have to have a way to say exactly
which function should be called. Java requires you to do an explicit
cast of arguments that would otherwise result in ambiguity.

Mihael




More information about the Swift-devel mailing list