From its initial release, F# has always been a good language for manipulating data. The standard F# library provides a wide range of functions that help to reduce the complexity of data-processing tasks. For example, grouping, aggregation, and floating windows can be implemented in a single line of code. F#’s rich libraries, concise syntax, and support for functional programming can significantly reduce the time to market for data-driven applications. Despite these features, many data-access tasks require some amount of boilerplate code.
For example, consider the task of reading historical stock prices from the Yahoo! Finance site, which returns data as a comma-separated value (CSV) file. When pulling data, you create a simple data type representing the data stored in the rows (for example, a StockQuote type with appropriately typed properties for the date, opening price, and so on) along with a corresponding method for creating an instance of the type from the strings pulled from the columns of the file. Given the columns of the file, creating this data type is completely mechanical; but before F# 3.0, there wasn’t a good way to automate this kind of metaprogramming. CSV files are just one example of a data source that has a logical schema that can be mapped to F# types—the same type of problem arises when dealing with databases, web services, XML and JSON documents, and even entire REST services.