BT

InfoQ Homepage News LINQ for F#

LINQ for F#

Bookmarks

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

Adoption
Style

Hello stranger!

You need to Register an InfoQ account or or login to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Community comments

  • workflows

    by Andrew McVeigh /

    • workflows

      by Andrew McVeigh /

      Your message is awaiting moderation. Thank you for participating in the discussion.

      Interesting to see queries are represented as workflows, which already existing in F#2. I wonder if they had to beef up the workflow semantics/interface to do this? Regardless, it's a strong argument for the syntactic power of F# workflows.

      Also curious that each query starts with " for student in db.Student do" and the remaining statements have no indenting. It will be interesting to look into the implementation of this and why they chose that strategy.

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

BT

Is your profile up-to-date? Please take a moment to review and update.

Note: If updating/changing your email, a validation request will be sent

Company name:
Company role:
Company size:
Country/Zone:
State/Province/Region:
You will be sent an email to validate the new email address. This pop-up will close itself in a few moments.