title: Altering module behavior in OCaml
body: <p>I have a set of ints whose input I'd like to restrict. I would like it to behave something like the following:</p>
  
  <pre><code># RestrictedIntSet.add 15 (RestrictedIntSet.make 0 10)
  Exception: 15 out of acceptable range [0 .. 10]
  </code></pre>
  
  <p>How can I implement this? In Java, it could look something like:</p>
  
  <pre><code>Set&lt;Integer&gt; restrictedSet = new HashSet&lt;Integer&gt;() {
      public boolean add(Integer i) {
          if (i &lt; lowerBound || i &gt; upperBound) {
              throw new IllegalArgumentException("out of bounds");
          }
          return super.add(i);
      }
  </code></pre>
  
  <p>Or, to be less abusing of inheritance:</p>
  
  <pre><code>public class RestrictedSet {
  
     private int lowerBound;
     private int upperBound;
     private Set elems = Sets.newHashSet();
  
     public RestrictedSet(int lowerBound, int upperBound) {
        this.lowerBound = lowerBound;
        this.upperBound = upperBound;
     }
  
     public boolean add(Integer i) {
        if (i &lt; lowerBound || i &gt; upperBound) {
           throw new IllegalArgumentException("out of bounds");
        }
        return elems.add(i);   
     }
  
     /* fill in other forwarded Set calls as needed */
  }
  </code></pre>
  
  <p>What is the equivalent, idiomatic way to do this in OCaml?</p>