Download presentation
Presentation is loading. Please wait.
Published byCharlotte Wilcox Modified over 8 years ago
1
Phillip Trelford 1
2
Goals Introduce F# Non-goals Cover every language feature Mass conversion to FP cult Sell books 2
3
1. Background 2. Programming Syntax 3. Code Sample 3
4
F# is multi-paradigm language, that is: Functional Object Orientated Imperative (A bit like Python) It also happens to be: A first class.Net language with Visual Studio integration 4
5
A paradigm where computation is declared as math functions: Avoiding state and mutable data Think C++ const correctness as the default Functional Programming Examples: Haskell Excel JavaScript 5
6
Target communities Scientific (Microsoft Research, AdCenter) Academic (French Universities use OCaml) Financial (Morgan Stanley, Credit Suisse) Target problem domains Maths Meta programming Scripting 6
7
Created by Don Syme (Microsoft Research Cambridge) (Creator of.Net Generics & Cup user) Influenced by ML OCaml To provide first class functional programming for.Net 7
8
Visual Studio integration Product announced on Somasegar’s blog (Oct 2007) CTP release available from MSDN site Books Expert F# book (Dec 2007) Foundations of F# (May 2007) Community Planet F# - RSS feed HubFS Forum 8
9
Programming in F# can be a bit like programming in C++ with const permanently turned on: 9 C++F# const int x = 10;let x = 10 mutable int x; void foo() const { x = 20; } let mutable x = 10; x <- 20
10
Beware.Net reference types don’t hold any implicit immutability guarantee. (As C#). Anything that isn’t a value type is a reference type. 10 C# pass by referenceF# pass by reference var x = 10; Foo(ref x) x = 20 x let x = ref (10) Foo x x := 20 !x
11
Anonymous/Lamda functions: [“Hello”,”World”] |> List.iter (fun i -> Debug.WriteLine(i)) Function nesting: let OuterF () = let InnerF word = Debug.WriteLine (word) InnerF “Hello” InnerF “World” 11
12
Tuples are type safe anonymous structures (no indexer): let me = (“Phil”, Male, 1.92, 1971) let name, sex, height, year = me Boost has a Tuple library: Ticker ticker = make_tuple(“Barclays”, 244.75, -40.25) double price = get (ticker); 12
13
let mul x y = x*y let tentimes = mul 10.0 13
14
let (|>) x f = f x Reduces scope of temporary variables 14 F# Code Sample // Shows name and first line of all cpp files modified today on drive C Directory.GetFile(@“C:\”, “*.cpp”, SearchOption.AllDirectories) |> Array.filter (fun name -> File.GetModifiedTime(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))
15
if total > 21 then print "Bust" if total > 21: print "Bust” 15
16
Order of declaration of functions and modules Values may be redefined/reused Obscure syntax, e.g. what is :?> 16
17
Not a pure functional language –.Net reference types do not have explicit immutability guarantees Can lead to bottom up programming In wrong hands code can be write only Less samples than C# Currently minimal F# project wizards C# slowly absorbing best F# features 17
18
Fewer lines ≈ Fewer errors Const correctness ≈ More correctness Reduced state ≈ Less errors Meta programming Asynchronous workflows Units of measure 18
19
19
20
20
21
21
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.