SlideShare ist ein Scribd-Unternehmen logo
1 von 22
Downloaden Sie, um offline zu lesen
Get Functional on the CLR:
Intro to Functional Programming with
F#
David Alpert | @davidalpert | http://about.me/davidalpert
Learning Goals
• Disambiguate functional programming
• Demystify F# and F# syntax
• Demonstrate .NET interoperability
• Experiment with F# syntax
• Create a new F# library project
• Write basic functions and data structures in F#
• Call F# from C#
So that you will be able to:
Put yourself in “I have no idea
what I’m doing” situations more
often. Your growth will be
exponential. - @derekbailey
https://twitter.com/derickbailey/status/452832022860292096
Woody Zuill
“Question Everything – put
special focus on our deepest
held beliefs. What we trust most
hides our biggest problems.”
Agile Maxim #2
http://zuill.us/WoodyZuill/2012/09/16/the-8-agile-maxims-of-woody-zuill/
We are addicted to complexity
We are addicted to
complexity
We are addicted to accidental
complexity
We are addicted to
accidental complexity
We are addicted to manipulating
state
We are addicted to
manipulating state
#noManipulatingState is like
#noDefects or #NoEstimates
#noManipulatingState
is like
#noDefects
or
#noEstimates
What is Functional Programming?
It is programming... with functions!
• Pure – Referentially Transparent
• First Class and Higher-Order functions
• Partial application & Currying
What is Functional Programming?
(function ($) {
$(document).ready(function () {
$('dt').click(function (ev) {
// do something interesting
});
function doSomethingElse(ev) {
// something else again
}
$('a').click(doSomethingElse);
});
})(jQuery);
Func<int, bool> isEven = x => x%2 == 0;
public static MvcHtmlString LabelFor<TModel, TValue>(
this HtmlHelper<TModel> html,
Expression<Func<TModel, TValue>> expression)
{
// ...
}
var someString = @Html.TextBoxFor(model => model.Rating)
Why F#?
• Concise
• Convenient
• Correctness
• Concurrency
• Complete
Concise
Convenient
Correctness
Concurrency
Complete
The “Billion Dollar Mistake”
http://www.infoq.com/presentations/Null-References-The-Billion-Dollar-Mistake-Tony-Hoare
Sir Charles Antony Richard Hoare, commonly
known as Tony Hoare, is a British computer
scientist, probably best known for the
development in 1960, at age 26, of Quicksort.
He also developed Hoare logic, the formal
language Communicating Sequential Processes
(CSP), and inspired the Occam programming
language.
Tony Hoare introduced Null references in
ALGOL W back in 1965 “simply because it was
so easy to implement”, says Mr. Hoare. He talks
about that decision considering it “my billion-
dollar mistake”.
We are addicted to accidental
complexity
We are addicted to
accidental complexity
From C# syntax to F# syntax
C# F#
Curly braces denote scope Indentation (i.e. Whitespace) denotes scope
Brackets and commas in argument list No brackets or commas
// single line comment // single line comment
/* multi-line comment */ (* multi-line comment *)
Explicit return Implicit return (value of the last expression)
public int Add(int x, int y)
{
return x + y;
}
let add x y = x + y
IEnumerable<T> seq<‘T>
IList<T> ‘T list
Null None ( an Option value)
Some more F# syntax
Description Syntax Evaluates to
Declare a list (of int) [2; 3; 4] int list = [2; 3; 4]
Prepend to a list 1 :: [2; 3; 4] int list = [1; 2; 3; 4]
Contact two lists [0; 1] @ [2; 3; 4] int list = [0; 1; 2; 3; 4]
Declare a tuple of int (1, 2, 3) int * int * int = (1, 2, 3)
Declare an optional value let x = Some(1) val x : int option = Some 1
Declare a ‘null’ value Let z = None val z : 'a option
Pipe a list into a function
(like Linq’s Select)
[1; 2; 3]
|> (fun x -> x ^ 2) int list = [1; 4; 9]
Functional Type Notation
let add1 x = x + 1 int -> int
let add x y = x + y int -> int -> int
Basic List Functions
List.filter : ('T -> bool) -> 'T list -> 'T list
List.map : ('T -> 'U) -> 'T list -> 'U list
List.fold : ('State -> 'T -> 'State) -> 'State -> 'T list -> 'State
predicate items result
projection items result
accumulator items final
state
initial
state
+ new item = final
state
initial
state
Basic List Functions
predicateitemsresult
projectionitemsresult
items
final
state initial
state
accumulator
+ new item = final
state
initial
state
public static IEnumerable<TSource> Where<TSource>( this IEnumerable<TSource> source, Func<TSource, bool> predicate )
public static IEnumerable<TResult> Select<TSource, TResult>( this IEnumerable<TSource> source, Func<TSource, TResult> selector )
public static TAccumulate Aggregate<TSource, TAccumulate>( this IEnumerable<TSource> source,
TAccumulate seed,
Func<TAccumulate, TSource, TAccumulate> func )
Demo: Rapid Prototyping with FSI
• Rapid prototyping with the FSI REPL
and the F# Interactive Window
Demo:
Rapid Prototyping w/ FSI REPL
& the F# Interactive window
Demo: File -> New F# Project
• Create a new F# library project
• Create a new C# library project w/ Nunit
• Add references and test F# code from C#Demo:
File -> New F# Project
Demo: Other goodies
• Parsing with FParsec
(a parser-combinator approach)
• Strongly-typed Units of Measure
• Domain Modelling (i.e. Lightweight DDD)
• Automated browser testing with Canopy
Demo:
Other F# goodies
References & Resources
Get Functional on the CLR:
Intro to Functional Programming with
F#
David Alpert | @davidalpert | http://about.me/davidalpert
Reference
• http://en.wikipedia.org/wiki/Functional_programming
• http://fsharpforfunandprofit.com/why-use-fsharp/
• http://www.infoq.com/presentations/Null-References-The-Billion-Dollar-Mistake-Tony-Hoare
• http://www.tryfsharp.org/Create
• http://fsharpforfunandprofit.com/posts/fsharp-in-60-seconds/
• http://lostechies.com/jimmybogard/2008/08/12/enumeration-classes/
• http://research.microsoft.com/en-us/um/cambridge/projects/fsharp/manual/fsharp-component-design-
guidelines.pdf [ Component design guidelines ]
• http://visualstudiogallery.msdn.microsoft.com/07636c36-52be-4dce-9f2e-3c56b8329e33 [ depth colorizer ]
Examples
• http://www.quanttec.com/fparsec/ [ A parser-combinator library ]
• https://github.com/davidalpert/furlstrong [ F# based url parsing with FParsec ]
• http://nuggle.me/ [ DC Circuits in F# ]
• http://blogs.msdn.com/b/andrewkennedy/archive/2008/08/29/units-of-measure-in-f-part-one-introducing-
units.aspx [ Custom units of measure in F# ]
• http://www.slideshare.net/ScottWlaschin/ddd-with-fsharptypesystemlondonndc2013 [ DDD & F# Types ]
• http://lefthandedgoat.github.io/canopy/ [ Browser automation DSL with F# ]

Weitere ähnliche Inhalte

Was ist angesagt?

Pipeline oriented programming
Pipeline oriented programmingPipeline oriented programming
Pipeline oriented programmingScott Wlaschin
 
仕事で使うF#
仕事で使うF#仕事で使うF#
仕事で使うF#bleis tift
 
Chapter 1 Basic Programming (Python Programming Lecture)
Chapter 1 Basic Programming (Python Programming Lecture)Chapter 1 Basic Programming (Python Programming Lecture)
Chapter 1 Basic Programming (Python Programming Lecture)IoT Code Lab
 
Advance python programming
Advance python programming Advance python programming
Advance python programming Jagdish Chavan
 
Python-02| Input, Output & Import
Python-02| Input, Output & ImportPython-02| Input, Output & Import
Python-02| Input, Output & ImportMohd Sajjad
 
F# Presentation
F# PresentationF# Presentation
F# Presentationmrkurt
 
46630497 fun-pointer-1
46630497 fun-pointer-146630497 fun-pointer-1
46630497 fun-pointer-1AmIt Prasad
 
CS4200 2019 | Lecture 2 | syntax-definition
CS4200 2019 | Lecture 2 | syntax-definitionCS4200 2019 | Lecture 2 | syntax-definition
CS4200 2019 | Lecture 2 | syntax-definitionEelco Visser
 
Python quickstart for programmers: Python Kung Fu
Python quickstart for programmers: Python Kung FuPython quickstart for programmers: Python Kung Fu
Python quickstart for programmers: Python Kung Fuclimatewarrior
 
F# Eye 4 the C# Guy - DDD Cambridge Nights 2014
F# Eye 4 the C# Guy -  DDD Cambridge Nights 2014F# Eye 4 the C# Guy -  DDD Cambridge Nights 2014
F# Eye 4 the C# Guy - DDD Cambridge Nights 2014Phillip Trelford
 
Python Programming Essentials - M16 - Control Flow Statements and Loops
Python Programming Essentials - M16 - Control Flow Statements and LoopsPython Programming Essentials - M16 - Control Flow Statements and Loops
Python Programming Essentials - M16 - Control Flow Statements and LoopsP3 InfoTech Solutions Pvt. Ltd.
 
Python unit 2 as per Anna university syllabus
Python unit 2 as per Anna university syllabusPython unit 2 as per Anna university syllabus
Python unit 2 as per Anna university syllabusDhivyaSubramaniyam
 
Write Your Own Compiler in 24 Hours
Write Your Own Compiler in 24 HoursWrite Your Own Compiler in 24 Hours
Write Your Own Compiler in 24 HoursPhillip Trelford
 
Python programming Workshop SITTTR - Kalamassery
Python programming Workshop SITTTR - KalamasseryPython programming Workshop SITTTR - Kalamassery
Python programming Workshop SITTTR - KalamasserySHAMJITH KM
 
GE8151 Problem Solving and Python Programming
GE8151 Problem Solving and Python ProgrammingGE8151 Problem Solving and Python Programming
GE8151 Problem Solving and Python ProgrammingMuthu Vinayagam
 
Chapter 2 Decision Making (Python Programming Lecture)
Chapter 2 Decision Making (Python Programming Lecture)Chapter 2 Decision Making (Python Programming Lecture)
Chapter 2 Decision Making (Python Programming Lecture)IoT Code Lab
 

Was ist angesagt? (20)

Rx workshop
Rx workshopRx workshop
Rx workshop
 
Pipeline oriented programming
Pipeline oriented programmingPipeline oriented programming
Pipeline oriented programming
 
仕事で使うF#
仕事で使うF#仕事で使うF#
仕事で使うF#
 
Chapter 1 Basic Programming (Python Programming Lecture)
Chapter 1 Basic Programming (Python Programming Lecture)Chapter 1 Basic Programming (Python Programming Lecture)
Chapter 1 Basic Programming (Python Programming Lecture)
 
Advance python programming
Advance python programming Advance python programming
Advance python programming
 
Python-02| Input, Output & Import
Python-02| Input, Output & ImportPython-02| Input, Output & Import
Python-02| Input, Output & Import
 
Time for Functions
Time for FunctionsTime for Functions
Time for Functions
 
F# Presentation
F# PresentationF# Presentation
F# Presentation
 
46630497 fun-pointer-1
46630497 fun-pointer-146630497 fun-pointer-1
46630497 fun-pointer-1
 
CS4200 2019 | Lecture 2 | syntax-definition
CS4200 2019 | Lecture 2 | syntax-definitionCS4200 2019 | Lecture 2 | syntax-definition
CS4200 2019 | Lecture 2 | syntax-definition
 
Python quickstart for programmers: Python Kung Fu
Python quickstart for programmers: Python Kung FuPython quickstart for programmers: Python Kung Fu
Python quickstart for programmers: Python Kung Fu
 
F# Eye 4 the C# Guy - DDD Cambridge Nights 2014
F# Eye 4 the C# Guy -  DDD Cambridge Nights 2014F# Eye 4 the C# Guy -  DDD Cambridge Nights 2014
F# Eye 4 the C# Guy - DDD Cambridge Nights 2014
 
Python Programming Essentials - M16 - Control Flow Statements and Loops
Python Programming Essentials - M16 - Control Flow Statements and LoopsPython Programming Essentials - M16 - Control Flow Statements and Loops
Python Programming Essentials - M16 - Control Flow Statements and Loops
 
Unit2 input output
Unit2 input outputUnit2 input output
Unit2 input output
 
Python unit 2 as per Anna university syllabus
Python unit 2 as per Anna university syllabusPython unit 2 as per Anna university syllabus
Python unit 2 as per Anna university syllabus
 
Write Your Own Compiler in 24 Hours
Write Your Own Compiler in 24 HoursWrite Your Own Compiler in 24 Hours
Write Your Own Compiler in 24 Hours
 
Python programming Workshop SITTTR - Kalamassery
Python programming Workshop SITTTR - KalamasseryPython programming Workshop SITTTR - Kalamassery
Python programming Workshop SITTTR - Kalamassery
 
Python Programming Essentials - M17 - Functions
Python Programming Essentials - M17 - FunctionsPython Programming Essentials - M17 - Functions
Python Programming Essentials - M17 - Functions
 
GE8151 Problem Solving and Python Programming
GE8151 Problem Solving and Python ProgrammingGE8151 Problem Solving and Python Programming
GE8151 Problem Solving and Python Programming
 
Chapter 2 Decision Making (Python Programming Lecture)
Chapter 2 Decision Making (Python Programming Lecture)Chapter 2 Decision Making (Python Programming Lecture)
Chapter 2 Decision Making (Python Programming Lecture)
 

Andere mochten auch

Functional programming ruby mty
Functional programming   ruby mtyFunctional programming   ruby mty
Functional programming ruby mtyAdrianGzz2112
 
The Rise of Functional Programming
The Rise of Functional ProgrammingThe Rise of Functional Programming
The Rise of Functional ProgrammingTjerk Wolterink
 
JavaScript Unit Testing
JavaScript Unit TestingJavaScript Unit Testing
JavaScript Unit TestingShabnamShahfar
 
Eclipse Day India 2015 - Keynote - Stephan Herrmann
Eclipse Day India 2015 - Keynote - Stephan HerrmannEclipse Day India 2015 - Keynote - Stephan Herrmann
Eclipse Day India 2015 - Keynote - Stephan HerrmannEclipse Day India
 
Get Ready for Agile Methods: How to manage constant and rapid change in IT pr...
Get Ready for Agile Methods: How to manage constant and rapid change in IT pr...Get Ready for Agile Methods: How to manage constant and rapid change in IT pr...
Get Ready for Agile Methods: How to manage constant and rapid change in IT pr...Dimitris Dranidis
 
No silver bullet essence and accidents of software engineering
No silver bullet essence and accidents of software engineeringNo silver bullet essence and accidents of software engineering
No silver bullet essence and accidents of software engineeringArun Banotra
 
C# Async on iOS and Android - Miguel de Icaza, CTO of Xamarin
C# Async on iOS and Android - Miguel de Icaza, CTO of XamarinC# Async on iOS and Android - Miguel de Icaza, CTO of Xamarin
C# Async on iOS and Android - Miguel de Icaza, CTO of XamarinXamarin
 
Swift and Kotlin Presentation
Swift and Kotlin PresentationSwift and Kotlin Presentation
Swift and Kotlin PresentationAndrzej Sitek
 
An Empirical Study of Goto in C Code from GitHub Repositories
An Empirical Study of Goto in C Code from GitHub RepositoriesAn Empirical Study of Goto in C Code from GitHub Repositories
An Empirical Study of Goto in C Code from GitHub RepositoriesSAIL_QU
 
Software reliability engineering
Software reliability engineeringSoftware reliability engineering
Software reliability engineeringMark Turner CRP
 
Chapter 7 software reliability
Chapter 7 software reliabilityChapter 7 software reliability
Chapter 7 software reliabilitydespicable me
 
Agile Is the New Waterfall
Agile Is the New WaterfallAgile Is the New Waterfall
Agile Is the New WaterfallNaresh Jain
 

Andere mochten auch (14)

Functional programming ruby mty
Functional programming   ruby mtyFunctional programming   ruby mty
Functional programming ruby mty
 
The Rise of Functional Programming
The Rise of Functional ProgrammingThe Rise of Functional Programming
The Rise of Functional Programming
 
JavaScript Unit Testing
JavaScript Unit TestingJavaScript Unit Testing
JavaScript Unit Testing
 
Eclipse Day India 2015 - Keynote - Stephan Herrmann
Eclipse Day India 2015 - Keynote - Stephan HerrmannEclipse Day India 2015 - Keynote - Stephan Herrmann
Eclipse Day India 2015 - Keynote - Stephan Herrmann
 
Get Ready for Agile Methods: How to manage constant and rapid change in IT pr...
Get Ready for Agile Methods: How to manage constant and rapid change in IT pr...Get Ready for Agile Methods: How to manage constant and rapid change in IT pr...
Get Ready for Agile Methods: How to manage constant and rapid change in IT pr...
 
No silver bullet essence and accidents of software engineering
No silver bullet essence and accidents of software engineeringNo silver bullet essence and accidents of software engineering
No silver bullet essence and accidents of software engineering
 
No silver bullet
No silver bulletNo silver bullet
No silver bullet
 
C# Async on iOS and Android - Miguel de Icaza, CTO of Xamarin
C# Async on iOS and Android - Miguel de Icaza, CTO of XamarinC# Async on iOS and Android - Miguel de Icaza, CTO of Xamarin
C# Async on iOS and Android - Miguel de Icaza, CTO of Xamarin
 
Swift and Kotlin Presentation
Swift and Kotlin PresentationSwift and Kotlin Presentation
Swift and Kotlin Presentation
 
An Empirical Study of Goto in C Code from GitHub Repositories
An Empirical Study of Goto in C Code from GitHub RepositoriesAn Empirical Study of Goto in C Code from GitHub Repositories
An Empirical Study of Goto in C Code from GitHub Repositories
 
Software reliability engineering
Software reliability engineeringSoftware reliability engineering
Software reliability engineering
 
Chapter 7 software reliability
Chapter 7 software reliabilityChapter 7 software reliability
Chapter 7 software reliability
 
Agile Is the New Waterfall
Agile Is the New WaterfallAgile Is the New Waterfall
Agile Is the New Waterfall
 
Kotlin
KotlinKotlin
Kotlin
 

Ähnlich wie Get Functional on the CLR: Intro to Functional Programming with F#

F# for C# devs - NDC Oslo 2015
F# for C# devs - NDC Oslo 2015F# for C# devs - NDC Oslo 2015
F# for C# devs - NDC Oslo 2015Phillip Trelford
 
devLink - What's New in C# 4?
devLink - What's New in C# 4?devLink - What's New in C# 4?
devLink - What's New in C# 4?Kevin Pilch
 
F# for C# devs - Leeds Sharp 2015
F# for C# devs -  Leeds Sharp 2015F# for C# devs -  Leeds Sharp 2015
F# for C# devs - Leeds Sharp 2015Phillip Trelford
 
Improve Your Edge on Machine Learning - Day 1.pptx
Improve Your Edge on Machine Learning - Day 1.pptxImprove Your Edge on Machine Learning - Day 1.pptx
Improve Your Edge on Machine Learning - Day 1.pptxCatherineVania1
 
Introduction to TensorFlow 2.0
Introduction to TensorFlow 2.0Introduction to TensorFlow 2.0
Introduction to TensorFlow 2.0Databricks
 
So I am writing a CS code for a project and I keep getting cannot .pdf
So I am writing a CS code for a project and I keep getting cannot .pdfSo I am writing a CS code for a project and I keep getting cannot .pdf
So I am writing a CS code for a project and I keep getting cannot .pdfezonesolutions
 
Whats New In C# 4 0 - NetPonto
Whats New In C# 4 0 - NetPontoWhats New In C# 4 0 - NetPonto
Whats New In C# 4 0 - NetPontoPaulo Morgado
 
Testing for share
Testing for share Testing for share
Testing for share Rajeev Mehta
 
C++ Interview Question And Answer
C++ Interview Question And AnswerC++ Interview Question And Answer
C++ Interview Question And AnswerJagan Mohan Bishoyi
 
C++ questions And Answer
C++ questions And AnswerC++ questions And Answer
C++ questions And Answerlavparmar007
 
Running Head Discussion Board .docx
Running Head Discussion Board                                  .docxRunning Head Discussion Board                                  .docx
Running Head Discussion Board .docxjeanettehully
 
FUNDAMENTALS OF PYTHON LANGUAGE
 FUNDAMENTALS OF PYTHON LANGUAGE  FUNDAMENTALS OF PYTHON LANGUAGE
FUNDAMENTALS OF PYTHON LANGUAGE Saraswathi Murugan
 
Functional programming with FSharp
Functional programming with FSharpFunctional programming with FSharp
Functional programming with FSharpDaniele Pozzobon
 

Ähnlich wie Get Functional on the CLR: Intro to Functional Programming with F# (20)

F# for C# devs - NDC Oslo 2015
F# for C# devs - NDC Oslo 2015F# for C# devs - NDC Oslo 2015
F# for C# devs - NDC Oslo 2015
 
devLink - What's New in C# 4?
devLink - What's New in C# 4?devLink - What's New in C# 4?
devLink - What's New in C# 4?
 
Lesson11
Lesson11Lesson11
Lesson11
 
F# for C# devs - Leeds Sharp 2015
F# for C# devs -  Leeds Sharp 2015F# for C# devs -  Leeds Sharp 2015
F# for C# devs - Leeds Sharp 2015
 
Improve Your Edge on Machine Learning - Day 1.pptx
Improve Your Edge on Machine Learning - Day 1.pptxImprove Your Edge on Machine Learning - Day 1.pptx
Improve Your Edge on Machine Learning - Day 1.pptx
 
F# for C# devs - SDD 2015
F# for C# devs - SDD 2015F# for C# devs - SDD 2015
F# for C# devs - SDD 2015
 
Introduction to TensorFlow 2.0
Introduction to TensorFlow 2.0Introduction to TensorFlow 2.0
Introduction to TensorFlow 2.0
 
So I am writing a CS code for a project and I keep getting cannot .pdf
So I am writing a CS code for a project and I keep getting cannot .pdfSo I am writing a CS code for a project and I keep getting cannot .pdf
So I am writing a CS code for a project and I keep getting cannot .pdf
 
Whats New In C# 4 0 - NetPonto
Whats New In C# 4 0 - NetPontoWhats New In C# 4 0 - NetPonto
Whats New In C# 4 0 - NetPonto
 
Testing for share
Testing for share Testing for share
Testing for share
 
C++ Interview Question And Answer
C++ Interview Question And AnswerC++ Interview Question And Answer
C++ Interview Question And Answer
 
C++ questions And Answer
C++ questions And AnswerC++ questions And Answer
C++ questions And Answer
 
Running Head Discussion Board .docx
Running Head Discussion Board                                  .docxRunning Head Discussion Board                                  .docx
Running Head Discussion Board .docx
 
Pythonppt28 11-18
Pythonppt28 11-18Pythonppt28 11-18
Pythonppt28 11-18
 
FUNDAMENTALS OF PYTHON LANGUAGE
 FUNDAMENTALS OF PYTHON LANGUAGE  FUNDAMENTALS OF PYTHON LANGUAGE
FUNDAMENTALS OF PYTHON LANGUAGE
 
C tutorial
C tutorialC tutorial
C tutorial
 
C tutorial
C tutorialC tutorial
C tutorial
 
C tutorial
C tutorialC tutorial
C tutorial
 
Python basic
Python basicPython basic
Python basic
 
Functional programming with FSharp
Functional programming with FSharpFunctional programming with FSharp
Functional programming with FSharp
 

Kürzlich hochgeladen

Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DaySri Ambati
 

Kürzlich hochgeladen (20)

Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
 

Get Functional on the CLR: Intro to Functional Programming with F#

  • 1. Get Functional on the CLR: Intro to Functional Programming with F# David Alpert | @davidalpert | http://about.me/davidalpert
  • 2. Learning Goals • Disambiguate functional programming • Demystify F# and F# syntax • Demonstrate .NET interoperability • Experiment with F# syntax • Create a new F# library project • Write basic functions and data structures in F# • Call F# from C# So that you will be able to:
  • 3. Put yourself in “I have no idea what I’m doing” situations more often. Your growth will be exponential. - @derekbailey https://twitter.com/derickbailey/status/452832022860292096
  • 4. Woody Zuill “Question Everything – put special focus on our deepest held beliefs. What we trust most hides our biggest problems.” Agile Maxim #2 http://zuill.us/WoodyZuill/2012/09/16/the-8-agile-maxims-of-woody-zuill/
  • 5. We are addicted to complexity We are addicted to complexity
  • 6. We are addicted to accidental complexity We are addicted to accidental complexity
  • 7. We are addicted to manipulating state We are addicted to manipulating state
  • 8. #noManipulatingState is like #noDefects or #NoEstimates #noManipulatingState is like #noDefects or #noEstimates
  • 9. What is Functional Programming? It is programming... with functions! • Pure – Referentially Transparent • First Class and Higher-Order functions • Partial application & Currying
  • 10. What is Functional Programming? (function ($) { $(document).ready(function () { $('dt').click(function (ev) { // do something interesting }); function doSomethingElse(ev) { // something else again } $('a').click(doSomethingElse); }); })(jQuery); Func<int, bool> isEven = x => x%2 == 0; public static MvcHtmlString LabelFor<TModel, TValue>( this HtmlHelper<TModel> html, Expression<Func<TModel, TValue>> expression) { // ... } var someString = @Html.TextBoxFor(model => model.Rating)
  • 11. Why F#? • Concise • Convenient • Correctness • Concurrency • Complete Concise Convenient Correctness Concurrency Complete
  • 12. The “Billion Dollar Mistake” http://www.infoq.com/presentations/Null-References-The-Billion-Dollar-Mistake-Tony-Hoare Sir Charles Antony Richard Hoare, commonly known as Tony Hoare, is a British computer scientist, probably best known for the development in 1960, at age 26, of Quicksort. He also developed Hoare logic, the formal language Communicating Sequential Processes (CSP), and inspired the Occam programming language. Tony Hoare introduced Null references in ALGOL W back in 1965 “simply because it was so easy to implement”, says Mr. Hoare. He talks about that decision considering it “my billion- dollar mistake”.
  • 13. We are addicted to accidental complexity We are addicted to accidental complexity
  • 14. From C# syntax to F# syntax C# F# Curly braces denote scope Indentation (i.e. Whitespace) denotes scope Brackets and commas in argument list No brackets or commas // single line comment // single line comment /* multi-line comment */ (* multi-line comment *) Explicit return Implicit return (value of the last expression) public int Add(int x, int y) { return x + y; } let add x y = x + y IEnumerable<T> seq<‘T> IList<T> ‘T list Null None ( an Option value)
  • 15. Some more F# syntax Description Syntax Evaluates to Declare a list (of int) [2; 3; 4] int list = [2; 3; 4] Prepend to a list 1 :: [2; 3; 4] int list = [1; 2; 3; 4] Contact two lists [0; 1] @ [2; 3; 4] int list = [0; 1; 2; 3; 4] Declare a tuple of int (1, 2, 3) int * int * int = (1, 2, 3) Declare an optional value let x = Some(1) val x : int option = Some 1 Declare a ‘null’ value Let z = None val z : 'a option Pipe a list into a function (like Linq’s Select) [1; 2; 3] |> (fun x -> x ^ 2) int list = [1; 4; 9]
  • 16. Functional Type Notation let add1 x = x + 1 int -> int let add x y = x + y int -> int -> int
  • 17. Basic List Functions List.filter : ('T -> bool) -> 'T list -> 'T list List.map : ('T -> 'U) -> 'T list -> 'U list List.fold : ('State -> 'T -> 'State) -> 'State -> 'T list -> 'State predicate items result projection items result accumulator items final state initial state + new item = final state initial state
  • 18. Basic List Functions predicateitemsresult projectionitemsresult items final state initial state accumulator + new item = final state initial state public static IEnumerable<TSource> Where<TSource>( this IEnumerable<TSource> source, Func<TSource, bool> predicate ) public static IEnumerable<TResult> Select<TSource, TResult>( this IEnumerable<TSource> source, Func<TSource, TResult> selector ) public static TAccumulate Aggregate<TSource, TAccumulate>( this IEnumerable<TSource> source, TAccumulate seed, Func<TAccumulate, TSource, TAccumulate> func )
  • 19. Demo: Rapid Prototyping with FSI • Rapid prototyping with the FSI REPL and the F# Interactive Window Demo: Rapid Prototyping w/ FSI REPL & the F# Interactive window
  • 20. Demo: File -> New F# Project • Create a new F# library project • Create a new C# library project w/ Nunit • Add references and test F# code from C#Demo: File -> New F# Project
  • 21. Demo: Other goodies • Parsing with FParsec (a parser-combinator approach) • Strongly-typed Units of Measure • Domain Modelling (i.e. Lightweight DDD) • Automated browser testing with Canopy Demo: Other F# goodies
  • 22. References & Resources Get Functional on the CLR: Intro to Functional Programming with F# David Alpert | @davidalpert | http://about.me/davidalpert Reference • http://en.wikipedia.org/wiki/Functional_programming • http://fsharpforfunandprofit.com/why-use-fsharp/ • http://www.infoq.com/presentations/Null-References-The-Billion-Dollar-Mistake-Tony-Hoare • http://www.tryfsharp.org/Create • http://fsharpforfunandprofit.com/posts/fsharp-in-60-seconds/ • http://lostechies.com/jimmybogard/2008/08/12/enumeration-classes/ • http://research.microsoft.com/en-us/um/cambridge/projects/fsharp/manual/fsharp-component-design- guidelines.pdf [ Component design guidelines ] • http://visualstudiogallery.msdn.microsoft.com/07636c36-52be-4dce-9f2e-3c56b8329e33 [ depth colorizer ] Examples • http://www.quanttec.com/fparsec/ [ A parser-combinator library ] • https://github.com/davidalpert/furlstrong [ F# based url parsing with FParsec ] • http://nuggle.me/ [ DC Circuits in F# ] • http://blogs.msdn.com/b/andrewkennedy/archive/2008/08/29/units-of-measure-in-f-part-one-introducing- units.aspx [ Custom units of measure in F# ] • http://www.slideshare.net/ScottWlaschin/ddd-with-fsharptypesystemlondonndc2013 [ DDD & F# Types ] • http://lefthandedgoat.github.io/canopy/ [ Browser automation DSL with F# ]