|
|
|
|
|
by adeelk
5127 days ago
|
|
A programming language designer shouldn’t have to make accommodations for users of whatever other languages are popular at the moment. If “return” is the natural name for a keyword, then regardless of its semantics in other languages, that is the best choice in the long term. Technical note: even in languages where every expression has a value, it is possible to have an `if` form that doesn’t require an `else` value: just return nil. See, for example, Clojure: http://clojure.org/special_forms#if |
|
A typical example of a confusing return in haskell is this. Note that this always prints "hi".
Here xyzzy and plugh return different types; since the if statement needs the same type on both if branches, return has to be used to return a dummy value of the same type as plugh (here assumed to be ()). But it only returns it to the outside of the if; haskell's return does not influence control flow.You do get used to this pretty quickly, but there's also a tendency to move away from that style of haskell. I'd write the above more like this, using guards rather than the if, and using void to force both plugh and xyzzy to return the same type.