Anonymous user
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▼
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 =
let sols' = html.Split([|"{{header|"|], System.StringSplitOptions.None).Length - 1
lock stdout (fun () -> printfn "%s: %d
|> Async.Parallel
|> Async.RunSynchronously
|> fun xs -> printfn "Total: %d examples" (Seq.sum xs)</lang>
This is 21× faster than the python thanks to the concurrency.
=={{header|Haskell}}==
{{libheader|HTTP XML}} from [http://hackage.haskell.org/packages/hackage.html HackageDB]
|