1
votes

I am new to programming and F# is my first .NET language.

Here is some code I have written so far:

let downloadFromWebsite (url: string) =
    async { 
        let uri = new System.Uri(url)
        let webClient = new WebClient()
        let! html = webClient.AsyncDownloadString(uri)
        printfn "Read %d characters from %s" html.Length url
        return html
        }

let results = downloadFromWebsite @"http://plato.stanford.edu"
printf "%s" results

Here is the error message:

~vs8222.fsx(19,13): error FS0001: This expression was expected to have type string but here has type Async

What went wrong? What changes should I make?

1

1 Answers

3
votes

results is an Async<string> while the format string you're using requires a string. You need to run the computation and get the result before you can print it. You can use Async.RunSynchronously:

let results = downloadFromWebsite @"http://plato.stanford.edu" |> Async.RunSynchronously
printf "%s" results