SlideShare a Scribd company logo
Practical F#Ryan RileyCatapult Systems, Inc.Houston TechFest 2009
AgendaCore ConceptsBasic SyntaxWhy Consider F#When to use F#When not to use F#Summary
Core Concepts
F# ParadigmsFunctionalObject-orientedLanguage-oriented
Functional Programming ConceptsFirst-Class Functions (and Events)Strong Type InferenceImmutabilityMake side-effects explicit (the M-word)Functional Reactive ProgrammingEasy ConcurrencyActor-model Messaging (similar to Erlang)Lazy Evaluation
Basic Syntax
letSimilar to var in C#.
TuplesType-safe collection of valuesC# out parameters are returned as tuples
Class Declaration
Abstract Classes
Interfaces
Inheritance
RecordsBut then, why bother?
Discriminated UnionsFunctional inheritance
Pattern Matching
Extension Methods
Object Expressions
Control Flow with Pipes
Function Composition
Computation Workflows
QuotationsThis is supposed to be a practical discussion!Quotations are similar to LINQ Expressions.
REPL
Visual Studio Integration
Why Consider F#?You can do everything you did in C# within F#Some things are simpler, some harderSimpler: many OO design patternsSimpler: Asynchronous tasksHarder: GUI programmingTerrific for specialized tasks (polyglot)Many great F# librariesTerse language = fewer lines of code = $ saved
When to use F#Asynchronous operationsConcurrent operationsMessaging (MailboxProcessor)Transformation operations (like SSIS)Computation-intensive operations (like SSAS)Creating Domain Specific Languages (DSLs)Aspect-Oriented Programming (AOP)Testing
FP vs. OOP
#1 Reason to use F#	Your entire application is already just a series of LINQ statements!
TestingFsTestFsUnit
Generate Test Data
Mathematical CalculationsProject Euler Problem 4:Project Euler Problem 3:Project Euler Problem 6
Excel Financial Functions
ParsersFSharp.PowerPack has a lexer and parserFparsecCashel
Automated Builds with Fake
Async Workflows
Async Workflows from C#
Functional AOP?
When not to use F# Just want to use the newest thingGUI programmingYou can do itCan’t use the designersCan still be a great toolWhen you are already proficient in C# and are focused almost entirely on OOP.Stick to what you know. You’ll be faster.
Summary“Write tomorrow’s legacy code today with C#”Chris Smith’s F# FactsTry F#Fall in love with F#Use F#The End
ResourcesF# is still CTPTry it in VS2010 Beta 1Or use the VS2008 CTP installerRead booksFoundations of F#(Pickering)Expert F# (Syme)Functional Programming for the Real World (Petricek and Skeet)F# for Scientists (Harrop)
Resourceshttp://channel9.msdn.com/pdc2008/TL11/http://tomasp.net/blog/fsharp-webcast-functional.aspxhttp://lorgonblog.spaces.live.com/blog/http://codebetter.com/blogs/matthew.podwysocki/default.aspx
The end …
MonadsMonads are about function composition.Take a monoid:f(x) -> xg(x) -> xf(g(x)) -> xf.g x -> xAdd a transformation:f(x) -> Mxg(x) -> Mxf(g(x)) -> Mxf.g x -> Mx
Creating Monadic BuildersThe 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.
Computation workflow structureTypical 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

More Related Content

PDF
F# for Scala developers
PDF
C#(VB)プログラマのためのF#入門
PDF
So you think you can pdb?
PDF
Chatbots are so last decade
PPTX
FSharp eye for the Haskell guy - London 2015
PPTX
F# Tutorial @ QCon
PDF
From Python to Kotlin - TalkingKT 2019
PDF
Perl::Lint - Yet Another Perl Source Code Linter
F# for Scala developers
C#(VB)プログラマのためのF#入門
So you think you can pdb?
Chatbots are so last decade
FSharp eye for the Haskell guy - London 2015
F# Tutorial @ QCon
From Python to Kotlin - TalkingKT 2019
Perl::Lint - Yet Another Perl Source Code Linter

What's hot (20)

