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 6861105
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T02:29:35+00:00 2026-05-27T02:29:35+00:00

In F#, I have a record with a few fields: type myRecord = {

  • 0

In F#, I have a record with a few fields:

    type myRecord = { a:float; b:float; c:float }

I am using FsCheck to test some properties which use this record.
For (a contrived) example,

    let verify_this_property (r:myRecord) = myFunction(r) = (r.a * r.b) / r.c

Due to the internal implementation restrictions of myFunction, I would like to have FsCheck create test cases in which each of the fields a,b,c are restricted to non-negative floats.

I suspect this requires creating a generator for myRecord, but I have not been able to find any examples of how to do this.

Can anyone supply guidance?

  • 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-27T02:29:36+00:00Added an answer on May 27, 2026 at 2:29 am

    Try this:

    type Generators = 
        static member arbMyRecord =
            fun (a,b,c) -> { myRecord.a = a; b = b; c = c }
            <!> (Arb.generate<float> |> Gen.suchThat ((<) 0.) |> Gen.three)
            |> Arb.fromGen
    
    Arb.register<Generators>() |> ignore
    Check.Quick verify_this_property
    

    The <!> is an infix map, useful for applicative style. This is an equivalent generator:

    type Generators = 
        static member arbMyRecord =
            Arb.generate<float> 
            |> Gen.suchThat ((<) 0.) 
            |> Gen.three
            |> Gen.map (fun (a,b,c) -> { myRecord.a = a; b = b; c = c })
            |> Arb.fromGen
    

    If you don’t want to globally register your generator, you can use forAll:

    Check.Quick (forAll Generators.arbMyRecord verify_this_property)
    

    Shrinking left as an exercise 😉

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

Sidebar

Related Questions

I have a master record which I'd like to use with. Here's a very
I have done a few projects lately using a Database Object super class which
I have a record store of items which have (name, quantity, owner, status) Now
I have a record store which holds a list of shopping items i am
Let's say I have this: -record(my_record, {foo, bar, baz}). Keyvalpairs = [{foo, val1}, {bar,
I have an entity in my EDMX that I've extended with a few fields
I have a Silverlight 4 app which pulls entities down from a database using
I have few thousands of records with few 100 fields in a MySQL Table.
I have a MVCgrid with few fields with and expander to view all the
Right now I have classes like: abstract class Record { // Required fields val

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.