Rosetta Code/Count examples: Difference between revisions

Concurrent F#
(Concurrent F#)
Line 212:
 
=={{header|F#}}==
 
Using asynchronous workflows to perform downloads concurrently:
 
<lang fsharp>#r "System.Xml.Linq.dll"
 
Line 217 ⟶ 220:
let uri2 task = sprintf "http://www.rosettacode.org/w/index.php?title=%s&action=raw" task
 
[|for xml in (System.Xml.Linq.XDocument.Load uri1).Root.Descendants() do
let mutable sols = 0
for attrib in xml.Attributes() do
for xml in (System.Xml.Linq.XDocument.Load uri1).Root.Descendants() do
if attrib.Name.LocalName = "title" then
for attrib in xml.Attributes() do
yield async {
if attrib.Name.LocalName = "title" then
let uri = uri2 (attrib.Value.Replace(" ", "_") |> System.Web.HttpUtility.UrlEncode)
use client = new System.Net.WebClient()
let! html = try client.DownloadStringAsyncDownloadString(System.Uri uri) with _ -> ""
let sols' = html.Split([|"{{header|"|], System.StringSplitOptions.None).Length - 1
lock stdout (fun () -> printfn "%s: %d solutionsexamples" attrib.Value sols')
sols <- sols + return sols' }|]
|> Async.Parallel
printfn "%d solutions in total." sols</lang>
|> Async.RunSynchronously
|> fun xs -> printfn "Total: %d examples" (Seq.sum xs)</lang>
 
This is 21&#215; faster than the python thanks to the concurrency.
 
=={{header|Haskell}}==
{{libheader|HTTP XML}} from [http://hackage.haskell.org/packages/hackage.html HackageDB]
Anonymous user