SlideShare une entreprise Scribd logo
1  sur  33
Télécharger pour lire hors ligne
MADRID F# MEETUP 
Introduction to F#
MADRID F# MEETUP 
About me 
Alfonso García-Caro 
Independent Developer 
Studied IT but got degree in Linguistics 
Japanese speaker 
.NET fanboy 
Started F# recently 
More pragmatic than theoretical 
@alfonsogcnunez 
github.com/alfonsogarciacaro
MADRID F# MEETUP 
About this talk 
Not official nor comprehensive 
Mostly based in personal experience 
Not an introduction to functional programming 
Please ask if you need more detail 
Will “borrow” from other F#ers 
Particularly @ScottWlaschin 
fsharp.org 
fsharpforfunandprofit.com
MADRID F# MEETUP 
What is F#? 
F# is an open source, cross-platform, 
strongly-typed, functional-first 
programming language. It offers 
interoperability with all .NET languages 
and libraries and data-rich analytical 
services like type providers and LINQ 
queries.
FunScript 
F# to JavaScript with type providers MADRID F# MEETUP
MADRID F# MEETUP 
F# is... robust 
Its powerful type system prevents many 
common errors (null references) and allows you 
to encode business logic to make illegal states 
unrepresentable. 
Yaron minsky via 
fsharpforfunandprofit.com
MADRID F# MEETUP Model Problem: A contact must have 
an email or a postal address 
Naïve solution 
Solution with 
union types
MADRID F# MEETUP 
F# types: Tuples 
• No explicit names 
• Can have any number of components 
• Components can be generic o complex types 
• Most often used to return multiple values from private functions
MADRID F# MEETUP 
F# types: Records 
• Like tuples with labels 
• Structural equality by default 
• Can have members
MADRID F# MEETUP 
F# types: Discriminated Unions 
• Mostly used with pattern matching 
• Can be recursive 
• Can have field names (tuple labels) 
• Empty cases possible 
• Option union instead of null
MADRID F# MEETUP 
F# types: Discriminated Unions 
Construction 
Pattern matching: 
Check case and 
deconstruct all-in-one
MADRID F# MEETUP 
F# types: unit 
• No void functions 
• Single value: () 
• Automatically ignored 
F# types: Abbreviations 
Use an alias for convenience (no type-safe) 
These ones are built-in
MADRID F# MEETUP 
F# types: Collections 
Many built-in functions 
to deal with sequences: 
map, reduce, fold, find... 
• Immutable 
oRecursive lists 
oSet and maps 
oLazy sequences 
• Mutable 
oArray 
oBuilt-in .NET collections: Lists, Dictionaries... 
• Also ranges and comprehensions 
All collections 
are generic
MADRID F# MEETUP 
F# types: Built-in .NET Types 
• Built-in value types: int, bool... 
• Built-in reference types: string... 
• User-defined value types: enum and struct 
• Classes and interfaces 
• Delegates 
Not the same as 
F# functions but 
they can be converted Also pointers, but they 
are not usually needed
FunScript 
F# to JavaScript with type providers MADRID F# MEETUP 
YOU SAY STATIC TYPING 
I HEAR BOILERPLATE
MADRID F# MEETUP 
F# is... agile 
Type inference reduces the number of type 
annotations, bringing together the benefits of static 
typing and the conciseness of dynamic typing. C# 
F#
MADRID F# MEETUP 
F# reduces code “noise” 
But you can use them 
• No curly braces for scope 
• No semicolons 
• Meaningful whitespace like Python 
• No return keyword 
if necessary 
C# 
F# 
Forward pipe operator
MADRID F# MEETUP 
Pattern Matching 
Match and deconstruct complex patterns with no hassle 
Wildcard 
Constant 
Empty 
list 
Guard 
The compiler 
warns you if 
you don’t cover 
all cases
MADRID F# MEETUP 
Pattern Matching 
Define your own active patterns 
Syntactic 
sugar
MADRID F# MEETUP 
Thinking sequentially (1) 
Use computation expressions (aka monads) to simplify 
complex programming workflows and simulate state machines 
Perform 
asynchronous 
operations 
as if 
they were 
synchronous
MADRID F# MEETUP 
Thinking sequentially (2) 
Define your own workflows easily 
Can return Some(value) 
or None 
... and without 
With...
MADRID F# MEETUP 
Thinking sequentially (and 3) 
Parallelism made easy thanks to immutability and Async 
Erlang-like agents 
also available 
Parallel I/O 
Parallel CPU
MADRID F# MEETUP 
Domain Driven Design 
Programmers and non-programmers can 
Believe it! 
speak the same language
MADRID F# MEETUP 
Source
MADRID F# MEETUP 
Scripting 
With F# you can write both complex project 
and simple scripts 
There is a REPL too
FunScript 
F# to JavaScript with type providers MADRID F# MEETUP 
I 
ALREADY 
KNEW 
ALL 
THAT
MADRID F# MEETUP 
Killer Features: Measure Units 
Protect your number values for free! 
Combine them with other types 
Use generics 
The measure annotations 
disappear after compilation so 
they have no performance penalty 
The compiler prevents mistakes
FunScript 
F# to JavaScript with type providers MADRID F# MEETUP 
There are more 
killer features 
but let’s go 
directly to 
the crown jewel
MADRID F# MEETUP 
Killer Features: Type Providers 
Static typing on demand! 
Fsharp.Data 
Sergey Tihon’s blog
FunScript 
F# to JavaScript with type providers MADRID F# MEETUP 
I WANT NO 
ACADEMIC STUFF 
I WANNA MAKE REAL APPS!
MADRID F# MEETUP 
F# is multiplatform 
• .NET: Windows Desktop and Store, Windows Phone 
• Mono: Mac and Linux 
• Xamarin: Android and iOS 
• ASP.NET: Server 
• FunScript and WebSharper: Browser 
• GPU, FreeBSD... 
more at fsharp.org
FunScript 
F# to JavaScript with type providers MADRID F# MEETUP 
DEMO TIME
MADRID F# MEETUP 
Why F#? Why now? 
• Functional programming is booming 
• Great community, really open to newcomers 
• Everybody can contribute to the evolution of the 
language 
• Open source but backed by big companies 
oMicrosoft 
oXamarin 
• fun is a keyword!

