[Haskell-beginners] if ands
Deniz Dogan
deniz.a.m.dogan at gmail.com
Fri Nov 6 04:03:16 EST 2009
2009/11/6 Keith Sheppard <keithshep at gmail.com>:
> Also, an nice way to check how evaluation works in ghci is to do something like:
>
>> if False && error "error here" then "it's true" else "it's false"
>
> This expression will evaluate as "it's false" without any "error here"
> error message appearing
>
> On Thu, Nov 5, 2009 at 9:05 PM, Nathan M. Holden
> <nathanmholden at gmail.com> wrote:
>> If you have an if statement like
>>
>> if (a&&b) then fun else fun'
>>
>> and a is false, does GHC actually bother to check b?
>
Note that Haskell is far from the only programming language that is
smart about this. I actually can't think of a single programming
language implementation that I know of which isn't this smart...
For what it's worth, Haskell (and others) is smart about ORs as well.
In (x || y), y will only be evaluated if x is False.
--
Deniz Dogan
More information about the Beginners
mailing list