F# (F Sharp) An Introductory Look By Kody Myers. History “Mathematicians stand on each others'...

27
F# (F Sharp) An Introductory Look By Kody Myers

Transcript of F# (F Sharp) An Introductory Look By Kody Myers. History “Mathematicians stand on each others'...

Page 1: F# (F Sharp) An Introductory Look By Kody Myers. History “Mathematicians stand on each others' shoulders and computer scientists stand on each others'

F# (F Sharp)An Introductory Look

By Kody Myers

Page 2: F# (F Sharp) An Introductory Look By Kody Myers. History “Mathematicians stand on each others' shoulders and computer scientists stand on each others'

History“Mathematicians stand on each others' shoulders and computer scientists stand on each others' toes.”

- Richard Hamming, 1968 Turing Award recipient

Page 3: F# (F Sharp) An Introductory Look By Kody Myers. History “Mathematicians stand on each others' shoulders and computer scientists stand on each others'

Lambda Calculus (λ-calculus)

• A formalism for representing functions.

• Formulated by Alonzo Church in the 1930s.

• Formed the basis of functional programming.

Page 4: F# (F Sharp) An Introductory Look By Kody Myers. History “Mathematicians stand on each others' shoulders and computer scientists stand on each others'

Early Functional Languages

• Lisp – 1958

• ISWIM (“If you See What I Mean”) – 1966

• Metalanguage (ML) – 1973

• Caml – 1985

• Haskell - 1990

Page 5: F# (F Sharp) An Introductory Look By Kody Myers. History “Mathematicians stand on each others' shoulders and computer scientists stand on each others'

"There are only two kinds of programming languages: those people always bitch about and those nobody uses.”

- Bjarne Stroustrup, Creator of C++

Page 6: F# (F Sharp) An Introductory Look By Kody Myers. History “Mathematicians stand on each others' shoulders and computer scientists stand on each others'

“Why Nobody Uses Functional Languages”

• Article appeared in the ACM SIGPLAN Notices newsletter in 1998 by Philip Wadler.

• Wadler was one of the principal designers of Haskell.

Page 7: F# (F Sharp) An Introductory Look By Kody Myers. History “Mathematicians stand on each others' shoulders and computer scientists stand on each others'

[…] there are a large number of factors that hinder the widespread adoption of functional languages. To be widely used, a language should support interlanguage working, possess extensive libraries, be highly portable, have a stable and easy to install implementation, come with debuggers and profilers, be accompanied by training courses, and have a good track record on previous projects.

-- Philip Wadler

Page 8: F# (F Sharp) An Introductory Look By Kody Myers. History “Mathematicians stand on each others' shoulders and computer scientists stand on each others'
Page 9: F# (F Sharp) An Introductory Look By Kody Myers. History “Mathematicians stand on each others' shoulders and computer scientists stand on each others'

Don Syme

• Principal Researcher at Microsoft Research, Cambridge, UK.

• Was working on generics for C# for the .NET Framework.

• Tasked with finding a functional language that would be a good fit with .NET.

Page 10: F# (F Sharp) An Introductory Look By Kody Myers. History “Mathematicians stand on each others' shoulders and computer scientists stand on each others'

Haskell.NET?

We had a go doing Haskell for .NET. We actually got a long way in doing that, but in the end there is quite a lot of dissonance between Haskell and .NET.

- Don Syme

Page 11: F# (F Sharp) An Introductory Look By Kody Myers. History “Mathematicians stand on each others' shoulders and computer scientists stand on each others'

Okay, How About OCaml.NET, Then?

• OCaml: Objective Caml

• Dialect of Caml.

• Descendent of Metalanguage (ML).

Page 12: F# (F Sharp) An Introductory Look By Kody Myers. History “Mathematicians stand on each others' shoulders and computer scientists stand on each others'

F# 1.0 – May 2005

• Functional programming

• Discriminated unions

• Records

• Tuples

• Pattern matching

• Type abbreviations

• Object programming

• Structs

• Signature files

• Scripting files

• Imperative programming

• Modules (no functors)

• Nested modules

• .NET Interoperability

Page 13: F# (F Sharp) An Introductory Look By Kody Myers. History “Mathematicians stand on each others' shoulders and computer scientists stand on each others'

F# 2.0 – April 2010

• Active patterns

• Units of measure

• Sequence expressions

• Asynchronous programming

• Agent programming

• Extension members

• Named arguments

• Optional arguments

• Array slicing

• Quotations

• Native interoperability

• Computation expressions

Page 14: F# (F Sharp) An Introductory Look By Kody Myers. History “Mathematicians stand on each others' shoulders and computer scientists stand on each others'

F# 3.0 – August 2012

• Type providers

• LINQ query expressions

• CLIMutable attribute

• Triple-quoted strings

• Auto-properties

• Provided units-of-measure

