Skip to content

Commit

Permalink
Rephrase an example due to C# having gotten better in version 11
Browse files Browse the repository at this point in the history
Fixes #114
  • Loading branch information
david-christiansen committed Oct 3, 2023
1 parent c0c9653 commit af634d3
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions functional-programming-lean/src/type-classes.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ In C++, Java, C# and Kotlin, multiple implementations of a method are allowed, w
The compiler uses the number of arguments and their types to determine which overload was intended.

Function and operator overloading has a key limitation: polymorphic functions can't restrict their type arguments to types for which a given overload exists.
That is, there is no way to write a function that works for any type that has addition defined.
Instead, this function must itself be overloaded for each type that has addition, resulting in many boilerplate definitions instead of a single polymorphic definition.
For example, an overloaded method might be defined for strings, byte arrays, and file pointers, but there's no way to write a second method that works for any of these.
Instead, this second method must itself be overloaded for each type that has an overload of the original method, resulting in many boilerplate definitions instead of a single polymorphic definition.
Another consequence of this restriction is that some operators (such as equality in Java) end up being defined for _every_ combination of arguments, even when it is not necessarily sensible to do so.
If programmers are not very careful, this can lead to programs that crash at runtime or silently compute an incorrect result.

Expand Down

0 comments on commit af634d3

Please sign in to comment.