Download presentation
Presentation is loading. Please wait.
1
Phillip Trelford Twitter: @ptrelford Blog: http://www.trelford.com/blog
2
Talk Goals Goals Introduce F# Non-goals Provide in-depth understanding Mass conversion to functional programming cult Sell my own books
3
Talk Structure 1. Background 2. Language Syntax 3. Code Samples
4
Jargon Buster OO = Object Orientated FP = Functional Programming Lambda = Anonymous Function DSL = Domain Specific Language
5
What is F#? F# is multi-paradigm language, that is: Functional Declarative Object Orientated Imperative.Net language with VS integration (a bit like Python)
6
Languages circa 2010 Functional Clojure Erlang F# Haskell Scala Dynamic Groovy JavaScript Python Ruby OO C++ C# Java VB.Net
7
Functional Programming Key Features Functions are idempotent Functions are first class High order functions Languages: Scala Excel JavaScript
8
Real World FP Erlang Document DB: CouchDB, Amazon Simple DB Messaging: RabbitMQ, ejabberd F#/OCaml Financial: Credit Suisse, Jane Street Capital, UBS Technical Halo3,Bing Haskell Academic
9
A Brief History of F# Created in 2002 by Don Syme (Microsoft Research Cambridge) (Creator of.Net Generics & Cup holder) Influenced by OCaml (1996) ML (1973) Mission: First class functional programming for.Net
10
Books
11
F# Community RSS: Microsft F# Developer Center Forums: HubFs London F# User Group
12
Performance
13
Conditions C#: int x; If(result) x = 1; else x = 0; F#: let x = if result then 1 else 0 C#: var x = result ? 1 : 0;
14
Light syntax (like Python) F#: if total > 21 then print "Bust" Python: if total > 21: print "Bust”
15
Tuples NameExample Single(1) Pair(1,2) Triple(1,2,null) Quadruple(1,2,3.0, null) Quintuple Sextuple Septuble Octuple Nonuple Decuple
16
Tuples F#: let me = (“Phil”, Male, 1.92, 1971) let name, sex, height, year = me C# (.Net 4.0): var me = PhiPTuple.Create(“Phil”,1971); var name = me.Item1; C++ (Boost ): Ticker ticker = make_tuple(“Barclays”, 244.75, -40.25) double price = get (ticker);
17
Partial Application F# let times x y = x*y let tenTimes = times 10.0
18
Composition let (|>) x f = f x F# Code Sample Directory.GetFiles(@"C:\", "*.cpp", SearchOption.AllDirectories) |> Array.filter (fun name -> File.GetLastWriteTime(name) > DateTime.Now.Date) |> Array.map (fun name -> name, using (File.OpenText (name)) (fun reader -> reader.ReadLine()) ) |> Array.iter (fun (name, firstLine) -> Console.WriteLine (name) Console.WriteLine (firstLine))
19
Classes type Child(name,age) = member this.Name = name member this.Age = age override this.ToString() = sprintf "%s %d" name age
20
Records type Child = { Name:string; Age:int } with override this.ToString() = sprintf "%s %d" this.Name this.Age
21
Discriminated Unions type Child = Child of string * int type Sex = Male | Female type Tree = | Branch of Tree * Tree | Leaf of 'a
22
Automating Acceptance Tests Scenario X: given a customer buys a black jumper type ``Scenario X`` = let basket = Basket() member this. ``given a customer buys a black jumper`` = basket.Add(“Black Jumper”,1)
23
Gotchas Order of declaration of functions and modules Values may be redefined Obscure syntax, e.g. what is :?>
24
F# Strengths F# MathSuccinct Language Orientated Concurrency.Net Integration
25
Demos
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.