Conversation

If your language has if/then/else, and you're not a coward, then you're forced to invent some amount of dependent types
1
10
A classic example of this sort of cowardice is how if/then/else in C initiates scope blocks. For example, this is valid C code that does nothing and fails to bring x into scope: > if b then int x = 69; else char *x = "Nice"; x *should* have a type dependent on b
1
7
Yep. In functional languages if-then-else builds *terms* so it has to "return" a value, and generally the then-term and else-term are required to have equal/unifiable types
1
1
Oh right; I would rather (in the context of C) think of it as returning an rvalue, rather than x itself (i.e. with the name “x”) continuing to be in scope. This is how Rust does it
1
1
eg let foo = if b { let x = 42; /* … */ } else { let x = “foo”; /* … */ }; x is not in scope after the block, but foo is, and the two branches must return unifiable types in the commented portion
1
1