Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ


Choose your language

InfoQ Homepage News LINQ for F#

LINQ for F#

This item in japanese

F# 3.0, included in the Visual Studio 11 beta, gains the ability to use LINQ expressions.

While F# has always had access to the underlying libraries that make LINQ possible, F# 3 marks the first version where the LINQ syntax is actually supported. Like Visual Basic, F#’s LINQ supports aggregate functions such as count, sum, first, and last directly in the query. Also like VB, F# doesn’t require a trailing “select” clause. Instead all queries need to be inside an expression that begins with “query {“ and ends with a matching brace.

LINQ or Language Integrated Query is a SQL-like syntax originally developed for the research language Cω and eventually released in Visual Basic and C#. While distinct, it is conceptually similar to languages from 80’s and 90’s such as dBase and PowerBuilder.

Another feature being released with F# 3 is Type Providers. This is a rather complex topic involving what can be thought of as an alternative to both code generation and dynamic typing. For more we direct you to Joe Pamer’s presentation on Type Providers. Out of the box, F# has type providers for:

  • OData services
  • Database Connections such as SQL
  • Database Schema such as LINQ to SQL’s dbml files
  • Entity Data Model format (i.e. EDMX schema files)
  • Web services in the WSDL format
  • Resource files with the extension .resx

An interesting feature of type providers is that they feed into Visual Studio’s IntelliSense at design time. This does mean that there will be times when the code-completion hints show “loading” instead of the actual properties and methods. The delay will depend on the particular type provider and how responsive the server on the far side is.

F# will also be including support for Portable Libraries. Portable Libraries are DLLs that can be shared between .NET, Silverlight, Windows Phone, and/or XNA without recompiling separate versions.

Finally, F# 3 offers auto-implemented properties via the “member val” keyword. Properties need to be initialized as part of their declaration, and mutable properties need the suffix “with get, set”.

Rate this Article