title: Using F#'s built-in async support with *Async() methods
body: <p>How do I use F#'s built-in support for async operations classes exposing the <a href="http://msdn.microsoft.com/en-us/library/wewwczdw.aspx" rel="nofollow noreferrer">Event-based Asynchronous Pattern</a> such as <em>WebClient</em> class?</p>
  
  <pre><code>let Download(url : Uri) =
      let client = new WebClient()
      let html = client.DownloadString(url)
      html
  </code></pre>
  
  <p>When I try to change this to use "let!" in an <em>async</em> block (say as described in Soma's recent <a href="http://blogs.msdn.com/somasegar/archive/2009/10/09/f-in-vs2010.aspx" rel="nofollow noreferrer">post</a>)</p>
  
  <pre><code>let Download(url : Uri) =
      async {
      let client = new WebClient()
      let! html = client.DownloadStringAsync(url)
      return html }
  </code></pre>
  
  <p>I get an error message:</p>
  
  <blockquote>
    <p>Type constraint mismatch. The type   unit is not compatible with type  Async&lt;'a> The type 'unit' is not compatible with the type 'Async&lt;'a>'</p>
  </blockquote>
  
  <p>Edit: I'm really asking about the general question of using *Async() methods, WebClient is just an easy example.  Microsoft <a href="http://msdn.microsoft.com/en-us/library/ms228966.aspx" rel="nofollow noreferrer">says</a> "... you should expose asynchronous features using the Event-based Asynchronous Pattern [ as opposed to BeginFoo()/EndFoo() ] whenever possible ..." so I would think there should be an easy way to consume an arbitrary *Async() method from F#. </p>