type Person =
  {Name: string;
   Age: int;}

Full name: index.Person
Person.Name: string
Multiple items
val string : value:'T -> string

Full name: Microsoft.FSharp.Core.Operators.string

--------------------
type string = System.String

Full name: Microsoft.FSharp.Core.string
Person.Age: int
Multiple items
val int : value:'T -> int (requires member op_Explicit)

Full name: Microsoft.FSharp.Core.Operators.int

--------------------
type int = int32

Full name: Microsoft.FSharp.Core.int

--------------------
type int<'Measure> = int

Full name: Microsoft.FSharp.Core.int<_>
val name : string * string

Full name: index.name
val firstName : string

Full name: index.firstName
val secondName : string

Full name: index.secondName
val numbers : int list

Full name: index.numbers
namespace Microsoft
namespace Microsoft.FSharp
namespace Microsoft.FSharp.Data
namespace Microsoft.FSharp.Data.UnitSystems
namespace Microsoft.FSharp.Data.UnitSystems.SI
namespace Microsoft.FSharp.Data.UnitSystems.SI.UnitNames
val measurements : (string * float<meter ^ 2>) list

Full name: index.measurements
[<Measure>]
type meter = metre

Full name: Microsoft.FSharp.Data.UnitSystems.SI.UnitNames.meter
Multiple items
module List

from Microsoft.FSharp.Collections

--------------------
type List<'T> =
  | ( [] )
  | ( :: ) of Head: 'T * Tail: 'T list
  interface IEnumerable
  interface IEnumerable<'T>
  member GetSlice : startIndex:int option * endIndex:int option -> 'T list
  member Head : 'T
  member IsEmpty : bool
  member Item : index:int -> 'T with get
  member Length : int
  member Tail : 'T list
  static member Cons : head:'T * tail:'T list -> 'T list
  static member Empty : 'T list

Full name: Microsoft.FSharp.Collections.List<_>
val sumBy : projection:('T -> 'U) -> list:'T list -> 'U (requires member ( + ) and member get_Zero)

Full name: Microsoft.FSharp.Collections.List.sumBy
val snd : tuple:('T1 * 'T2) -> 'T2

Full name: Microsoft.FSharp.Core.Operators.snd

F#

The Pit of Success

About me

  • .NET dev / contractor / consultant since .NET 1.0
  • Director of Compositional IT
  • F# developer since 2012
  • Microsoft MVP in F# / .NET
  • Based in Hessen & London

alt

This talk...

  • will not teach you everything about F# :-(
  • will give you a flavour of the language and tooling :-)
  • will make you wish you had some of these features in your current language :-)
  • will involve about 15 minutes of presentation + talking :-(
  • ...then about 60-90 minutes of coding and demos :-)
  • ...QA throughout please!

As a junior dev...

alt

Aha!

alt

alt

alt

alt

What is F# then?

  • Functional-first programming language
  • Pragmatic, not purist
  • General purpose
    • Web apps
    • Console programs
    • Desktop apps etc.

But also!

  • Data-driven apps
  • Distributed applications
  • Machine Learning
  • Exploratory scripting

Why F#?

  • It's awesome :)
  • Easy to use
  • Get things done quickly but safely
  • Happier developers
  • Happier customers
  • solve complex problems with simple code
  • define your problem domain with compiler support rather than e.g. unit tests or runtime errors
  • type inference reduces bloat
  • make code easier to reason about

Testimonials

alt

Jet

E-Commerce

Credit Suisse

Investment Banking

Bayard Rock

Anti Money Laundering

Grange

Insurance

Bing

Search

Lufthansa Cargo

Aviation & Logistics

alt

alt alt

Why not OO?

  • Inheritance vs Composition
  • State vs Immutability
  • Identity vs Structural Equality

The changing face of hardware

  • CPU clock speed has reached a peak
  • Single machine computing no longer sufficient for data-intensive problems
  • Systems are becoming more complex

The shifting programming landscape

alt

Isn't FP hard?

Isn't FP black magic?

alt

The .NET / CLR picture

alt

Three sides to every story...

C# and VB .NET

F#

Mutable by default

Immutable by default

Side-effects and statements

Expressions

Classes

Data + Functions

Inheritance

Function Composition

State

Pure functions

Polymorphism

Algebraic Data Types

The future of C#

In C# now

  • Tuple support
  • Limited expression support
  • Limited pattern matching

Coming to C#

  • Non-nullable reference types
  • Union types?

.NET, MS and Open Source

  • .NET is now .NET Core
  • Microsoft are the largest open source contributor
  • Microsoft are committed to cross-platform
  • Microsoft is committed to F#
  • Azure is driving Microsoft strategy

Open Source in .NET

  • F# community is open, pro-active and self-managing
  • Not reliant on Microsoft for tooling etc.
  • Creating lots of open source projects
  • Already has a strong x-platform community
  • C# and VB communities need to follow suit

Syntax overview

F# is lightweight

 1: 
 2: 
 3: 
 4: 
 5: 
 6: 
 7: 
 8: 
 9: 
10: 
class Person {
    private readonly string name;
    private readonly int age;
    public string Name { get { return name; } }
    public string Age { get { return age; } }
    public Person(string name, int age) {
        this.name = name;
        this.age = age;
    }
}

vs

1: 
type Person = { Name : string; Age : int }
1: 
2: 
3: 
4: 
var name = Tuple.Create("isaac", "abraham")
var firstName = name.Item1
var secondName = name.Item2
var numbers = new List<int>(new [] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 })

vs

1: 
2: 
3: 
let name = "isaac", "abraham"
let firstName, secondName = name
let numbers = [ 1 .. 10 ]

F# is safe

 1: 
 2: 
 3: 
 4: 
 5: 
 6: 
 7: 
 8: 
 9: 
10: 
open Microsoft.FSharp.Data.UnitSystems.SI.UnitNames

let measurements =
    [   "Lounge", (7.47<meter> * 3.51<meter>)
        "Bedroom 1", (4.11<meter> * 2.74<meter>)
        "Bedroom 2", (4.19<meter> * 2.06<meter>) ]

measurements |> List.sumBy snd

// val it : float<meter ^ 2> = 46.1125

F# is designed for scale

Demos!

How do we get started?

  • You can start small
    • Scripts
    • Testing
    • Build system
  • Write F# projects alongside C# / VB .NET projects
  • Interop with non-CLR languages via Type Providers e.g. R

Find out and learn more...

Thank you!

Questions?

https://compositional-it.com

@isaac_abraham

isaac@compositional-it.com