Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6668201
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T03:00:53+00:00 2026-05-26T03:00:53+00:00

For example, I have an operation fnB :: a -> Bool that makes no

  • 0

For example, I have an operation fnB :: a -> Bool that makes no sense until fnA :: Bool returns False. In C I may compose these two operations in one if block:

if( fnA && fnB(a) ){ doSomething; }

and C will guarantee that fnB will not execute until fnA returns false.

But Haskell is lazy, and, generally, there is no guarantee what operation will execute first, until we don’t use seq, $!, or something else to make our code strict. Generally, this is what we need to be happy. But using && operator, I would expect that fnB will not be evaluated until fnA returns its result. Does Haskell provide such a guarantee with &&? And will Haskell evaluate fnB even when fnA returns False?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T03:00:54+00:00Added an answer on May 26, 2026 at 3:00 am

    The function (&&) is strict in its second argument only if its first argument is True. It is always strict in its first argument. This strictness / laziness is what guarantees the order of evaluation.

    So it behaves exactly like C. The difference is that in Haskell, (&&) is an ordinary function. In C, this would be impossible.

    But Haskell is lazy, and, generally, there are no guarantee what operation will execute first, until we don’t use seq, $!, or something else to make our code strict.

    This is not correct. The truth is deeper.

    Crash course in strictness:

    We know (&&) is strict in its first parameter because:

    ⊥ && x = ⊥
    

    Here, ⊥ is something like undefined or an infinite loop (⊥ is pronounced “bottom”). We also know that (False &&) is non-strict in its second argument:

    False && ⊥ = False
    

    It can’t possibly evaluate its second argument, because its second argument is ⊥ which can’t be evaluated. However, the function (True &&) is strict in its second argument, because:

    True && ⊥ = ⊥
    

    So, we say that (&&) is always strict in its first argument, and strict in its second argument only when the first argument is True.

    Order of evaluation:

    For (&&), its strictness properties are enough to guarantee order of execution. That is not always the case. For example, (+) :: Int -> Int -> Int is always strict in both arguments, so either argument can be evaluated first. However, you can only tell the difference by catching exceptions in the IO monad, or if you use an unsafe function.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Would it make sense to have a constify operation in C/C++ that makes a
I have multiple forms that popup during an intensive operation. For example, when a
How to reverse bitwise AND (&) in C? For example I have an operation
Lets just say you have a simple operation that runs on a background thread.
Assume that you have the following operation: void AddCustomer(Customer) (i.e. a Customer object as
I have a list that is created within an itertools.groupby operation: def yield_unpacked_list(): for
I can't find the is not operator in C#. For example I have the
Greetings everybody. I have seen examples of such operations for so many times that
If I for example have <p> some long text </p> on my HTML page,
Why does: const char example; (uint64*)example have a value of 140734799798420 and *(uint64*)example have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.