Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4235828
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T02:33:21+00:00 2026-05-21T02:33:21+00:00

After shamelessly pilfering a code snippet from Tomas Petricek’s Blog: http://tomasp.net/blog/csharp-fsharp-async-intro.aspx Specifically, this one

  • 0

After shamelessly pilfering a code snippet from Tomas Petricek’s Blog:
http://tomasp.net/blog/csharp-fsharp-async-intro.aspx
Specifically, this one (and making a few alterations to it):

     let downloadPage(url:string) (postData:string) = async {
  let request = HttpWebRequest.Create(url)
// Asynchronously get response and dispose it when we're done
  use! response = request.AsyncGetResponse()
  use stream = response.GetResponseStream()
  let temp = new MemoryStream()
  let buffer = Array.zeroCreate 4096 

   // Loop that downloads page into a buffer (could use 'while' 
   // but recursion is more typical for functional language)
  let rec download() = async { 
   let! count = stream.AsyncRead(buffer, 0, buffer.Length)
   do! temp.AsyncWrite(buffer, 0, count)
   if count > 0 then return! download() }

   // Start the download asynchronously and handle results
  do! download()
  temp.Seek(0L, SeekOrigin.Begin) |> ignore
  let html = (new StreamReader(temp)).ReadToEnd()
  return html };;

I tried to do the following with it, and got the error on the last line:

The type was expected to have type Async<'a> but has string -> Asnyc<'a> instead

I googled the error but couldn’t find anything that revealed my particular issue.

let postData = "userid=" + userId + "&password=" + password + "&source=" + sourceId + "&version=" + version
let url = postUrlBase + "100/LogIn?" + postData
Async.RunSynchronously (downloadPage(url, postData));;

Also, how would I modify the code so that it downloads a non-ending byte stream (but with occasional pauses between each burst of bytes) asynchronously instead of a string? How would I integrate reading this byte stream as it comes through? I realize this is more than one question, but since they are are all closely related I figured one question would save some time.

Thanks in advance,

Bob

P.S. As I am still new to F# please feel free to make any alterations/suggestions to my code which shows how its done in a more functional style. I’m really trying to get out of my C# mindset, so I appreciate any pointers anyone may wish to share.

Edit: I accidentally pasted in the wrong snippet I was using. I did make an alteration to Tomas’ snippet and forgot about it.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T02:33:21+00:00Added an answer on May 21, 2026 at 2:33 am

    When I attempt to run your code downloadPage(url, postData) doesn’t work as downloadPage expects two seperate strings. downloadPage url postData is what is expected.

    If you changed the let binding to tuple form, or let downloadPage(url:string, postData:string) your call would have worked as well.

    To explain why you got the error you got is more complicated. Curried form creates a function that returns a function or string -> string -> Async<string> in your case. The compiler therefore saw you passing a single parameter (tuples are single items after all) and saw that the result would have to be a string -> Async<string> which is not compatible with Async<string>. Another error it could have found (and did in my case) is that string * string is not compatible with string. The exact error being Expected string but found 'a * 'b.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

After I click update in the grid view, the code works successfully. But when
I have the following code (asp.net-mvc, jquery) (i have simplified the example to show
After reading http://gbif.blogspot.com/2011/01/setting-up-hadoop-cluster-part-1-manual.html we came to the conclusion our 6-nodes hadoop cluster could use
After using Instruments, I have found the a spot in my code that is
After updating from ruby-1.8.7-p352 to ruby-1.8.7-p358 via rvm , gems are still installed to
After doing an AJAX call, am redirecting- using the following code. But, after AJAX
Take this jsFiddle as example: http://jsfiddle.net/mostthingsweb/cfDHm/3/ . Note that I am able to use
After going through so many documents and online content like: http://stackoverflow.com/questions/4066167/sencha-touch-or-jquery-mobile http://stackoverflow.com/questions/5093691/sencha-touch-vs-jqtouch-vs-gwt-mobile-vs-xui-vs-jquery-mobile-vs http://www.quora.com/Were-deciding-between-jQuery-Mobile-currently-in-alpha-and-Sencha-Touch-What-are-the-pros-and-cons-for-each http://interfacethis.com/2011/adventures-in-html5-part-one/
After deploying WCF server (svc) on my Server, I have got this message when
After discovering about Javascript namespaces, I tried to implement them but I run into

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.