This document summarizes an introduction to the F# programming language presented at the Houston TechFest 2009. It covers core F# concepts like functional, object-oriented, and language-oriented programming paradigms. It also provides an overview of basic F# syntax, when to use F#, when not to use it, and resources for learning more about F#.
24. Why Consider F#? You can do everything you did in C# within F# Some things are simpler, some harder Simpler: many OO design patterns Simpler: Asynchronous tasks Harder: GUI programming Terrific for specialized tasks (polyglot) Many great F# libraries Terse language = fewer lines of code = $ saved
25. When to use F# Asynchronous operations Concurrent operations Messaging (MailboxProcessor) Transformation operations (like SSIS) Computation-intensive operations (like SSAS) Creating Domain Specific Languages (DSLs) Aspect-Oriented Programming (AOP) Testing
37. When not to use F# Just want to use the newest thing GUI programming You can do it Can’t use the designers Can still be a great tool When you are already proficient in C# and are focused almost entirely on OOP. Stick to what you know. You’ll be faster.
38. Summary “Write tomorrow’s legacy code today with C#” Chris Smith’s F# Facts Try F# Fall in love with F# Use F# The End
39. Resources F# is still CTP Try it in VS2010 Beta 1 Or use the VS2008 CTP installer Read books Foundations of F#(Pickering) Expert F# (Syme) Functional Programming for the Real World (Petricek and Skeet) F# for Scientists (Harrop)
42. Monads Monads are about function composition. Take a monoid:f(x) -> xg(x) -> xf(g(x)) -> x f.g x -> x Add a transformation:f(x) -> Mxg(x) -> Mxf(g(x)) -> Mx f.g x -> Mx
43. Creating Monadic Builders The parts of a monad:(in F#, this would be a workflow builder) x.Let (value, transform): sets a value, like LINQ’s Select(). x.Bind (value, transform): splits the value from the transform and passes it into the next function, like LINQ’s SelectMany(). x.Return (value): returns the result. x.Delay (transform): kicks off the workflow.
44. Computation workflow structure Typical structure of a workflow builder:type WorkflowBuilder () = member x.Bind (value, transform) = transform value member x.Return (value) = fun () -> value member x.Delay (transform) = fun () -> transform ()let workflow = new WorkflowBuilder() Execute like so:let myWorkflow = workflow { let x = 1 // x.Let let! y = 2 // x.Bind return x + y // x.Return }let result = myWorkflow () // x.Delay