BT

LINQ for F#

by Jonathan Allen on Mar 07, 2012 |

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”.

Hello stranger!

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

Get the most out of the InfoQ experience.

Tell us what you think

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

Email me replies to any of my messages in this thread

workflows by Andrew McVeigh

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

Email me replies to any of my messages in this thread

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

Email me replies to any of my messages in this thread

1 Discuss

Educational Content

General Feedback
Bugs
Advertising
Editorial
InfoQ.com and all content copyright © 2006-2013 C4Media Inc. InfoQ.com hosted at Contegix, the best ISP we've ever worked with.
Privacy policy
BT