FSharp.Data provides F# type providers for working with common external data formats and sources. It can generate usable types from CSV, JSON, or HTML, making data ingestion and exploration concise without requiring manually defined classes. section 10.7
An HTML type provider can treat a local file or live web page as a schema. The generated API exposes tables and rows directly, so a Wikipedia table can become a programmatic dataset with only a few lines of F#. section 10.3.3
Reading a table and calculating density
type LondonBoroughs = HtmlProvider<"https://en.wikipedia.org/wiki/List_of_London_boroughs">\nlet boroughs = LondonBoroughs.GetSample().Tables.``List of boroughs and local authoritiesEdit``\n\nlet density =\n boroughs.Rows\n |> Array.map (fun row ->\n row.Borough,\n row.``Population (2019 est)`` / row.``Area (sq mi)``\n )\n |> Array.sortByDescending snd\n |> Chart.Column\n |> Chart.show section 10.3.3 section 10.4
The resulting array of tuples is enough to pass data into Plotly.NET: neither library requires custom interfaces or classes. Standard F# arrays, collection functions, pipelines, and lambdas connect ingestion, calculation, and presentation. section 10.4
Listing 10.5 Using the HTML type provider
#r "nuget:FSharp.Data" open FSharp.Data type LondonBoroughs = HtmlProvider<"https://en.wikipedia.org/wiki/ List_of_London_boroughs"> #1 let boroughs = LondonBoroughs.GetSample().Tables. ``List of boroughs and local authoritiesEdit`` #2 boroughs.Rows |> Array.map (fun row -> row.Borough) #3 #1 Defines a schema based on a live HTML web page #2 Accesses a specific table #3 Uses the data to list all boroughs
Inspect the complete HTML type-provider example, including the NuGet reference, generated schema, named table access, and row mapping. section 10.3.3
