[Haskell-beginners] if ands

Magnus Therning magnus at therning.org
Fri Nov 6 15:43:27 EST 2009

On 06/11/09 09:03, Deniz Dogan wrote:
> 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.

IIRC Pascal isn't "smart" about it.


Magnus Therning                        (OpenPGP: 0xAB4DFBA4)
magnus@therning.org          Jabber: magnus@therning.org
http://therning.org/magnus         identi.ca|twitter: magthe

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 198 bytes
Desc: OpenPGP digital signature
Url : http://www.haskell.org/pipermail/beginners/attachments/20091106/d04f14f2/signature.bin

More information about the Beginners mailing list