Overload in different programming languages

Can someone explain (with examples) the difference between context-independent and context-sensitive overloading?

+3
source share
2 answers

I have never heard of this. And only about five hits on Google, one of which is the very question, which seems to suggest to me that these are made up conditions. And, as with any drafted term, if you want to know what this means, you should ask the person who created it.

From what I could collect, it seems to be related to overload based on the return type.

Basically, if you have four overloaded functions like these:

foo :: string β†’ int
foo :: string β†’ string
foo :: string β†’ ()
foo :: int β†’ int

And you call them like this:

1 + foo 1
1 + foo "one"
foo "one"

(, , ) :

1 + foo 1     # foo :: int β†’ int
1 + foo "one" # foo :: string β†’ int (because `+` takes an `int`)
foo "one"     # foo :: string β†’ ()  (because there is no return value)

- (.. ) :

1 + foo 1     # foo :: int β†’ int
1 + foo "one" # ERROR
foo "one"     # ERROR

ERROR foo :: string β†’ int, foo :: string β†’ string foo :: string β†’ (), , .

+6

:

/.

  • - -
  • ,
0
source

Source: https://habr.com/ru/post/1784369/


All Articles