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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:09:07+00:00 2026-06-16T00:09:07+00:00

Suppose I wanted to create a Record type that represents acceptable min/max bounds: type

  • 0

Suppose I wanted to create a Record type that represents acceptable min/max bounds:

type Bounds = { Min: float; Max: float }

Is there a way to enforce that Min < Max? It is easy to write a validateBounds function, I was just wondering if there was a better way to do this.

Edit: I realized that for this specific example I could probably get away with exposing two properties and re-order the arguments, so let’s say we were trying to do

type Person = { Name: string }

and Name needs to have at least one character.

  • 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-16T00:09:08+00:00Added an answer on June 16, 2026 at 12:09 am

    Here’s another solution based on protection levels:

    module MyModule =
        type Bounds = private { _min: float; _max: float } with
            // define accessors, a bit overhead
            member public this.Min = this._min
            member public this.Max = this._max
            static member public Make(min, max) =
                if min > max then raise (ArgumentException("bad values"))
                {_min=min; _max=max}
    
        // The following line compiles fine,
        // e.g. within your module you can do "unsafe" initialization
        let myBadBounds = {_min=10.0; _max=5.0}
    
    open MyModule
    let b1 = Bounds.Make(10.0, 20.0) // compiles fine
    let b1Min = b1.Min
    let b2 = Bounds.Make(10.0, 5.0) // throws an exception
    // The following line does not compile: the union cases of the type 'Bounds'
    // are not accessible from this code location
    let b3 = {_min=10.0; _max=20.0}
    // The following line takes the "bad" value from the module
    let b4 = MyModule.myBadBounds
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose I wanted to create a WCF WebHTTP service (ServiceREST) that had a reference
Suppose I wanted to create a boost.regex expression that would match strings such as
Suppose I have a process that is updating a record and encounters a record
Suppose I wanted to create an open source Windows Forms project written in .NET.
Let's just say for argument's sake that you wanted to create a PowerShell Cmdlet
Suppose I only had the regular J2SE http libraries but wanted to write a
I wanted to show a vertical drop-down menu on click on a div. Suppose
Suppose I have a pure virtual method in the base interface that returns to
Suppose I have a static method of my class that returns an object of
Suppose I have a class Baz that inherits from classes Foo and Bar ,

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.