Seite 1 von 1

Types in If0 Branches

Verfasst: 2. Mär 2019 14:59
von luxic
Hi,

in Exercise 13, Task 1.2's solution the then and else branches of If0 are not allowed to have different Types.
Why do we have this limitation? I'd think that the branches are completely independent from one another and may, therefore, have different types.

Greetings and thanks in advance!

Re: Types in If0 Branches

Verfasst: 2. Mär 2019 17:41
von 0b101101101
What type would the if expression have, if you would allow the different types in the branches?
var x = (if 1>3 then "hello" else 42)

Re: Types in If0 Branches

Verfasst: 3. Mär 2019 21:36
von luxic
Oh, I see, I understand.

Thanks! :)