Contenu connexe

Tendances

C programmimng basic.ppt
C programmimng basic.pptC programmimng basic.ppt
C programmimng basic.pptASIT Education
 
Introduction of c programming unit-ii ppt
Introduction of  c programming unit-ii pptIntroduction of  c programming unit-ii ppt
Introduction of c programming unit-ii pptJStalinAsstProfessor
 
Programming in C- Introduction
Programming in C- IntroductionProgramming in C- Introduction
Programming in C- Introductionsavitamhaske
 
Learning c - An extensive guide to learn the C Language
Learning c - An extensive guide to learn the C LanguageLearning c - An extensive guide to learn the C Language
Learning c - An extensive guide to learn the C LanguageAbhishek Dwivedi
 
C# programming datatypes
C# programming  datatypesC# programming  datatypes
C# programming datatypes성진 원
 
C programming language
C programming languageC programming language
C programming languageMaha lakshmi
 
Javascript by Yahoo
Javascript by YahooJavascript by Yahoo
Javascript by Yahoobirbal
 
Basic C Programming language
Basic C Programming languageBasic C Programming language
Basic C Programming languageAbhishek Soni
 
Glimpses of C++0x
Glimpses of C++0xGlimpses of C++0x
Glimpses of C++0xppd1961
 
Top C Language Interview Questions and Answer
Top C Language Interview Questions and AnswerTop C Language Interview Questions and Answer
Top C Language Interview Questions and AnswerVineet Kumar Saini
 

Tendances (18)

C programmimng basic.ppt
C programmimng basic.pptC programmimng basic.ppt
C programmimng basic.ppt
 
Introduction of c programming unit-ii ppt
Introduction of  c programming unit-ii pptIntroduction of  c programming unit-ii ppt
Introduction of c programming unit-ii ppt
 
Programming in C- Introduction
Programming in C- IntroductionProgramming in C- Introduction
Programming in C- Introduction
 
Introduction to F#
Introduction to F#Introduction to F#
Introduction to F#
 
Learning c - An extensive guide to learn the C Language
Learning c - An extensive guide to learn the C LanguageLearning c - An extensive guide to learn the C Language
Learning c - An extensive guide to learn the C Language
 
Unit ii
Unit   iiUnit   ii
Unit ii
 
