Types in If0 Branches

Moderator: Konzepte der Programmiersprachen

luxic
Erstie
Erstie
Beiträge: 21
Registriert: 24. Jan 2017 16:09

Types in If0 Branches

Beitrag von luxic » 2. Mär 2019 14:59

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!

0b101101101
Endlosschleifenbastler
Endlosschleifenbastler
Beiträge: 179
Registriert: 15. Apr 2015 18:24

Re: Types in If0 Branches

Beitrag von 0b101101101 » 2. Mär 2019 17:41

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)

luxic
Erstie
Erstie
Beiträge: 21
Registriert: 24. Jan 2017 16:09

Re: Types in If0 Branches

Beitrag von luxic » 3. Mär 2019 21:36

Oh, I see, I understand.

Thanks! :)

Antworten

Zurück zu „Konzepte der Programmiersprachen“