-
-
Notifications
You must be signed in to change notification settings - Fork 11
Operator overloading
Sven Nilsen edited this page Oct 18, 2015
·
1 revision
Programming languages can have different types of numbers. Instead of just one function to add all numbers, there can be many functions for adding different types of numbers.
For example: Real numbers, integers, complex numbers, matrices etc.
An operator is a symbol that can be reused for many types. We call this "overloading".
A + B
can be thought of as a function of the types and returning another function which executes the addition:
+(Ta, Tb)(A: Ta, B: Tb) = A + B
In general, for binary functions we have:
B(Ta, Tb)(A: Ta, B: Tb) = A `B` B
For unary functions:
B(Ta)(A: Ta) = `B` A