Introduction to C programming
Introduction to C programmingIntroduction to C programming
Introduction to C programming
 
C# programming datatypes
C# programming  datatypesC# programming  datatypes
C# programming datatypes
 
C programming language
C programming languageC programming language
C programming language
 
Javascript by Yahoo
Javascript by YahooJavascript by Yahoo
Javascript by Yahoo
 
C basics
C basicsC basics
C basics
 
basics of c++
basics of c++basics of c++
basics of c++
 
Basic C Programming language
Basic C Programming languageBasic C Programming language
Basic C Programming language
 
Syntax part1
Syntax part1Syntax part1
Syntax part1
 
CProgrammingTutorial
CProgrammingTutorialCProgrammingTutorial
CProgrammingTutorial
 
C Tokens
C TokensC Tokens
C Tokens
 
Glimpses of C++0x
Glimpses of C++0xGlimpses of C++0x
Glimpses of C++0x
 
Top C Language Interview Questions and Answer
Top C Language Interview Questions and AnswerTop C Language Interview Questions and Answer
Top C Language Interview Questions and Answer
 

En vedette

Spain powerpoint annabel doyle
Spain powerpoint annabel doyleSpain powerpoint annabel doyle
Spain powerpoint annabel doyleAnnabel Doyle
 
Spain Power Point
Spain Power PointSpain Power Point
Spain Power Pointguest6d01f8
 
Power point of Spain
Power point of SpainPower point of Spain
Power point of Spainguesta61f28
 
Powerpoint madrid[1]
Powerpoint madrid[1]Powerpoint madrid[1]
Powerpoint madrid[1]sergiopcpi
 
Presentation about London's attractions
Presentation about London's attractionsPresentation about London's attractions
Presentation about London's attractionsguest2393a8
 

En vedette (8)

Spain powerpoint annabel doyle
Spain powerpoint annabel doyleSpain powerpoint annabel doyle
Spain powerpoint annabel doyle
 
Spain Power Point
Spain Power PointSpain Power Point
Spain Power Point
 
Power point of Spain
Power point of SpainPower point of Spain
Power point of Spain
 
Spain ppt long
Spain ppt   longSpain ppt   long
Spain ppt long
 
Powerpoint madrid[1]
Powerpoint madrid[1]Powerpoint madrid[1]
Powerpoint madrid[1]
 
Madrid powerpoint
Madrid powerpointMadrid powerpoint
Madrid powerpoint
 
Presentation about London's attractions
Presentation about London's attractionsPresentation about London's attractions
Presentation about London's attractions
 
Spain Powerpoint
Spain PowerpointSpain Powerpoint
Spain Powerpoint
 

Similaire à Madrid F# Meetup: Introduction to F#

Functional Programming in C# and F#
Functional Programming in C# and F#Functional Programming in C# and F#
Functional Programming in C# and F#Alfonso Garcia-Caro
 
vpTech - Practical F# in Finance
vpTech - Practical F# in FinancevpTech - Practical F# in Finance
vpTech - Practical F# in FinanceAmin Khansari
 
Dmitry mozorov on code quotations code as-data for f#
Dmitry mozorov on code quotations code as-data for f#Dmitry mozorov on code quotations code as-data for f#
Dmitry mozorov on code quotations code as-data for f#Skills Matter
 
Functional Programming - Worth the Effort
Functional Programming - Worth the EffortFunctional Programming - Worth the Effort
Functional Programming - Worth the EffortBoldRadius Solutions
 
What the math geeks don't want you to know about F#
What the math geeks don't want you to know about F#What the math geeks don't want you to know about F#
What the math geeks don't want you to know about F#Kevin Hazzard
 
How you can get started with F# today
How you can get started with F# todayHow you can get started with F# today
How you can get started with F# todayRichard Minerich
 
Bay NET Aug 19 2009 presentation ppt
Bay  NET Aug 19 2009 presentation pptBay  NET Aug 19 2009 presentation ppt
Bay NET Aug 19 2009 presentation pptArt Scott
 
Developing mobile apps with f sharp
Developing mobile apps with f sharpDeveloping mobile apps with f sharp
Developing mobile apps with f sharpGustavo Guerra
 
Creating Domain Specific Languages in F#
Creating Domain Specific Languages in F#Creating Domain Specific Languages in F#
Creating Domain Specific Languages in F#Tomas Petricek
 
