Skip to content

Latest commit

 

History

History
28 lines (19 loc) · 1.31 KB

operator_overloading.md

File metadata and controls

28 lines (19 loc) · 1.31 KB
  • Lumi allows operator overloading.
  • Operator overloading is only allowed for types where the relationship has been declared implementations of operators will be checked against such declarations.

ie. (syntax not final)

lumi binop-relation: datetime + timedelta = datetime

This avoids a few issues that exist in python.

In python, given an expression, knowing the types of {z,x} or {z, y} does not give you knowledgeof the unknown of x or y

x + y = z

The reasons for this are a combination of both LHS and RHS being able to implement most binops (some exceptions like __matmul__, don't have a corresponding RHS version __rmatmul__) for the other operand noncooperatively, and that the RHS steals priority from the LHS when the RHS is a subclass of the LHS.

Given the priority placed on inference doing most of the work, asking people who are participating in operator overloading to just list out the participating overloads their types define prevents that lack of knowledge. In the future, this may result in special syntax for implementing this instead, with Lumi generating the correct dunder methods for the generated python code.