title: Implement IEnumerable in Fsharp on external type
body: <p>I am trying to implement a ToEnumerable property on an external type that does not implement it. I can't quite get the code to work.</p>
  
  <p>So I dumbed it down to adding a untyped <strong>GetEnumerator</strong> property, and added the code for ToComparable for guidance. However, I have no idea on how to store the mutable state for the counter.</p>
  
  <p>Is the pb the anonymous class ?</p>
  
  <p>How would you do it ?</p>
  
  <pre><code>open System
  open System.Collections
  open System.Collections.Generic
  
  type Bloomberglp.Blpapi.Element with
       //**WORKS OK**
       member this.ToComparable:IComparer&lt;Bloomberglp.Blpapi.Element&gt; =   { 
          new IComparer&lt;Bloomberglp.Blpapi.Element&gt; with 
             member this.Compare(x, y) = x.NumValues.CompareTo(y.NumValues) 
       }
  
       //**WORKS (sort of) OK without storing the state**
       member this.GetEnumerator2:IEnumerator =  {
          //let mutable i =0
          new IEnumerator with
                member this2.Reset() = 
                   i &lt;- 0;
                   ()
                member this2.MoveNext() = 
                   if i &lt; n then 
                      i &lt;- i + 1
                      true
                   else
                      false
                member this2.Current 
                   with get() =
                      this.GetElement(0) :&gt; obj
       }
  </code></pre>