"The F# Path to Relaxation", Don Syme
"The F# Path to Relaxation", Don Syme"The F# Path to Relaxation", Don Syme
"The F# Path to Relaxation", Don SymeFwdays
 

Similaire à Madrid F# Meetup: Introduction to F# (20)

FunScript: Why bother?
FunScript: Why bother?FunScript: Why bother?
FunScript: Why bother?
 
Functional Programming in C# and F#
Functional Programming in C# and F#Functional Programming in C# and F#
Functional Programming in C# and F#
 
vpTech - Practical F# in Finance
vpTech - Practical F# in FinancevpTech - Practical F# in Finance
vpTech - Practical F# in Finance
 
F# and the DLR
F# and the DLRF# and the DLR
F# and the DLR
 
Practical F#
Practical F#Practical F#
Practical F#
 
F# Tutorial @ QCon
F# Tutorial @ QConF# Tutorial @ QCon
F# Tutorial @ QCon
 
F# for Trading NYC
F# for Trading NYCF# for Trading NYC
F# for Trading NYC
 
F# for Trading
F# for TradingF# for Trading
F# for Trading
 
Dmitry mozorov on code quotations code as-data for f#
Dmitry mozorov on code quotations code as-data for f#Dmitry mozorov on code quotations code as-data for f#
Dmitry mozorov on code quotations code as-data for f#
 
Functional Programming - Worth the Effort
Functional Programming - Worth the EffortFunctional Programming - Worth the Effort
Functional Programming - Worth the Effort
 
What the math geeks don't want you to know about F#
What the math geeks don't want you to know about F#What the math geeks don't want you to know about F#
What the math geeks don't want you to know about F#
 
FINAL.ppt
FINAL.pptFINAL.ppt
FINAL.ppt
 
How you can get started with F# today
How you can get started with F# todayHow you can get started with F# today
How you can get started with F# today
 
F# 101
F# 101F# 101
F# 101
 
Tutorial csharp
Tutorial csharpTutorial csharp
Tutorial csharp
 
Bay NET Aug 19 2009 presentation ppt
Bay  NET Aug 19 2009 presentation pptBay  NET Aug 19 2009 presentation ppt
Bay NET Aug 19 2009 presentation ppt
 
Developing mobile apps with f sharp
Developing mobile apps with f sharpDeveloping mobile apps with f sharp
Developing mobile apps with f sharp
 
Creating Domain Specific Languages in F#
Creating Domain Specific Languages in F#Creating Domain Specific Languages in F#
Creating Domain Specific Languages in F#
 
C-sharping.docx
C-sharping.docxC-sharping.docx
C-sharping.docx
 
"The F# Path to Relaxation", Don Syme
"The F# Path to Relaxation", Don Syme"The F# Path to Relaxation", Don Syme
"The F# Path to Relaxation", Don Syme
 

Dernier

Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 

Dernier (20)

Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 

