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

  • SEARCH
  • Home
  • 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 8710149
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T04:33:03+00:00 2026-06-13T04:33:03+00:00

I wrote a QuickCheck property for a function that merges two sorted inputs into

  • 0

I wrote a QuickCheck property for a function that merges two sorted inputs into a sorted output:

prop_merge xs ys =
    if (sorted xs && sorted ys) then (sorted (merge xs ys)) else True

That is, when the inputs are sorted, the output is sorted as well. It can also be written as:

prop_merge xs ys = not(sorted xs && sorted ys) || (sorted (merge xs ys))

But I don’t really like either version. Is there a nicer syntax for “conditional properties” in QuickCheck?

  • 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-06-13T04:33:04+00:00Added an answer on June 13, 2026 at 4:33 am

    You can use the ==> operator to attach a boolean condition to your properties:

    prop_merge xs ys = (sorted xs && sorted ys) ==> sorted (merge xs ys)
    

    This is not only a nicer syntax, but allows QuickCheck to differentiate between test cases where the test was successful and test cases which did not satisfy the precondition. In the latter case, the test is not counted and QuickCheck generates new inputs.

    However, in cases where most inputs don’t satisfy the condition, this will cause your tests to either run more slowly, or, if enough inputs are discarded, QuickCheck will eventually give up. Since a random list is unlikely to be sorted, this is very likely to happen with the example above:

    > quickCheck (prop_merge :: [Int] -> [Int] -> Property)
    *** Gave up! Passed only 15 tests.
    

    (Note that with standard boolean operators instead of using ==>, QuickCheck will boost about all tests being passed, when most of them were useless due to a failed precondition)

    For this reason, it’s generally much better to directly generate only the test cases you need. For simple cases, the Test.QuickCheck.Modifiers module contains several useful newtypes which modify the way inputs are generated. For example, the OrderedList modifier will generate only sorted lists, so we can write your property simply as:

    prop_merge (Ordered xs) (Ordered ys) = sorted (merge xs ys)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Wrote an exercise & solution page, with buttons that start js functions that show
I wrote a function that tries to get a y/n (yes/no) answer from a
Wrote a simple program that calls ls, then passes each line through regexp filtering
I wrote a PHP script that retrieves values from a MySQL Query. I used
I wrote a Flickr search engine that makes a call to either a public
I wrote an application that use MKMapView. This application use a timer to update
I wrote some code: output = File.open(text_file).collect.reverse.join(<BR>) It seems to work okay on 1.8.7
I wrote a AutoHotKey script to remap LWin to LAlt LWin::LAlt LWin & Tab::AltTab
I wrote a php code that display error in red color. But somehow, this
I wrote a webpage where a user can enter a log entry that is

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.