[Haskell-beginners] if ands

Joe Fredette jfredett at gmail.com
Thu Nov 5 21:09:13 EST 2009


No, consider the definition of (&&)

-- I hope this is the def from the prelude. If it's not, then it's  
probably isomorphic...
(&&) :: Bool -> Bool -> Bool

True  && x = x
False && _ = False

Since (&&) ignores it's second argument if the first is false, then it  
will "Short circuit" (like most `&` operators in other languages) due  
to lazy evaluation.

/Joe

On Nov 5, 2009, at 9:05 PM, Nathan M. Holden 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?
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://www.haskell.org/mailman/listinfo/beginners



More information about the Beginners mailing list