SlideShare a Scribd company logo
F# Eye for the C# guy Leon Bambrick, secretGeek.net
F#... Do not be afraid.
hello
I’m F #
 
functional
Purely functional… Avoid  Side- Effects!
Purely functional… Avoid  Mutation!
Purely functional… No Variables!  Only Functions!
Purely functional… Same input -> Same output!
No Shared State Purely functional…
Why learn F#?
Do More With Less “ If I was using F# I’d be done by now” Why learn F#?
Do More With Less “ If I was using F# I’d be done by now” See where C# and VB.net are headed Why learn F#?
Do More With Less “ If I was using F# I’d be done by now” See where C# and VB.net are headed “ Learn one new language every year” (or two) Why learn F#?
Moore’s Law Keeps Going! Why learn F#?
But computers are not getting faster Why learn F#?
Data Grows Quickly  But # of Dimensions Grows much faster! And semi-structured data outgrowing structured Entropy Increasing Complexity is through the roof!
“ Software  gets slower faster than  hardware  gets faster” --Wirth’s Law
 
Some stuff is now cheap! Ram Disk  Cores Some stuff remains expensive! Time Concurrency Locking Computer Economics is Changing
Some stuff is now cheap! Ram Disk  Cores Some stuff remains expensive! Time Concurrency Locking Computer Economics is Changing
Some stuff is now cheap! Ram Disk  Cores Some stuff remains expensive! Time Concurrency Locking Computer Economics is Changing
Some stuff is now cheap! Ram Disk  Cores Some stuff remains expensive! Real Time Concurrency Locking Computer Economics is Changing
This  tips the balance  toward higher abstractions
Some Applications of F# “ Computationally intensive” work Map/Reduce over internets Financial Analysis Advertising Analysis SQL Data Mining XNA Games Development  Web tools, Compile F# to Javascript
Think About Game Programming
Game Programming Involves… 3D Animation Rendering Shading Simulation (e.g. physics) Collision Detection AI Opponents
Genealogy of F #  … Theorem proving and ISWIM
Genealogy of F #  … Theorem proving and ISWIM  begat: ML “Meta Language”
Genealogy of F #  … Theorem proving and ISWIM begat: ML “Meta Language”,  which begat: CAML
Genealogy of F #  … Theorem proving and ISWIM begat: ML “Meta Language”, which begat: CAML,  which in turn begat OCaml Oh!
Genealogy of F #  … Theorem proving and ISWIM begat: ML “Meta Language”, which begat: CAML, which in turn begat OCaml,  which in turn begat F# ... a sort of OCaml.net (plus more) Oh!
WTF # ? First official functional language on .net
WTF # ? First official functional language on .net Deep support thanks to Generics
WTF # ? First official functional language on .net Deep support thanks to Generics Assimilated by dev-div
WTF # ? First official functional language on .net Deep support thanks to Generics Assimilated by dev-div Will ship in VS.next
Code! Finally!
Code! //F# let a = 2
Code! //F# let a = 2 The ‘let’ keyword represents a binding between a value and an expression tree.
Code! //F# let a = 2 The ‘let’ blah blah blahblah blah blahblah blahblah blah blah blah blah blah blah.
Code! //F# let a = 2 //C# int a = 2 ≠
Code! //F# let a = 2 //C# //a function! static int a() { return 2; } More like
More Code! //F# #light open  System let  a = 2 Console.WriteLine a //C# using  System; namespace  ConsoleApplication1 { class   Program { static   int  a() { return  2; } static void  Main( string [] args) { Console .WriteLine(a);  } } }
More Code! //F# #light open  System let  a = 2 Console.WriteLine a More Noise  Than Signal!
More Code! //F# #light open  System let  a = 2 Console.WriteLine a Looks Weakly typed? Maybe Dynamic?
F#?
F#
F# Yet Expressive
F# Yet Versatile
More Code! //F# #light open  System let  a = 2 Console.WriteLine a Type Inference
let  a = 2 let  a = 3 error: FS0037: Duplicate definition of value 'a' Immutable by default
let  square x = x * x > val square : int -> int square 5 > val it : int = 25 simple function…
let  square x = x * x > val square : int -> int square 5 > val it : int = 25 simple function… Parameter
let  square x = x * x > val square : int -> int square 5 > val it : int = 25 simple function… “ Signature”
let  square x = x * x > val square : int -> int square 5 > val it : int = 25 simple function… Types are “inferred”
Discriminated union types type NullableInt = | Value of int | Nothing of unit
Discriminated union types type NullableInt = | Value of int | Nothing of unit Wish C#/“O-O” had this.
Discriminated union types type NullableInt = | Value of int | Nothing of unit “ O-O” has discriminated union envy When the only tool you have is a hammer Everything looks like a nail
Discriminated union types type NullableInt = | Value of int | Nothing of unit “ O-O” has discriminated union envy When the only tool you have is a hammer Everything looks like a nail e.g. “Inheritance” ends up being used in places where it’s not a perfect fit…
Discriminated union types type NullableInt = | Value of int | Nothing of unit “ O-O” has discriminated union envy When the only tool you have is a hammer Everything looks like a nail e.g. “Inheritance” ends up being used in places where it’s not a perfect fit… ‘ Discriminated union types’ -- a better fit for some problems?
Another great tool is  “pattern matching”
Another great tool is   “pattern matching” “ Switch/Case” statements on steroids
Another great tool is   “pattern matching” “ Switch/Case” statements on steroids “ method overloads” on crack
Discriminated unions   example type Weapon = | Knife  | Gun  | Bomb
Pattern Matching type Weapon = | Knife  | Gun  | Bomb  //block any weapon! let block w = match w with | Knife  | Gun  -> disarm w | _ -> difuse w block Gun block Knife block Bomb
Pattern Matching type Weapon = | Knife  | Gun  | Bomb  //block any weapon let block w = match w with | Knife  | Gun  -> disarm w | _ -> difuse w block Gun block Knife block Bomb
Lazy is a virtue let  lazy_square x =  lazy  ( print_endline “thinking...“ x * x ) let  lazy_square_ten = lazy_square 10 //first time: “thinking…” Lazy.force  (lazy_square_ten) //second time: no thinking, just result Lazy.force  (lazy_square_ten)
Lazy is a virtue let  lazy_square x =  lazy  ( print_endline “thinking...“ x * x ) let  lazy_square_ten = lazy_square 10 //first time: “thinking…” Lazy.force  (lazy_square_ten) //second time: no thinking, just result Lazy.force  (lazy_square_ten)
Useful libraries Neat manual Awesome Samples
 
 
“ Empty” source file… 5 pages of help!
Make sure F# Interactive is running!
F# Interactive: It’s the bomb!
F# Interactive:
 
