Hacker News new | ask | show | jobs
by hannibalhorn 2086 days 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!
1 comments

> squaring an imaginary number results in a real number

However, in general, squaring a complex number results in another complex number.