SlideShare a Scribd company logo
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!

More Related Content

PDF
F# for Scala developers
PPT
F# Intro for Scala Developers
ODP
Progressive f# tutorials nyc dmitry mozorov & jack pappas on code quotations ...
PDF
The State of C#
PPTX
Introduction to F#
PPTX
F# for startups
PPTX
ODP
C prog ppt
F# for Scala developers
F# Intro for Scala Developers
Progressive f# tutorials nyc dmitry mozorov & jack pappas on code quotations ...
The State of C#
Introduction to F#
F# for startups
C prog ppt

What's hot (18)

PPTX
C programmimng basic.ppt
PPTX
Introduction of c programming unit-ii ppt
PDF
Programming in C- Introduction
PPTX
Introduction to F#
PDF
Learning c - An extensive guide to learn the C Language
PPTX
Unit ii
PDF
Introduction to C programming
PDF
C# programming datatypes
PPTX
C programming language
PPT
Javascript by Yahoo
PDF
C basics
PPTX
basics of c++
ODP
Basic C Programming language
PDF
Syntax part1
ODP
CProgrammingTutorial
PPTX
C Tokens
PPT
Glimpses of C++0x
PDF
Top C Language Interview Questions and Answer
C programmimng basic.ppt
Introduction of c programming unit-ii ppt
Programming in C- Introduction
Introduction to F#
Learning c - An extensive guide to learn the C Language
Unit ii
Introduction to C programming
C# programming datatypes
C programming language
Javascript by Yahoo
C basics
basics of c++
Basic C Programming language
Syntax part1
CProgrammingTutorial
C Tokens
Glimpses of C++0x
Top C Language Interview Questions and Answer
Ad

Viewers also liked (8)

PPT
Spain powerpoint annabel doyle
PPT
Spain Power Point
PPT
Power point of Spain
ODP
Spain ppt long
PPT
Powerpoint madrid[1]
PPTX
Madrid powerpoint
PPT
Presentation about London's attractions
PPT
Spain Powerpoint
Spain powerpoint annabel doyle
Spain Power Point
Power point of Spain
Spain ppt long
Powerpoint madrid[1]
Madrid powerpoint
Presentation about London's attractions
Spain Powerpoint
Ad

Similar to Madrid F# Meetup: Introduction to F# (20)

PPTX
F# for startups v2
PPTX
Introduction to f#
ODP
F# 101
PPTX
Sharper tools with F#
PPTX
Can F# make us better as .NET developers?
PPTX
Functional programming with FSharp
PDF
F# and Reactive Programming for iOS
PPTX
What The F#
PPTX
F# Tutorial @ QCon
PPTX
F# and functional programming
PPTX
Break Free with Managed Functional Programming: An Introduction to F#
PPTX
Break Free with Managed Functional Programming: An Introduction to F#
PPTX
Domain Modeling & Full-Stack Web Development F#
PPTX
Qcon2011 functions rockpresentation_f_sharp
PPTX
Qcon2011 functions rockpresentation_f_sharp
PPT
F# Eye for the C# Guy
PPT
F# Sample and Resources
PPTX
F# for functional enthusiasts
PDF
"Introduction to F#" - South Dakota Code Camp, November 5, 2011
PPT
F# and the DLR
F# for startups v2
Introduction to f#
F# 101
Sharper tools with F#
Can F# make us better as .NET developers?
Functional programming with FSharp
F# and Reactive Programming for iOS
What The F#
F# Tutorial @ QCon
F# and functional programming
Break Free with Managed Functional Programming: An Introduction to F#
Break Free with Managed Functional Programming: An Introduction to F#
Domain Modeling & Full-Stack Web Development F#
Qcon2011 functions rockpresentation_f_sharp
Qcon2011 functions rockpresentation_f_sharp
F# Eye for the C# Guy
F# Sample and Resources
F# for functional enthusiasts
"Introduction to F#" - South Dakota Code Camp, November 5, 2011
F# and the DLR

Recently uploaded (20)

PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Encapsulation theory and applications.pdf
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
August Patch Tuesday
PDF
Machine learning based COVID-19 study performance prediction
PDF
Assigned Numbers - 2025 - Bluetooth® Document
PPT
Teaching material agriculture food technology
PDF
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
A comparative study of natural language inference in Swahili using monolingua...
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PPTX
Spectroscopy.pptx food analysis technology
PPTX
Machine Learning_overview_presentation.pptx
PDF
Approach and Philosophy of On baking technology
PPTX
Group 1 Presentation -Planning and Decision Making .pptx
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Heart disease approach using modified random forest and particle swarm optimi...
PDF
Accuracy of neural networks in brain wave diagnosis of schizophrenia
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Encapsulation theory and applications.pdf
Diabetes mellitus diagnosis method based random forest with bat algorithm
August Patch Tuesday
Machine learning based COVID-19 study performance prediction
Assigned Numbers - 2025 - Bluetooth® Document
Teaching material agriculture food technology
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
Advanced methodologies resolving dimensionality complications for autism neur...
A comparative study of natural language inference in Swahili using monolingua...
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Spectroscopy.pptx food analysis technology
Machine Learning_overview_presentation.pptx
Approach and Philosophy of On baking technology
Group 1 Presentation -Planning and Decision Making .pptx
Programs and apps: productivity, graphics, security and other tools
Network Security Unit 5.pdf for BCA BBA.
Reach Out and Touch Someone: Haptics and Empathic Computing
Heart disease approach using modified random forest and particle swarm optimi...
Accuracy of neural networks in brain wave diagnosis of schizophrenia

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!