title: Object expression, interface implementation, verbose syntax
body: <p>I frequently use verbose syntax to create one-line expressions that would normally be several lines.  Usually I do this so I can send the whole expression to F# interactive with <code>Alt+'</code>.  For example, I might do this:</p>
  
  <pre><code>let longLength list = let rec helper result = function [] -&gt; result | _ :: t -&gt; helper (result + 1L) t in helper 0L list
  </code></pre>
  
  <p>For the example code, assume that these namespaces have been opened:</p>
  
  <pre><code>open System
  open System.Collections
  open System.Collections.Generic
  </code></pre>
  
  <p>I want to translate this object expression to a single line:</p>
  
  <pre><code>let emptyEnumerator = {
      new IEnumerator&lt;int&gt; with member t.Current = raise(InvalidOperationException())
      interface IEnumerator with
          member t.MoveNext() = false
          member t.Reset() = ()
          member t.Current = raise(InvalidOperationException())
      interface IDisposable with member t.Dispose() = ()
      }
  </code></pre>
  
  <p>I have found that I can only do it using verbose syntax.  Normally, verbose-syntax code also compiles under light syntax, but here, it does not.  I also tried creating a named class with the same implementation, and that nearly-identical code does compile both under light and verbose syntax:</p>
  
  <pre><code>open System
  open System.Collections
  open System.Collections.Generic
  
  #light "off"
  type A() = class interface IEnumerator&lt;int&gt; with member t.Current = raise(InvalidOperationException()) end interface IEnumerator with member t.MoveNext() = false member t.Reset() = () member t.Current = raise(InvalidOperationException()) end interface IDisposable with member t.Dispose() = () end end
  let b = { new IEnumerator&lt;int&gt; with member t.Current = raise(InvalidOperationException()) end interface IEnumerator with member t.MoveNext() = false member t.Reset() = () member t.Current = raise(InvalidOperationException()) end interface IDisposable with member t.Dispose() = () end end }
  
  #light "on"
  type C() = class interface IEnumerator&lt;int&gt; with member t.Current = raise(InvalidOperationException()) end interface IEnumerator with member t.MoveNext() = false member t.Reset() = () member t.Current = raise(InvalidOperationException()) end interface IDisposable with member t.Dispose() = () end end
  let d = { new IEnumerator&lt;int&gt; with member t.Current = raise(InvalidOperationException()) end interface IEnumerator with member t.MoveNext() = false member t.Reset() = () member t.Current = raise(InvalidOperationException()) end interface IDisposable with member t.Dispose() = () end end }
  </code></pre>
  
  <p>Both class definitions succeed, but the last line fails with "~vsB756.fsx(29,150): error FS0010: Unexpected keyword 'member' in expression. Expected incomplete structured construct at or before this point or other token."</p>
  
  <p>The problem seems to be in the series of member definitions.  Visual Studio highlights the second and third <code>member</code> keywords in the <code>IEnumerator</code> part of the definition as the reasons for the FS0010 error.  (In other words, the highlighted <code>member</code> keywords are the ones that introduce the definitions of <code>IEnumerator.Reset()</code> and <code>IEnumerator.Current</code>.)</p>
  
  <p>Visual Studio also reports errors on "let" (incomplete value or function definition), on the open brace (unmatched '{'), and on the <code>end</code> keyword before the <code>IDisposable</code> implementation, but I suspect that this is because of its failure to recognize the three members in the <code>IEnumerator</code> implementation, which causes it to try to parse the additional members as part of the definition of the first member.</p>
  
  <p>Have I overlooked something in the syntax?  Is this a bug in the compiler?</p>