Sunday, August 28, 2011

DEV311 A Practical Developer's Introduction to F#

Ivan Towlson
Apologies that this post is fairly nonsensical. I've put my raw NZ TechEd 2011 notes up here for my reference. I'd like to think that I'll refine them over time, but that probably won't be the case.
TechEd Online Ivan's website - TechEd NZ 2011 demos and videos

What is F#?

A strongly typed functional programming language for .NET.
Can use existing .NET libraries.

F# outputs .NET assemblies so can be called from C# or VB.NET

Functional language.
Organised by functions rather than classes and objects.

Use cases
 Scientific and numerical computing
 Parsers / DSLs
 General purpose

F# 2 is included in Visual Studio 2010
Runs on all major .NET platforms

Variable types are inferred

All functions have a value and will return a value.

Indentation is significant. Indent implies structure (no braces)

Can't leave out else clause from if expression as it should return a value.

BigInteger can handle really large numbers

Can add new infix operators

F# lists are more like linked lists and are immutable.

New lists and share allocated resources to existing lists as the are immutable.

Pipeline operator |> makes chaining operators easier to read. Kind of similar to extension methods in C#

Shorthand lamda syntax. Can leave the full lamba syntax out.

Function composition operator 
(not << divisibleBy 2)

type State = { }

Units of measure can provide compile time checking 

async and let! (yield the thread until the async result is returned)

  Smaller programmer pool - Project managers won't like it.
  Learning curve
  Tooling - language interop is your friend

  Saves work - F# works harder so you don't have to
  Expressive power - e.g. pattern matching, options, infix
  Immutability by default
  Async workflows and agents
Friendly F# - F# snippets