Welcome to the F# May 2009 Community Technology Preview (CTP). F# is a typesafe, scalable, succinct, typed, efficient programming language for the .NET platform. This release represents an important step in the evolution of the F# language as we progress it towards product quality. The release contains:
Full details can be found at the F# Developer Center or the F# website . There you can find additional F# learning resources, links to the F# community and more. You may be interested in tracking Don Syme's F# blog and/or blogging about your experiences with using F#. If you are getting started with F#, try the following sites:
Your feedback is highly valuable to the F# team. Please send any comments to fsbugs@microsoft.com. Your positive and negative feedback, as well as suggestions, comments, feature requests, and bug reports are warmly welcomed.
If you have questions for the F# user community, post them to one of the sites listed in the Support section below.
This F# CTP is pre-release software and is not officially supported by Microsoft product support. If you have issues or questions that require support, you can use one of the following resources:
You may run F# programs in conjunction with other CLI implementations such as Mono. Please read the notes below. Some more information is available at the F# Wiki.
This release makes many improvements to the core experience provided with the last F# CTP, with improved debugging support, performance and scalability improvements in the language, libraries and Visual Studio, many minor language extensions, and a release of Visual Studio 2010 Beta1 with F# integrated.
The changes in this release are documented briefly below. More details are contained in the blog announcements coinciding with this release.
All F# source files now use the whitespace-aware #light syntax by default. This may be turned off with #light off at the top of a source file.
F# can call methods with ParamArray parameters defined in other .NET languages such as:
System.Console.WriteLine("a","b","c","d","e","f")
// Results in the following call:
// System.Console.WriteLine("a", [|"b";"c";"d";"e";"f"|])
F# types can also expose ParamArray parameters themselves using System.ParamArrayAttribute:
open System
type MyType() =
member this.M([] args : string[]) =
args |> Array.iter (printfn "%A")
Sequence expressions are now compiled to state machines, instead of as a collection of API calls. This results in improved performance of F# code which works with seq. Many of the Seq.* library functions also have improved performance as a result of this change.
Units of measure may now be applied to integral types such as int and int64, as well as existing floating point types such as float and decimal.
[<Measure>]
type clicks
let x = 64<clicks>
Also, a few bugs fixes to enable definitions of OO types annotated with measures to have the full range of overloaded operators (e.g. Vector, Matrix etc.).
It is now possible to bind numeric literals to custom numeric types. Custom numeric literals, with a numeric constant followed by a single letter, are treated as syntactic sugar for API calls.
In particular, 123X is now syntactic sugar for
NumericLiteralX.FromInt32(123)
Likewise
NumericLiteralX.FromZero()
NumericLiteralX.FromOne()
NumericLiteralX.FromInt32(6)
NumericLiteralX.FromInt64(…)
NumericLiteralX.FromString(…)
Depending on the input constant.
The ? and ?<- operators now treat their right-hand argument as a parse-time symbol, and pass this symbol to the operator definition as a string argument. This enables the definition of dynamic lookup as a library implementation of the ? operator.
open System.Reflection
let (?) (x: 'a) (prop: string) : 'b =
// A simplified '?' operator for dynamic property
// lookup using reflection
let pi = typeof<'a>.GetProperty(prop)
pi.GetValue(x, [||]) :?> 'b
let statically = "hello".Length
let dynamically : int = "hello"?Length
The command line options for the F# compiler have been further aligned with standard .NET compiler practice. Here are a few notable changes:
To see the full list of compiler options, use fsc.exe -?
The camelCase naming scheme has been adopted in place of under_scores in the compositional functional programming modules.
A few other functions have been renamed to align better with this naming convention.
F# BigInteger has been aligned with the new .NET4.0 BigInteger type. On .NET 2.0, a matching BigInteger implementation is included in FSharp.Core.dll.
The BigRational type has been moved into the F# PowerPack.
Two tools for customizing structured formatting of values with %A or in the F# Interactive have been added to this release.
%<width>.<node-count>A
A width of 0 will mean "no line splitting", i.e. 1-dimensional layout.
[<StructuredFormatDisplay("matrix {StructuredDisplayAsArray}")>]
type Matrix<'T>(width,height,generator:int->int->'T) =
///...Matrix members...
member private this.StructuredDisplayAsArray =
Array2D.init width height generator
This attribute is used to mark how a type is displayed by default when using %A printf formatting patterns and other two-dimensional text-based display layouts. In version 1 of F# the only valid values will be of the form PreText {PropertyName} PostText. The property name indicates a property to evaluate and to display instead of the object itself.
As a library developer:
As a library developer:
F# compiled for .NET4.0 uses the new System.Tuple and System.Lazy types in place of F#-specific types.
F# Async workflows can be used to compose together .NET4.0 Tasks, using the Task<'T>.AsyncValue and Async.StartAsTask functions.
async { // Await the value from some future we've been given
// This is effectively "ContinueWith"
let! v1 = someFuture.AsyncValue
... }
async { // Set a sub-async program running as a future
let! subtask = Async.StartChildAsTask ( async { ... } )
// Await the value from the future (don't block the thread!)
// This is effectively "ContinueWith"
let! v1 = subtask.AsyncValue
... }
let mytask = async { ... } |> Async.StartAsTask
Data parallel versions of some of the common Array operations are available in the Array.Parallel module. These can be used to quickly parallelize key loops in F# code. The performance profile of these operations is derived from the System.Threading.Parallel.For API in .NET4.0.
let random = new System.Random()
let numPoints = 10000000
let points = Array.init numPoints (fun _ -> random.NextDouble(), random.NextDouble())
let numInCircle =
points
|> Array.Parallel.choose (fun (x,y) ->
if x*x + y*y <= 1.0 then Some (x,y) else None)
|> Array.length
let pi = 4.0 * float numInCircle / float numPoints
The following Async utility functions have been added to the PowerPack:
The API in this assembly provides access to the F#-specific metadata. This can be used to get information about F# notions such as type abbreviations, units of measure, and currying or parameters.
#r "FSharp.PowerPack.Metadata.dll"
open FSharp.PowerPack.Metadata
let assm = FSharpAssembly.FromFile(@"FSharp.Core.dll")
let entities = assm.Entities
let allAbbreviations =
[ for e in entities do
if e.IsAbbreviation
then yield e.Name ]