title: F# 4.5.0.0: Compilation errors: FS1198, FS0661 and FS0001: I'm adapting a interface from C# to F#
body: <p>My goal is to port FSharp.Core version 4.5.0.0 to .NET 4.0. To achieve my goal I am rewriting parts of Theraot.Core in F#, since FSharp.Core does not "accept" third party libraries: <a href="https://github.com/theraot/Theraot/issues/121" rel="nofollow noreferrer">https://github.com/theraot/Theraot/issues/121</a>.</p>
  
  <p>I'm adapting a interface from C# to F#.</p>
  
  <p>Interface in C#:
  <a href="https://github.com/theraot/Theraot/blob/master/Framework.Core/System/Collections/Generic/IReadOnlyDictionary.cs" rel="nofollow noreferrer">https://github.com/theraot/Theraot/blob/master/Framework.Core/System/Collections/Generic/IReadOnlyDictionary.cs</a></p>
  
  <p>Type in F#:</p>
  
  <pre><code>namespace System.Collections.Generic
  
  open Microsoft.FSharp.Core
  
  type IReadOnlyCollection&lt;'T&gt; =
      inherit IEnumerable&lt;'T&gt;
  
      abstract Count : int with get
  
  type IReadOnlyDictionary&lt;'TKey, 'TValue&gt; =
      inherit IReadOnlyCollection&lt;KeyValuePair&lt;'TKey, 'TValue&gt;&gt;
  
      abstract Keys : IEnumerable&lt;'TKey&gt; with get
      abstract Values : IEnumerable&lt;'TValue&gt; with get
      abstract Item : key : 'TKey -&gt; 'TValue with get
      abstract ContainsKey : key : 'TKey -&gt; bool
      abstract TryGetValue : key : 'TKey * [&lt;System.Runtime.InteropServices.Out&gt;] value : byref&lt;'Value&gt; -&gt; bool
  </code></pre>
  
  <p>Where compilation errors occur:
  <a href="https://github.com/fsharp/fsharp/blob/master/src/fsharp/FSharp.Core/map.fs#L626" rel="nofollow noreferrer">https://github.com/fsharp/fsharp/blob/master/src/fsharp/FSharp.Core/map.fs#L626</a>
  <a href="https://github.com/fsharp/fsharp/blob/master/src/fsharp/FSharp.Core/fslib-extra-pervasives.fs#L88" rel="nofollow noreferrer">https://github.com/fsharp/fsharp/blob/master/src/fsharp/FSharp.Core/fslib-extra-pervasives.fs#L88</a></p>
  
  <p>When in C# to F# works perfectly, but compilation errors from F# to F# occur:</p>
  
  <p>map.fs:</p>
  
  <p>FS1198  The generic member 'TryGetValue' has been used at a non-uniform instantiation prior to this program point. Consider reordering the members so this member occurs first. Alternatively, specify the full type of the member explicitly, including argument types, return type and any additional generic parameters and constraints.</p>
  
  <p>FS0661  One or more of the explicit class or function type variables for this binding could not be generalized, because they were constrained to other types.</p>
  
  <p>fslib-extra-pervasives.fs:</p>
  
  <p>FS0001  This expression was expected to have type
      ''a'<br>
  but here has type
      ''T'    </p>
  
  <p>I also tried, without success:</p>
  
  <pre><code>abstract TryGetValue : key : 'TKey * [&lt;System.Runtime.InteropServices.Out&gt;] value : 'Value -&gt; bool
  </code></pre>
  
  <p>Edit:
  I'm taking my first steps in F#. The only information I found was that the immutability of F# is very cool, but sometimes it is not possible to write F# as like C#.</p>
  
  <p>The first two compiler errors I do not know where it came from, but the third is possible to simplify:</p>
  
  <pre><code>namespace TestBugApplication1
  
  open System.Collections.Generic
  
  type DictImpl&lt;'SafeKey,'Key,'T&gt;(t : Dictionary&lt;'SafeKey,'T&gt;, makeSafeKey : 'Key-&gt;'SafeKey) =
      interface IReadOnlyDictionary&lt;'Key, 'T&gt; with
          member this.ContainsKey(key) = raise (System.NotImplementedException())
          member this.Count = raise (System.NotImplementedException())
          member this.GetEnumerator() = raise (System.NotImplementedException())
          member this.GetEnumerator() = raise (System.NotImplementedException())
          member this.Item
              with get (key) = raise (System.NotImplementedException())
          member this.Keys = raise (System.NotImplementedException())
          member this.TryGetValue(key, r) =
              match t.TryGetValue (makeSafeKey key) with
                              | false, _ -&gt; false
                              | true, value -&gt;
                                  r &lt;- value //&lt;- Compiler error
                                  true
          member this.Values = raise (System.NotImplementedException())
  </code></pre>
  
  <p>I can also send a download link with the solution I am programming.</p>