SlideShare ist ein Scribd-Unternehmen logo
1 von 33
Downloaden Sie, um offline zu lesen
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!

Weitere ähnliche Inhalte

Was ist angesagt?

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
 

Was ist angesagt? (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
 

Andere mochten auch

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
 

Andere mochten auch (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
 

Ähnlich wie 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
 

Ähnlich wie 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
 

Kürzlich hochgeladen

Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
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
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
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
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
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
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
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
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
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
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
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
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessPixlogix Infotech
 
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
 

Kürzlich hochgeladen (20)

Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
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
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
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
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
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?
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
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
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
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
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
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)
 

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!