PDF
Static analysis for perl
PDF
Arguman
PPTX
Software architecture...Yes, on tests!
PPTX
PDF
Spelunking through JPEG with Racket (Sixth RacketCon)
PPTX
Presentation on python
PDF
Raspberry using Python Session 1
PDF
2011-09-19 Regex Day
PDF
Lets learn Python !
PPTX
Soalan chapter 5
PPTX
Why Python?
PPTX
What is Python? An overview of Python for science.
PPTX
Entity Framework NYC Firestarter
PPTX
Python 101 For The Net Developer
PDF
Non-Blocking Strategies for FFI
PDF
FNT Software Solutions Pvt Ltd Placement Papers - PHP Technologies
PDF
Python for the C# developer
PPTX
Arabic morphology and POS-tagging
PDF
Pythonanditsapplications 161121160425
PDF
Static analysis for perl
Arguman
Software architecture...Yes, on tests!
Spelunking through JPEG with Racket (Sixth RacketCon)
Presentation on python
Raspberry using Python Session 1
2011-09-19 Regex Day
Lets learn Python !
Soalan chapter 5
Why Python?
What is Python? An overview of Python for science.
Entity Framework NYC Firestarter
Python 101 For The Net Developer
Non-Blocking Strategies for FFI
FNT Software Solutions Pvt Ltd Placement Papers - PHP Technologies
Python for the C# developer
Arabic morphology and POS-tagging
Pythonanditsapplications 161121160425
Ad

Viewers also liked (6)

PPTX
SharePoint Saturday Boston 2010
PPTX
F# and functional programming
PPTX
F# on the Web
PPTX
Introduction to F#
PPT
F# Eye for the C# Guy
PPTX
Top 7 mistakes
SharePoint Saturday Boston 2010
F# and functional programming
F# on the Web
Introduction to F#
F# Eye for the C# Guy
Top 7 mistakes
Ad

Similar to Practical F# (20)

PPT
Bay NET Aug 19 2009 presentation ppt
PPTX
What the math geeks don't want you to know about F#
PPTX
Introduction to F#
PDF
Functional Programming in C# and F#
PPTX
.NET and C# introduction
PPT
F# and the DLR
PPT
Visual Studio .NET2010
PPTX
F# for Trading NYC
PPTX
Exploring SharePoint with F#
PPTX
Domain Modeling & Full-Stack Web Development F#
PPTX
"The F# Path to Relaxation", Don Syme
ODP
F# 101
PDF
vpTech - Practical F# in Finance
PPTX
BDD with F# at DDD9
PPTX
Qcon2011 functions rockpresentation_f_sharp
PPTX
Qcon2011 functions rockpresentation_f_sharp
PPTX
.NET 4 Demystified - Sandeep Joshi
PDF
[4DEV] Bartosz Sokół - Functional developer in object oriented world - how F#...
ODP
Progressive f# tutorials nyc rachel reese & phil trelford on try f# from zero...
PPTX
How F# Learned to Stop Worrying and Love the Data
Bay NET Aug 19 2009 presentation ppt
What the math geeks don't want you to know about F#
Introduction to F#
Functional Programming in C# and F#
.NET and C# introduction
F# and the DLR
Visual Studio .NET2010
F# for Trading NYC
Exploring SharePoint with F#
Domain Modeling & Full-Stack Web Development F#
"The F# Path to Relaxation", Don Syme
F# 101
vpTech - Practical F# in Finance
BDD with F# at DDD9
Qcon2011 functions rockpresentation_f_sharp
Qcon2011 functions rockpresentation_f_sharp
.NET 4 Demystified - Sandeep Joshi
[4DEV] Bartosz Sokół - Functional developer in object oriented world - how F#...
Progressive f# tutorials nyc rachel reese & phil trelford on try f# from zero...
How F# Learned to Stop Worrying and Love the Data

More from Ryan Riley (8)

PPTX
A Brief History of OWIN
PPTX
Test first
PPTX
Introduction to F#x
PPTX
The Functional Web
PPTX
Rx workshop
PPTX
Functional Programming
PPTX
HTTP: the Other ESB
PPTX
Domain Driven Design
A Brief History of OWIN
Test first
Introduction to F#x
The Functional Web
Rx workshop
Functional Programming
HTTP: the Other ESB
Domain Driven Design

Recently uploaded (20)

PDF
Network Security Unit 5.pdf for BCA BBA.
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
PDF
NewMind AI Monthly Chronicles - July 2025
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PPTX
A Presentation on Artificial Intelligence
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Unlocking AI with Model Context Protocol (MCP)
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
Modernizing your data center with Dell and AMD
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Network Security Unit 5.pdf for BCA BBA.
Understanding_Digital_Forensics_Presentation.pptx
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
NewMind AI Monthly Chronicles - July 2025
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Review of recent advances in non-invasive hemoglobin estimation
Mobile App Security Testing_ A Comprehensive Guide.pdf
Per capita expenditure prediction using model stacking based on satellite ima...
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
A Presentation on Artificial Intelligence
NewMind AI Weekly Chronicles - August'25 Week I
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Unlocking AI with Model Context Protocol (MCP)
20250228 LYD VKU AI Blended-Learning.pptx
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Dropbox Q2 2025 Financial Results & Investor Presentation
Modernizing your data center with Dell and AMD
Chapter 3 Spatial Domain Image Processing.pdf
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx

Practical F#