msdn.microsoft.com/fsharp/
8 Ways to Learn http://cs.hubfs.net Codeplex Fsharp Samples Books ML
Acknowledgements Cartman Einstein Dilbert Alan Turing Alonzo Church Godzilla Gears of war John Hughes,  Why Functional Programming Matters,   http://www.math.chalmers.se/~rjmh/Papers/whyfp.html Robert Pickering,  Foundations of F#,  http://www.apress.com/book/view/1590597575 Slava Akhmechet,  Functional Programming For The Rest of Us,  http://www.defmacro.org/ramblings/fp.html Steve Yegge,  Execution In the Kingdom of Nouns,  http://steve-yegge.blogspot.com/2006/03/execution-in-kingdom-of-nouns.html P. J. Landin,  The Next 700 Programming Languages   http://www.cs.utah.edu/~wilson/compilers/old/papers/p157-landin.pdf Tim Sweeney,  The Next Mainstream Programming Language ,  http://www.st.cs.uni-sb.de/edu/seminare/2005/advanced-fp/docs/sweeny.pdf Tomas Petricek,  F# Web Tools, Ajax Made Simple ,  http://www.codeplex.com/fswebtools Don Syme,  http://blogs.msdn.com/dsyme

More Related Content

PDF
Functional Programming in C# and F#
PPTX
Introduction to F#
PPTX
F# and functional programming
PPTX
History of F#, and the ML family of languages.
PPTX
Introduction to F#
PDF
F# for Scala developers
PPT
F# Intro for Scala Developers
PPT
F# and the DLR
Functional Programming in C# and F#
Introduction to F#
F# and functional programming
History of F#, and the ML family of languages.
Introduction to F#
F# for Scala developers
F# Intro for Scala Developers
F# and the DLR

