KEMBAR78
F# Tutorial @ QCon | PPTX
Turning to the Functional side(Using C# and F#)Phil Trelfordhttp://trelford.com/blog@ptrelfordTomas Petricekhttp://tomasp.net/blog@tomaspetricek
About UsTomas Author of F# book for C# programmersWorked with the F# team at MicrosoftFirst blogged about F# in May 2006Phil Software Developer and ArchitectWorked on first F# applications at MicrosoftCo-organizer of London F# User Group
TutorialGoalsIntroduce Functional Concepts with F# and C#Non-goalsProvide in-depth understandingMass conversion to functional programming cultSell books
Jargon BusterOO = Object OrientatedFP = Functional ProgrammingLambda = Anonymous FunctionDSL = Domain Specific Language
Thoughtworks Technology Radar 2011
Languages circa 2010
Languages go multi-paradigm
F# is a mix of
What is F#?F# is multi-paradigm language, that is:FunctionalDeclarativeObject OrientatedImperative.Net language with VS integration
Running F#Visual Studio 2010Visual Studio Shell + F# MonoDevelop on Linux and MacF# Compiler + Emacs etc.In your browser
FP hits mainstreamVisual Studio gets F#C# gets LINQ, lambdas, etcC++ gets lambdasJVM gets Clojure & Scala
Writing queries with LINQQuery syntax supported in C# 3.0Functional programming conceptsDeclaratively describes “what” not “how”Written as single expressionvarq=frompindb.Productswherep.UnitPrice>75.0MselectString.Format("{0} - ${1}", p.ProductName, p.UnitPrice);
Graphical User Interface FrameworksXUL (Mozilla), Glade (Gtk), XAML (.NET)Functional programming conceptsCompose button with ellipse insideSpecify behavior declaratively<Buttonx:Name="greenBtn" Background="Black">  <EllipseWidth="75"Height="75" Fill="LightGreen" /></Button><DoubleAnimationStoryboard.TargetName="greenBtn"Storyboard.TargetProperty="(Canvas.Left)"    From="0.0"To="100.0"Duration="0:0:5" />
Specifying financial contracts in F#Functional programming conceptsDeclaratively describes “what” not “how”Written as single expressionComposed from small number of primitivesletmarch day = DateTime(2011, 3, day)letitTrades =  (sell (tradeAt(march15) "GOOG"500)) $  (between (march10) (march19) (trade"MSFT"1000))lettradeAtdatewhatamount =between datedate (trade whatamount)
Code Samples1: // Declare a local value (inferred type is string)2: letworld="world"3: 4: // Using '%s' format specifier to include string parameter5: printfn"Hello %s!"world 
Functional data structuresA way of thinking about problemsModel data using composition of primitivesTuple   Combine two values of different typesDiscriminated Union   Represents one of several optionsList   Zero or more values of the same type
Tuples: Containers for a few different things
Discriminated Unions: Exclusive alternatives
Representing event scheduleObject-oriented wayEasy to add new casesHard to add new functionsFunctional wayEasy to add new functionsHard to add new casesGood thing about F# and Scala– you can use both!
List: Heads and Tails
Map ReduceMapReduce is a patented software framework introduced by Google to support distributed computing on large data sets on clusters of computers.Functional design scales extremely well!
Domain ModellingRetail Domain -> Testing
Checkout application workflowThink of a simple while loopImplement…Mutable field to keep the state and event handlers?Asynchronous while loop in F#
Asynchronous and concurrent programmingAsynchronous GUI in Checkout exampleSingle-threaded thanks to Async.StartImmediateEasy way to encode control flowParallel programmingWorkflows are non-blocking computationsRun workflows in parallel with Async.ParallelConcurrent programmingCompose application from (thousands of) agentsAgents communicate using messages
Wild Card FillerSilverlight mini-samples
SummaryFP is already in the mainstreamFP languages are readyStart small, go bigLanguage Orientated ProgrammingExploratory and ScriptingAsynchronous & ConcurrencyTechnical ComputingTesting
SummaryDon’t underestimate the power of the functional side
Meet the F#ers
F# Books
On the horizonNext Meet: In the brain of Rob Pickering on March 16th
Q & Ahttp://Fsharp.nethttp://fssnip.nethttp://tomasp.net/bloghttp://trelford.com/blog

F# Tutorial @ QCon

  • 1.
    Turning to theFunctional side(Using C# and F#)Phil Trelfordhttp://trelford.com/blog@ptrelfordTomas Petricekhttp://tomasp.net/blog@tomaspetricek
  • 2.
    About UsTomas Authorof F# book for C# programmersWorked with the F# team at MicrosoftFirst blogged about F# in May 2006Phil Software Developer and ArchitectWorked on first F# applications at MicrosoftCo-organizer of London F# User Group
  • 3.
    TutorialGoalsIntroduce Functional Conceptswith F# and C#Non-goalsProvide in-depth understandingMass conversion to functional programming cultSell books
  • 4.
    Jargon BusterOO =Object OrientatedFP = Functional ProgrammingLambda = Anonymous FunctionDSL = Domain Specific Language
  • 5.
  • 6.
  • 7.
  • 8.
    F# is amix of
  • 9.
    What is F#?F#is multi-paradigm language, that is:FunctionalDeclarativeObject OrientatedImperative.Net language with VS integration
  • 10.
    Running F#Visual Studio2010Visual Studio Shell + F# MonoDevelop on Linux and MacF# Compiler + Emacs etc.In your browser
  • 11.
    FP hits mainstreamVisualStudio gets F#C# gets LINQ, lambdas, etcC++ gets lambdasJVM gets Clojure & Scala
  • 12.
    Writing queries withLINQQuery syntax supported in C# 3.0Functional programming conceptsDeclaratively describes “what” not “how”Written as single expressionvarq=frompindb.Productswherep.UnitPrice>75.0MselectString.Format("{0} - ${1}", p.ProductName, p.UnitPrice);
  • 13.
    Graphical User InterfaceFrameworksXUL (Mozilla), Glade (Gtk), XAML (.NET)Functional programming conceptsCompose button with ellipse insideSpecify behavior declaratively<Buttonx:Name="greenBtn" Background="Black"> <EllipseWidth="75"Height="75" Fill="LightGreen" /></Button><DoubleAnimationStoryboard.TargetName="greenBtn"Storyboard.TargetProperty="(Canvas.Left)" From="0.0"To="100.0"Duration="0:0:5" />
  • 14.
    Specifying financial contractsin F#Functional programming conceptsDeclaratively describes “what” not “how”Written as single expressionComposed from small number of primitivesletmarch day = DateTime(2011, 3, day)letitTrades = (sell (tradeAt(march15) "GOOG"500)) $ (between (march10) (march19) (trade"MSFT"1000))lettradeAtdatewhatamount =between datedate (trade whatamount)
  • 15.
    Code Samples1: //Declare a local value (inferred type is string)2: letworld="world"3: 4: // Using '%s' format specifier to include string parameter5: printfn"Hello %s!"world 
  • 17.
    Functional data structuresAway of thinking about problemsModel data using composition of primitivesTuple Combine two values of different typesDiscriminated Union Represents one of several optionsList Zero or more values of the same type
  • 18.
    Tuples: Containers fora few different things
  • 19.
  • 20.
    Representing event scheduleObject-orientedwayEasy to add new casesHard to add new functionsFunctional wayEasy to add new functionsHard to add new casesGood thing about F# and Scala– you can use both!
  • 21.
  • 22.
    Map ReduceMapReduce isa patented software framework introduced by Google to support distributed computing on large data sets on clusters of computers.Functional design scales extremely well!
  • 23.
  • 24.
    Checkout application workflowThinkof a simple while loopImplement…Mutable field to keep the state and event handlers?Asynchronous while loop in F#
  • 25.
    Asynchronous and concurrentprogrammingAsynchronous GUI in Checkout exampleSingle-threaded thanks to Async.StartImmediateEasy way to encode control flowParallel programmingWorkflows are non-blocking computationsRun workflows in parallel with Async.ParallelConcurrent programmingCompose application from (thousands of) agentsAgents communicate using messages
  • 26.
  • 27.
    SummaryFP is alreadyin the mainstreamFP languages are readyStart small, go bigLanguage Orientated ProgrammingExploratory and ScriptingAsynchronous & ConcurrencyTechnical ComputingTesting
  • 28.
    SummaryDon’t underestimate thepower of the functional side
  • 29.
  • 30.
  • 31.
    On the horizonNextMeet: In the brain of Rob Pickering on March 16th
  • 32.

Editor's Notes

  • #6 Thoughtworkstechnlogy radar: http://www.thoughtworks.com/radar/Image source: http://www.thoughtworks.com/sites/www.thoughtworks.com/files/files/tw-radar-april-2010.pdfSee also: http://qconlondon.com/london-2010/file?path=/qcon-london-2010/slides/AmandaLaucher_and_JoshGraham_TheStateOfTheArtNET12MonthsOfThingsToLearn.pdf
  • #7 http://en.wikipedia.org/wiki/Dynamic_programming_language
  • #8 http://en.wikipedia.org/wiki/Comparison_of_programming_languagesDefinitions of FP, OO and Dynamic
  • #9 Python = light, C# = OO, OCaml = Functional
  • #11 http://tryfsharporg.cloudapp.net/http://trelford.com/MissileCommand.fsx