
Hi Brent, Re: '"if" expressions, not statements' is an elegant clarification, one definitely for the haskellwiki, if not there already. Just for completeness' sake, bottom is a value for any expression. Wouldn't making the else clause optional by defaulting to "undefined" worthy of consideration for Evil Haskell? -- Kim-Ee Brent Yorgey-2 wrote:
On Wed, Oct 21, 2009 at 07:49:14PM -0500, Tim Wawrzynczak wrote:
Yes, an if statement must have both 'then' and 'else' branches. As an example, what if you had
let a = if b == 2 then True else False
and you were missing an else branch? What would 'a' get assigned to?
The if statement "returns" a value so must have both branches.
By the way, it helps to be precise with language here: "statement" usually indicates an instruction which causes some effect to happen. "Expression" indicates something which evaluates to a value. Haskell doesn't have "if statements" but it does have "if expressions". It makes sense for an if *statement* (in imperative languages like C) to have an optional else clause, since "do nothing" is a perfectly valid *statement*. But it doesn't make sense for an if *expression* to have a missing else, since it must evaluate to something and (in general) there is no "null value" that could be used. Of course, as others have noted, in a monadic context there IS a special "null value", namely return (), which can be used to indicate "do nothing".
-Brent _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
-- View this message in context: http://www.nabble.com/Is-there-a-null-statement-that-does-nothing--tp2600244... Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com.