Page 15: F# (F Sharp) An Introductory Look By Kody Myers. History “Mathematicians stand on each others' shoulders and computer scientists stand on each others'

Present Day

Page 16: F# (F Sharp) An Introductory Look By Kody Myers. History “Mathematicians stand on each others' shoulders and computer scientists stand on each others'

F# 3.1 – October 2013

• Named union type fields

• Extensions to array slicing

• Type inference enhancements

**Specification not yet finalized

Page 17: F# (F Sharp) An Introductory Look By Kody Myers. History “Mathematicians stand on each others' shoulders and computer scientists stand on each others'

Currently Active Keywords

abstract

and

as

assert

base

begin

class

default

delegate

do

done

downcast

downto

elif

else

end

exception

extern

false

finally

for

fun

function

global

if

in

inherit

inline

interface

internal

lazy

let

let!

match

member

module

mutable

namespace

new

not

null

of

open

or

override

private

public

rec

return

return!

select

static

struct

then

to

true

try

type

upcast

use

use!

val

void

when

while

with

yield

yield!

Page 18: F# (F Sharp) An Introductory Look By Kody Myers. History “Mathematicians stand on each others' shoulders and computer scientists stand on each others'

Inactive Keywords From OCaml

asr

land

lor

lsl

lsr

lxor

mod

sig

Page 19: F# (F Sharp) An Introductory Look By Kody Myers. History “Mathematicians stand on each others' shoulders and computer scientists stand on each others'

Reserved Keywords for Future Use

atomic

break

checked

component

const

constraint

constructor

continue

eager

event

external

fixed

functor

include

method

mixin

object

parallel

process

protected

pure

sealed

tailcall

trait

virtual

volatile

Page 20: F# (F Sharp) An Introductory Look By Kody Myers. History “Mathematicians stand on each others' shoulders and computer scientists stand on each others'

Introducing your“let-saber”“A more elegant weapon for a more civilized age.”

- Obi Wan Kenobi, Star Wars: A New Hope

Page 21: F# (F Sharp) An Introductory Look By Kody Myers. History “Mathematicians stand on each others' shoulders and computer scientists stand on each others'

“let” Us Begin

let hello = “Hello World!”

let pi = 3.1415926

let isRunning = false

let numList = [1 .. 10]

let vehicle = (2013, “Ford”, “Explorer”, true)

let userId = System.Guid.NewGuid()

Page 22: F# (F Sharp) An Introductory Look By Kody Myers. History “Mathematicians stand on each others' shoulders and computer scientists stand on each others'

Wow, Those Puns Were Terrible

• Yeah, you’re probably right.

• Time to lose these boring slides for awhile.

Page 23: F# (F Sharp) An Introductory Look By Kody Myers. History “Mathematicians stand on each others' shoulders and computer scientists stand on each others'

Advantages of F#

• Highly readable, especially for developers who are already with functional languages and .NET programming.

• Highly writeable, especially developing with the help of the Visual Studio IDE.

• Highly reliable, thanks to the tried and heavily-tested libraries of the .NET Framework.

• Moderately portable to other, non-Windows platforms, thanks to the Mono project.

Page 24: F# (F Sharp) An Introductory Look By Kody Myers. History “Mathematicians stand on each others' shoulders and computer scientists stand on each others'

Disadvantages of F#

• Functional languages require an uncomfortable adjustment to the way programmers normally think about problems.

• Sacrifices a measure of performance in favor of reliability.

• Hasn’t garnered a comparable amount of confidence as the other more well-established languages of the .NET Framework.

• Practical solutions are limited to very specific class of problems.

Page 25: F# (F Sharp) An Introductory Look By Kody Myers. History “Mathematicians stand on each others' shoulders and computer scientists stand on each others'

The Future: F# 4.0+

• Printf on unitized values

• Extension property initializers

• Non-null provided types

• Class names as functions

• Static parameters for provided methods

• Printf interpolation

• Extended #if grammar

• Support for 'fixed'

• Tailcall attribute

• Multiple interface instantiations

• Optional type args

• Params dictionaries

Page 26: F# (F Sharp) An Introductory Look By Kody Myers. History “Mathematicians stand on each others' shoulders and computer scientists stand on each others'

A Sampling of Practical Applications

• Unit conversion

• Power generation load balancing and scheduling

• Insurance risk engine

• Game rules engine

• Website click prediction

• Forensic image comparison

• Genome sequencing

• Game player ranking

let isFSharpUseful = true

Source: http://fsharp.org/testimonials/

Page 27: F# (F Sharp) An Introductory Look By Kody Myers. History “Mathematicians stand on each others' shoulders and computer scientists stand on each others'

Suggested Resources

• Try F# – tryfsharp.org

• The F# Software Foundation – fsharp.org

• F# for fun and profit – fsharpforfunandprofit.com