Can somebody please explain (with example) the difference between context-independent and context-dependent overloading?
Can somebody please explain (with example) the difference between context-independent and context-dependent overloading?
Share
I have never heard about those. And there’s only about five hits on Google, one of which is this very question, which seems to suggest to me that these are made-up terms. And as with any made-up term, if you want to know what it means, you have to ask the person who made it up.
From what little I could gather, it seems to be related to return-type based overloading.
Basically, if you have four overloaded functions like these:
And you call them like this:
Then, with context-dependent overloading (i.e. overloading based on the return type as well as the parameter types), the following implementations will be selected:
Whereas with context-independent overloading (i.e. ignoring the return type), the following implementations will be selected:
In both the
ERRORcases, there is an ambiguity betweenfoo :: string → int,foo :: string → stringandfoo :: string → (), since they only differ in their return type but have the same paremeter type.