What's hot (20)

PPTX
Python Introduction
PDF
Advanced C Language for Engineering
PPTX
Practical F#
PPTX
PDF
JavaScript: Core Part
PDF
Python Programming - I. Introduction
PPT
The smartpath information systems c pro
PDF
Learning c - An extensive guide to learn the C Language
DOC
PPT
PPTX
C language ppt
PPTX
C++ ppt
PPTX
Python Basics
PPT
Introduction to C Programming - I
PPTX
What is Python? An overview of Python for science.
PPTX
Introduction to C programming
ODP
Basic C Programming language
ODP
OpenGurukul : Language : C Programming
PDF
C programming Ms. Pranoti Doke
Python Introduction
Advanced C Language for Engineering
Practical F#
JavaScript: Core Part
Python Programming - I. Introduction
The smartpath information systems c pro
Learning c - An extensive guide to learn the C Language
C language ppt
C++ ppt
Python Basics
Introduction to C Programming - I
What is Python? An overview of Python for science.
Introduction to C programming
Basic C Programming language
OpenGurukul : Language : C Programming
C programming Ms. Pranoti Doke
Ad

Similar to F# Eye for the C# Guy (20)

PPTX
Functional programming with FSharp
PDF
Functional programming with F#
PPTX
Introduction to f#
PPTX
What The F#
PDF
Functional Programming in F#
PPTX
London F-Sharp User Group : Don Syme on F# - 09/09/2010
PPTX
F sharp _vs2010_beta2
ODP
F# 101
PPTX
Can F# make us better as .NET developers?
PPTX
Sharper tools with F#
PDF
F# and Reactive Programming for iOS
PPTX
Reasonable Code With Fsharp
PDF
Madrid F# Meetup: Introduction to F#
PPTX
Real World F# - SDD 2015
PPSX
DITEC - Programming with C#.NET
PPTX
Functional Programming Fundamentals
PPSX
DISE - Windows Based Application Development in C#
PPTX
FP Day 2011 - Turning to the Functional Side (using C# & F#)
PPTX
F# for startups v2
PPTX
Introduction to Functional Programming in FSharp
Functional programming with FSharp
Functional programming with F#
Introduction to f#
What The F#
Functional Programming in F#
London F-Sharp User Group : Don Syme on F# - 09/09/2010
F sharp _vs2010_beta2
F# 101
Can F# make us better as .NET developers?
Sharper tools with F#
F# and Reactive Programming for iOS
Reasonable Code With Fsharp
Madrid F# Meetup: Introduction to F#
Real World F# - SDD 2015
DITEC - Programming with C#.NET
Functional Programming Fundamentals
DISE - Windows Based Application Development in C#
FP Day 2011 - Turning to the Functional Side (using C# & F#)
F# for startups v2
Introduction to Functional Programming in FSharp
Ad

Recently uploaded (20)

PDF
cuic standard and advanced reporting.pdf
PDF
CIFDAQ's Market Insight: SEC Turns Pro Crypto
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Modernizing your data center with Dell and AMD
PDF
NewMind AI Monthly Chronicles - July 2025
PPT
Teaching material agriculture food technology
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Approach and Philosophy of On baking technology
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
cuic standard and advanced reporting.pdf
CIFDAQ's Market Insight: SEC Turns Pro Crypto
Network Security Unit 5.pdf for BCA BBA.
Dropbox Q2 2025 Financial Results & Investor Presentation
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Modernizing your data center with Dell and AMD
NewMind AI Monthly Chronicles - July 2025
Teaching material agriculture food technology
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
NewMind AI Weekly Chronicles - August'25 Week I
20250228 LYD VKU AI Blended-Learning.pptx
Understanding_Digital_Forensics_Presentation.pptx
“AI and Expert System Decision Support & Business Intelligence Systems”
Approach and Philosophy of On baking technology
Building Integrated photovoltaic BIPV_UPV.pdf
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Mobile App Security Testing_ A Comprehensive Guide.pdf
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Advanced methodologies resolving dimensionality complications for autism neur...

F# Eye for the C# Guy

  • 1. F# Eye for the C# guy Leon Bambrick, secretGeek.net
  • 2. F#... Do not be afraid.
  • 5.  
  • 7. Purely functional… Avoid Side- Effects!
  • 9. Purely functional… No Variables! Only Functions!
  • 10. Purely functional… Same input -> Same output!
  • 11. No Shared State Purely functional…
  • 13. Do More With Less “ If I was using F# I’d be done by now” Why learn F#?
  • 14. Do More With Less “ If I was using F# I’d be done by now” See where C# and VB.net are headed Why learn F#?
  • 15. Do More With Less “ If I was using F# I’d be done by now” See where C# and VB.net are headed “ Learn one new language every year” (or two) Why learn F#?
  • 16. Moore’s Law Keeps Going! Why learn F#?
  • 17. But computers are not getting faster Why learn F#?
  • 18. Data Grows Quickly But # of Dimensions Grows much faster! And semi-structured data outgrowing structured Entropy Increasing Complexity is through the roof!
  • 19. “ Software gets slower faster than hardware gets faster” --Wirth’s Law
  • 20.  
  • 21. Some stuff is now cheap! Ram Disk Cores Some stuff remains expensive! Time Concurrency Locking Computer Economics is Changing
  • 22. Some stuff is now cheap! Ram Disk Cores Some stuff remains expensive! Time Concurrency Locking Computer Economics is Changing
  • 23. Some stuff is now cheap! Ram Disk Cores Some stuff remains expensive! Time Concurrency Locking Computer Economics is Changing
  • 24. Some stuff is now cheap! Ram Disk Cores Some stuff remains expensive! Real Time Concurrency Locking Computer Economics is Changing
  • 25. This tips the balance toward higher abstractions
  • 26. Some Applications of F# “ Computationally intensive” work Map/Reduce over internets Financial Analysis Advertising Analysis SQL Data Mining XNA Games Development Web tools, Compile F# to Javascript
  • 27. Think About Game Programming
  • 28. Game Programming Involves… 3D Animation Rendering Shading Simulation (e.g. physics) Collision Detection AI Opponents
  • 29. Genealogy of F # … Theorem proving and ISWIM
  • 30. Genealogy of F # … Theorem proving and ISWIM begat: ML “Meta Language”
  • 31. Genealogy of F # … Theorem proving and ISWIM begat: ML “Meta Language”, which begat: CAML
  • 32. Genealogy of F # … Theorem proving and ISWIM begat: ML “Meta Language”, which begat: CAML, which in turn begat OCaml Oh!
  • 33. Genealogy of F # … Theorem proving and ISWIM begat: ML “Meta Language”, which begat: CAML, which in turn begat OCaml, which in turn begat F# ... a sort of OCaml.net (plus more) Oh!
  • 34. WTF # ? First official functional language on .net
  • 35. WTF # ? First official functional language on .net Deep support thanks to Generics
  • 36. WTF # ? First official functional language on .net Deep support thanks to Generics Assimilated by dev-div
  • 37. WTF # ? First official functional language on .net Deep support thanks to Generics Assimilated by dev-div Will ship in VS.next
  • 39. Code! //F# let a = 2
  • 40. Code! //F# let a = 2 The ‘let’ keyword represents a binding between a value and an expression tree.
  • 41. Code! //F# let a = 2 The ‘let’ blah blah blahblah blah blahblah blahblah blah blah blah blah blah blah.
  • 42. Code! //F# let a = 2 //C# int a = 2 ≠
  • 43. Code! //F# let a = 2 //C# //a function! static int a() { return 2; } More like
  • 44. More Code! //F# #light open System let a = 2 Console.WriteLine a //C# using System; namespace ConsoleApplication1 { class Program { static int a() { return 2; } static void Main( string [] args) { Console .WriteLine(a); } } }
  • 45. More Code! //F# #light open System let a = 2 Console.WriteLine a More Noise Than Signal!
  • 46. More Code! //F# #light open System let a = 2 Console.WriteLine a Looks Weakly typed? Maybe Dynamic?
  • 47. F#?
  • 48. F#
  • 51. More Code! //F# #light open System let a = 2 Console.WriteLine a Type Inference
  • 52. let a = 2 let a = 3 error: FS0037: Duplicate definition of value 'a' Immutable by default
  • 53. let square x = x * x > val square : int -> int square 5 > val it : int = 25 simple function…
  • 54. let square x = x * x > val square : int -> int square 5 > val it : int = 25 simple function… Parameter
  • 55. let square x = x * x > val square : int -> int square 5 > val it : int = 25 simple function… “ Signature”
  • 56. let square x = x * x > val square : int -> int square 5 > val it : int = 25 simple function… Types are “inferred”
  • 57. Discriminated union types type NullableInt = | Value of int | Nothing of unit
  • 58. Discriminated union types type NullableInt = | Value of int | Nothing of unit Wish C#/“O-O” had this.
  • 59. Discriminated union types type NullableInt = | Value of int | Nothing of unit “ O-O” has discriminated union envy When the only tool you have is a hammer Everything looks like a nail
  • 60. Discriminated union types type NullableInt = | Value of int | Nothing of unit “ O-O” has discriminated union envy When the only tool you have is a hammer Everything looks like a nail e.g. “Inheritance” ends up being used in places where it’s not a perfect fit…
  • 61. Discriminated union types type NullableInt = | Value of int | Nothing of unit “ O-O” has discriminated union envy When the only tool you have is a hammer Everything looks like a nail e.g. “Inheritance” ends up being used in places where it’s not a perfect fit… ‘ Discriminated union types’ -- a better fit for some problems?
  • 62. Another great tool is “pattern matching”
  • 63. Another great tool is “pattern matching” “ Switch/Case” statements on steroids
  • 64. Another great tool is “pattern matching” “ Switch/Case” statements on steroids “ method overloads” on crack
  • 65. Discriminated unions example type Weapon = | Knife | Gun | Bomb
  • 66. Pattern Matching type Weapon = | Knife | Gun | Bomb //block any weapon! let block w = match w with | Knife | Gun -> disarm w | _ -> difuse w block Gun block Knife block Bomb
  • 67. Pattern Matching type Weapon = | Knife | Gun | Bomb //block any weapon let block w = match w with | Knife | Gun -> disarm w | _ -> difuse w block Gun block Knife block Bomb
  • 68. Lazy is a virtue let lazy_square x = lazy ( print_endline “thinking...“ x * x ) let lazy_square_ten = lazy_square 10 //first time: “thinking…” Lazy.force (lazy_square_ten) //second time: no thinking, just result Lazy.force (lazy_square_ten)
  • 69. Lazy is a virtue let lazy_square x = lazy ( print_endline “thinking...“ x * x ) let lazy_square_ten = lazy_square 10 //first time: “thinking…” Lazy.force (lazy_square_ten) //second time: no thinking, just result Lazy.force (lazy_square_ten)
  • 70. Useful libraries Neat manual Awesome Samples
  • 71.  
  • 72.  
  • 73. “ Empty” source file… 5 pages of help!
  • 74. Make sure F# Interactive is running!
  • 77.  
  • 79. 8 Ways to Learn http://cs.hubfs.net Codeplex Fsharp Samples Books ML
  • 80. Acknowledgements Cartman Einstein Dilbert Alan Turing Alonzo Church Godzilla Gears of war John Hughes, Why Functional Programming Matters, http://www.math.chalmers.se/~rjmh/Papers/whyfp.html Robert Pickering, Foundations of F#, http://www.apress.com/book/view/1590597575 Slava Akhmechet, Functional Programming For The Rest of Us, http://www.defmacro.org/ramblings/fp.html Steve Yegge, Execution In the Kingdom of Nouns, http://steve-yegge.blogspot.com/2006/03/execution-in-kingdom-of-nouns.html P. J. Landin, The Next 700 Programming Languages http://www.cs.utah.edu/~wilson/compilers/old/papers/p157-landin.pdf Tim Sweeney, The Next Mainstream Programming Language , http://www.st.cs.uni-sb.de/edu/seminare/2005/advanced-fp/docs/sweeny.pdf Tomas Petricek, F# Web Tools, Ajax Made Simple , http://www.codeplex.com/fswebtools Don Syme, http://blogs.msdn.com/dsyme

Editor's Notes

  • #2: What’s this F# thing anyway?