Hacker News new | ask | show | jobs
by bad_user 5567 days ago
About your [1] ... dynamic languages can support multimethods (i.e. method overloading on steroids) so I don't get how a dynamic language can't do overloading based on return type.

The difference between a static and a dynamic language would be when this dispatch is made (compile-time versus runtime).

1 comments

Overloading on return type is fundamentally impossible in dynamic languages, since they dispatch on values, and the return value can not be known before the function is called.
Oh come on, all you need to do is to (OPTIONALLY) tag the function with the return type.

And it's still a dynamic type system ;)

Well it's not impossible. You could run them all and then decide which result to use. :)
That doesn't work either, since then you will have more than one result. Which one will you dispatch on?
Presumably, you'll have some rules that determine which is the best match and then error if it's ambiguous - just like the static case