title: Type constraint mismatch in class with two generic types, overloaded to make the two types equal
body: <p>I have a problem with generic type constraints.</p>
  
  <p>Background: I'm just getting started with WPF and am creating a class to help with validation. The goal is easy usage from XAML as well as type safety in the validation from the back-end.</p>
  
  <p>To that end, I have created a class that wraps another value. It has a property <code>Raw</code> that I bind to in XAML, and a property <code>Valid</code> that gives me a final, valid and converted result. The class is instantiated with both a converter and a list of checks on the converted value. The converter as well as the checks can, of course, fail.</p>
  
  <p>I want to create two overloads: One without the checks (to make a wrapper that only converts) and one without the converter (to make a wrapper that only checks and doesn't convert). I'm having trouble with the latter. Here's the class (INotifyPropertyChanged and IDataErrorInfo removed): </p>
  
  <pre><code>type Validated&lt;'raw, 'converted&gt;
        (init:'raw,
         convert:'raw-&gt;Result&lt;'converted,string&gt;,
         checks:('converted-&gt;Result&lt;unit,string&gt;) list) =
  
    let getValidationError converted validate =
      match validate converted with
      | Ok () -&gt; None
      | Error err -&gt; Some err
  
    new(init:'raw, convert:'raw-&gt;Result&lt;'converted,string&gt;) = 
      Validated(init, convert, [])
  
    // This is the one I'm having trouble with  
    new(init:'raw, checks:('converted-&gt;Result&lt;unit,string&gt;) list) = 
      Validated(init, Ok, checks)
  
    member val Raw = init with get, set
  
    member private this.Converted = convert this.Raw
  
    member this.Errors =
        match this.Converted with
        | Ok x -&gt; checks |&gt; List.choose (getValidationError x)
        | Error x -&gt; [x]
  
    member this.ValidValue = 
      match this.Converted, this.Errors with
      | Ok x, [] -&gt; Some x
      | _ -&gt; None
  </code></pre>
  
  <p>In the second overload, I get the following error: <code>This construct code causes code to be less generic than indicated by type annotations. The type variable 'raw has been constrained to be type 'converted.</code> Which of course makes sense - since it's not converting, the types would have to be the same.</p>
  
  <p>Is it possible to create such an overload for this class, or do I have to use another class with a single type parameter for that?</p>
  
  <p>Note that I can create an instance using e.g. <code>new Validated("", Ok, [])</code> which then is of type <code>Validated&lt;string, string&gt;</code>. It's just the actual constructor overload I'm having trouble with.</p>