Madrid F# Meetup: Introduction to F#

  • 1. MADRID F# MEETUP Introduction to F#
  • 2. MADRID F# MEETUP About me Alfonso García-Caro Independent Developer Studied IT but got degree in Linguistics Japanese speaker .NET fanboy Started F# recently More pragmatic than theoretical @alfonsogcnunez github.com/alfonsogarciacaro
  • 3. MADRID F# MEETUP About this talk Not official nor comprehensive Mostly based in personal experience Not an introduction to functional programming Please ask if you need more detail Will “borrow” from other F#ers Particularly @ScottWlaschin fsharp.org fsharpforfunandprofit.com
  • 4. MADRID F# MEETUP What is F#? F# is an open source, cross-platform, strongly-typed, functional-first programming language. It offers interoperability with all .NET languages and libraries and data-rich analytical services like type providers and LINQ queries.
  • 5. FunScript F# to JavaScript with type providers MADRID F# MEETUP
  • 6. MADRID F# MEETUP F# is... robust Its powerful type system prevents many common errors (null references) and allows you to encode business logic to make illegal states unrepresentable. Yaron minsky via fsharpforfunandprofit.com
  • 7. MADRID F# MEETUP Model Problem: A contact must have an email or a postal address Naïve solution Solution with union types
  • 8. MADRID F# MEETUP F# types: Tuples • No explicit names • Can have any number of components • Components can be generic o complex types • Most often used to return multiple values from private functions
  • 9. MADRID F# MEETUP F# types: Records • Like tuples with labels • Structural equality by default • Can have members
  • 10. MADRID F# MEETUP F# types: Discriminated Unions • Mostly used with pattern matching • Can be recursive • Can have field names (tuple labels) • Empty cases possible • Option union instead of null
  • 11. MADRID F# MEETUP F# types: Discriminated Unions Construction Pattern matching: Check case and deconstruct all-in-one
  • 12. MADRID F# MEETUP F# types: unit • No void functions • Single value: () • Automatically ignored F# types: Abbreviations Use an alias for convenience (no type-safe) These ones are built-in
  • 13. MADRID F# MEETUP F# types: Collections Many built-in functions to deal with sequences: map, reduce, fold, find... • Immutable oRecursive lists oSet and maps oLazy sequences • Mutable oArray oBuilt-in .NET collections: Lists, Dictionaries... • Also ranges and comprehensions All collections are generic
  • 14. MADRID F# MEETUP F# types: Built-in .NET Types • Built-in value types: int, bool... • Built-in reference types: string... • User-defined value types: enum and struct • Classes and interfaces • Delegates Not the same as F# functions but they can be converted Also pointers, but they are not usually needed
  • 15. FunScript F# to JavaScript with type providers MADRID F# MEETUP YOU SAY STATIC TYPING I HEAR BOILERPLATE
  • 16. MADRID F# MEETUP F# is... agile Type inference reduces the number of type annotations, bringing together the benefits of static typing and the conciseness of dynamic typing. C# F#
  • 17. MADRID F# MEETUP F# reduces code “noise” But you can use them • No curly braces for scope • No semicolons • Meaningful whitespace like Python • No return keyword if necessary C# F# Forward pipe operator
  • 18. MADRID F# MEETUP Pattern Matching Match and deconstruct complex patterns with no hassle Wildcard Constant Empty list Guard The compiler warns you if you don’t cover all cases
  • 19. MADRID F# MEETUP Pattern Matching Define your own active patterns Syntactic sugar
  • 20. MADRID F# MEETUP Thinking sequentially (1) Use computation expressions (aka monads) to simplify complex programming workflows and simulate state machines Perform asynchronous operations as if they were synchronous
  • 21. MADRID F# MEETUP Thinking sequentially (2) Define your own workflows easily Can return Some(value) or None ... and without With...
  • 22. MADRID F# MEETUP Thinking sequentially (and 3) Parallelism made easy thanks to immutability and Async Erlang-like agents also available Parallel I/O Parallel CPU
  • 23. MADRID F# MEETUP Domain Driven Design Programmers and non-programmers can Believe it! speak the same language
  • 25. MADRID F# MEETUP Scripting With F# you can write both complex project and simple scripts There is a REPL too
  • 26. FunScript F# to JavaScript with type providers MADRID F# MEETUP I ALREADY KNEW ALL THAT
  • 27. MADRID F# MEETUP Killer Features: Measure Units Protect your number values for free! Combine them with other types Use generics The measure annotations disappear after compilation so they have no performance penalty The compiler prevents mistakes
  • 28. FunScript F# to JavaScript with type providers MADRID F# MEETUP There are more killer features but let’s go directly to the crown jewel
  • 29. MADRID F# MEETUP Killer Features: Type Providers Static typing on demand! Fsharp.Data Sergey Tihon’s blog
  • 30. FunScript F# to JavaScript with type providers MADRID F# MEETUP I WANT NO ACADEMIC STUFF I WANNA MAKE REAL APPS!
  • 31. MADRID F# MEETUP F# is multiplatform • .NET: Windows Desktop and Store, Windows Phone • Mono: Mac and Linux • Xamarin: Android and iOS • ASP.NET: Server • FunScript and WebSharper: Browser • GPU, FreeBSD... more at fsharp.org
  • 32. FunScript F# to JavaScript with type providers MADRID F# MEETUP DEMO TIME
  • 33. MADRID F# MEETUP Why F#? Why now? • Functional programming is booming • Great community, really open to newcomers • Everybody can contribute to the evolution of the language • Open source but backed by big companies oMicrosoft oXamarin • fun is a keyword!