2 ms·
I was just thinking that squaring an imaginary number results in a real number - that's a pretty crazy thing for a type system to handle, no? I guess that means
by hannibalhorn 6y ago
I was just thinking that squaring an imaginary number results in a real number - that's a pretty crazy thing for a type system to handle, no? I guess that means the correct annotations would be more along the lines of:
def square(number: numbers.Complex) -> numbers.Real: ...
T = typing.TypeVar('T', numbers.Real)
def square(number: T) -> T:
return number ** 2
What a rabbit hole!
- pansa2 6y ago> squaring an imaginary number results in a real number However, in general, squaring a complex number results in another complex number.