SlideShare a Scribd company logo
[F#] DEV LIFE’S LITTLE PLEASURES
Natallie Baikevich,
F# enthusiast and financial dev
@lu_a_jalla
WE ARE EVERYWHERE!
THINGS TO CARE ABOUT:

• Correctness

• Efficiency
• Safety

• Conciseness
• Simplicity
Based on true stories

WHEN YOU MEET THE REAL WORLD…
#1. THE SPREADSHEET
How to gain by selling £17mln and buying $10mln?
• Buy $10mln
• Sell £16mln

• Spot Rate = 1.6
• GBP/USD =1.5945
• RGL = 88000
Pretty nice, isn’t it?
#1. THE CODE
let buyAmount, sellAmount = 10000000.0, 16000000.0
let spotRate = sellAmount / buyAmount // 1.6
let exchRate = 1.5945

let rgl amount spotRate exchRate =
amount * (spotRate - exchRate)

rgl sellAmount spotRate exchRate |> printfn "%A"
// 88000.0
UNITS OF MEASURE
[<Measure>] type USD
[<Measure>] type GBP

let buyAmount, sellAmount = 10000000.0<USD>, 16000000.0<GBP>

let spotRate = sellAmount / buyAmount

let exchRate = 1.5945<USD/GBP>

let rgl amount spotRate exchRate =

amount * (spotRate – exchRate)
UNITS OF MEASURE - FIXED
[<Measure>] type USD
[<Measure>] type GBP

let buyAmount, sellAmount = 10000000.0<USD>, 16000000.0<GBP>

let spotRate = buyAmount / sellAmount

let exchRate = 1.5945<USD/GBP>

let rgl amount spotRate exchRate =
amount * (spotRate – exchRate)

// -15512000.0
#2. THE OPPORTUNITIES
The same trick works for yield quotes! Get a 100 times
greater coupon. Or smaller. Whatever.
• 1 = 100%
• 1 % = 100 bp

… Or add <pct> and <bp>.
The copy-paste is still around, so

GO FOR GENERICS!
WHAT MAKES A PROGRAM WRITE ITSELF?
#3. THE BOILERPLATE
DevExpress layouts: Save/Restore
• DockManager:
public void SaveLayoutToStream(Stream stream);
public void RestoreLayoutFromStream(Stream stream);

• Grid:
public void SaveLayoutToStream(Stream stream);
public void RestoreLayoutFromStream(Stream stream);
#4. LOADING STOCK DATA FROM YAHOO
type Price = {

“Oct 10, 2013“

Date: DateTime

parse DateTime

“33.31”

parse float

“33.38”

parse float

…

Open: float

…

High: float
Low: float
Close: float
Volume: float

AdjClose: float option
}
MEET GENERIC RESTRICTIONS
let inline tryParse str =
let mutable res = Unchecked.defaultof<_>
let ok = (^a: (static member TryParse: string * byref< ^a > -> bool) (str, &res))
res

match s.Split ',' with

| [| date; o; h; l; c; v; adj |] ->
Some { Date = tryParse date;
Open = tryParse o;
High = tryParse h;

}
Good and Evil

MUTABILITY / STATE / MORE
[F#] Dev Life's Little Pleasures
#6. JUST CHECKING UPDATES
.NET List [ResizeArray]
foreach(var update in updatesList)
{
doSomethingWith(update);
}

System.InvalidOperationException: Collection was modified; enumeration
operation may not execute.
WHEN CHOOSE WHAT
Immutable

Mutable

• Safe
• Simple to read

• Performance optimizations
(e.g. Dictionary vs Map)

• Efficient data structures:

• Interop

• Check fsharpx
• F# Core extensions (ExtCore)
HOW
• let for values
• types: tuples, records, DUs
• core & community collections and data structures (list, map, set
and more)
Scala

F#

• val

• let

• var

• let mutable
The billion dollar mistake and co

MAKE ILLEGAL STATES UNREPRESENTABLE
(NULL)

We have an Option to avoid nulls!
#8. SEND A MESSAGE
match status with
| Pending ->
| Verified -> doSomething()

Pattern matching &
Discriminated Unions FTW!

FS0025: Incomplete pattern matches on this expression. For example,
the value '(_,Released)’

type Status =
| Pending
| Verified of User
| Released of User * DateTime

match msg with
| text, Verified user ->
Summing up

LET THE COMPILER HELP YOU!
WHAT’S NEXT?
• The big ones: Type Providers

• For those who is crazy about types: F*
Getting Started:

• The F# Software Foundation: http://fsharp.org/
• Try F# in your browser: http://www.tryfsharp.org/
• Snippets: http://www.fssnip.net/

• Join Twitter discussions: #fsharp
QUESTIONS?

More Related Content

Similar to [F#] Dev Life's Little Pleasures

Verilog Lecture3 hust 2014
Verilog Lecture3 hust 2014Verilog Lecture3 hust 2014
Verilog Lecture3 hust 2014
Béo Tú
 
Introduction to mysql part 3
Introduction to mysql part 3Introduction to mysql part 3
10 Billion a Day, 100 Milliseconds Per: Monitoring Real-Time Bidding at AdRoll
10 Billion a Day, 100 Milliseconds Per: Monitoring Real-Time Bidding at AdRoll10 Billion a Day, 100 Milliseconds Per: Monitoring Real-Time Bidding at AdRoll
10 Billion a Day, 100 Milliseconds Per: Monitoring Real-Time Bidding at AdRoll
Brian Troutwine
 
The Ring programming language version 1.7 book - Part 10 of 196
The Ring programming language version 1.7 book - Part 10 of 196The Ring programming language version 1.7 book - Part 10 of 196
The Ring programming language version 1.7 book - Part 10 of 196
Mahmoud Samir Fayed
 
MySQL Stored Procedures: Building High Performance Web Applications
MySQL Stored Procedures: Building High Performance Web ApplicationsMySQL Stored Procedures: Building High Performance Web Applications
MySQL Stored Procedures: Building High Performance Web Applications
OSSCube
 
Robots, Small Molecules & R
Robots, Small Molecules & RRobots, Small Molecules & R
Robots, Small Molecules & R
Rajarshi Guha
 
Quantitative finance 101
Quantitative finance 101Quantitative finance 101
Quantitative finance 101
Martin Froehler
 
Quantitative finance 101
Quantitative finance 101Quantitative finance 101
Quantitative finance 101
Martin Froehler
 
Building financial systems in scala
Building financial systems in scalaBuilding financial systems in scala
Building financial systems in scala
oxbow_lakes
 
The Ring programming language version 1.6 book - Part 9 of 189
The Ring programming language version 1.6 book - Part 9 of 189The Ring programming language version 1.6 book - Part 9 of 189
The Ring programming language version 1.6 book - Part 9 of 189
Mahmoud Samir Fayed
 
Array&pointer
Array&pointerArray&pointer
Code optimization
Code optimization Code optimization
Code optimization
Code optimization Code optimization
Testing in the World of Functional Programming
Testing in the World of Functional ProgrammingTesting in the World of Functional Programming
Testing in the World of Functional Programming
Luka Jacobowitz
 
Pl sql guide
Pl sql guidePl sql guide
Pl sql guide
Vinay Kumar
 
Shift-Left Testing: QA in a DevOps World by David Laulusa
Shift-Left Testing: QA in a DevOps World by David LaulusaShift-Left Testing: QA in a DevOps World by David Laulusa
Shift-Left Testing: QA in a DevOps World by David Laulusa
QA or the Highway
 
Javascript Memory leaks and Performance & Angular
Javascript Memory leaks and Performance & AngularJavascript Memory leaks and Performance & Angular
Javascript Memory leaks and Performance & Angular
Erik Guzman
 
Matlab Workshop Presentation
Matlab Workshop PresentationMatlab Workshop Presentation
Matlab Workshop Presentation
Jairo Maldonado-Contreras
 
SOLID, DRY, SLAP design principles
SOLID, DRY, SLAP design principlesSOLID, DRY, SLAP design principles
SOLID, DRY, SLAP design principles
Sergey Karpushin
 
2. overview of c#
2. overview of c#2. overview of c#
2. overview of c#
Rohit Rao
 

Similar to [F#] Dev Life's Little Pleasures (20)

Verilog Lecture3 hust 2014
Verilog Lecture3 hust 2014Verilog Lecture3 hust 2014
Verilog Lecture3 hust 2014
 
Introduction to mysql part 3
Introduction to mysql part 3Introduction to mysql part 3
Introduction to mysql part 3
 
10 Billion a Day, 100 Milliseconds Per: Monitoring Real-Time Bidding at AdRoll
10 Billion a Day, 100 Milliseconds Per: Monitoring Real-Time Bidding at AdRoll10 Billion a Day, 100 Milliseconds Per: Monitoring Real-Time Bidding at AdRoll
10 Billion a Day, 100 Milliseconds Per: Monitoring Real-Time Bidding at AdRoll
 
The Ring programming language version 1.7 book - Part 10 of 196
The Ring programming language version 1.7 book - Part 10 of 196The Ring programming language version 1.7 book - Part 10 of 196
The Ring programming language version 1.7 book - Part 10 of 196
 
MySQL Stored Procedures: Building High Performance Web Applications
MySQL Stored Procedures: Building High Performance Web ApplicationsMySQL Stored Procedures: Building High Performance Web Applications
MySQL Stored Procedures: Building High Performance Web Applications
 
Robots, Small Molecules & R
Robots, Small Molecules & RRobots, Small Molecules & R
Robots, Small Molecules & R
 
Quantitative finance 101
Quantitative finance 101Quantitative finance 101
Quantitative finance 101
 
Quantitative finance 101
Quantitative finance 101Quantitative finance 101
Quantitative finance 101
 
Building financial systems in scala
Building financial systems in scalaBuilding financial systems in scala
Building financial systems in scala
 
The Ring programming language version 1.6 book - Part 9 of 189
The Ring programming language version 1.6 book - Part 9 of 189The Ring programming language version 1.6 book - Part 9 of 189
The Ring programming language version 1.6 book - Part 9 of 189
 
Array&pointer
Array&pointerArray&pointer
Array&pointer
 
Code optimization
Code optimization Code optimization
Code optimization
 
Code optimization
Code optimization Code optimization
Code optimization
 
Testing in the World of Functional Programming
Testing in the World of Functional ProgrammingTesting in the World of Functional Programming
Testing in the World of Functional Programming
 
Pl sql guide
Pl sql guidePl sql guide
Pl sql guide
 
Shift-Left Testing: QA in a DevOps World by David Laulusa
Shift-Left Testing: QA in a DevOps World by David LaulusaShift-Left Testing: QA in a DevOps World by David Laulusa
Shift-Left Testing: QA in a DevOps World by David Laulusa
 
Javascript Memory leaks and Performance & Angular
Javascript Memory leaks and Performance & AngularJavascript Memory leaks and Performance & Angular
Javascript Memory leaks and Performance & Angular
 
Matlab Workshop Presentation
Matlab Workshop PresentationMatlab Workshop Presentation
Matlab Workshop Presentation
 
SOLID, DRY, SLAP design principles
SOLID, DRY, SLAP design principlesSOLID, DRY, SLAP design principles
SOLID, DRY, SLAP design principles
 
2. overview of c#
2. overview of c#2. overview of c#
2. overview of c#
 

Recently uploaded

Three New Criminal Laws in India 1 July 2024
Three New Criminal Laws in India 1 July 2024Three New Criminal Laws in India 1 July 2024
Three New Criminal Laws in India 1 July 2024
aakash malhotra
 
[Talk] Moving Beyond Spaghetti Infrastructure [AOTB] 2024-07-04.pdf
[Talk] Moving Beyond Spaghetti Infrastructure [AOTB] 2024-07-04.pdf[Talk] Moving Beyond Spaghetti Infrastructure [AOTB] 2024-07-04.pdf
[Talk] Moving Beyond Spaghetti Infrastructure [AOTB] 2024-07-04.pdf
Kief Morris
 
Calgary MuleSoft Meetup APM and IDP .pptx
Calgary MuleSoft Meetup APM and IDP .pptxCalgary MuleSoft Meetup APM and IDP .pptx
Calgary MuleSoft Meetup APM and IDP .pptx
ishalveerrandhawa1
 
IPLOOK Remote-Sensing Satellite Solution
IPLOOK Remote-Sensing Satellite SolutionIPLOOK Remote-Sensing Satellite Solution
IPLOOK Remote-Sensing Satellite Solution
IPLOOK Networks
 
BT & Neo4j: Knowledge Graphs for Critical Enterprise Systems.pptx.pdf
BT & Neo4j: Knowledge Graphs for Critical Enterprise Systems.pptx.pdfBT & Neo4j: Knowledge Graphs for Critical Enterprise Systems.pptx.pdf
BT & Neo4j: Knowledge Graphs for Critical Enterprise Systems.pptx.pdf
Neo4j
 
Use Cases & Benefits of RPA in Manufacturing in 2024.pptx
Use Cases & Benefits of RPA in Manufacturing in 2024.pptxUse Cases & Benefits of RPA in Manufacturing in 2024.pptx
Use Cases & Benefits of RPA in Manufacturing in 2024.pptx
SynapseIndia
 
Amul milk launches in US: Key details of its new products ...
Amul milk launches in US: Key details of its new products ...Amul milk launches in US: Key details of its new products ...
Amul milk launches in US: Key details of its new products ...
chetankumar9855
 
leewayhertz.com-AI agents for healthcare Applications benefits and implementa...
leewayhertz.com-AI agents for healthcare Applications benefits and implementa...leewayhertz.com-AI agents for healthcare Applications benefits and implementa...
leewayhertz.com-AI agents for healthcare Applications benefits and implementa...
alexjohnson7307
 
Girls call Kolkata 👀 XXXXXXXXXXX 👀 Rs.9.5 K Cash Payment With Room Delivery
Girls call Kolkata 👀 XXXXXXXXXXX 👀 Rs.9.5 K Cash Payment With Room Delivery Girls call Kolkata 👀 XXXXXXXXXXX 👀 Rs.9.5 K Cash Payment With Room Delivery
Girls call Kolkata 👀 XXXXXXXXXXX 👀 Rs.9.5 K Cash Payment With Room Delivery
sunilverma7884
 
(CISOPlatform Summit & SACON 2024) Digital Personal Data Protection Act.pdf
(CISOPlatform Summit & SACON 2024) Digital Personal Data Protection Act.pdf(CISOPlatform Summit & SACON 2024) Digital Personal Data Protection Act.pdf
(CISOPlatform Summit & SACON 2024) Digital Personal Data Protection Act.pdf
Priyanka Aash
 
find out more about the role of autonomous vehicles in facing global challenges
find out more about the role of autonomous vehicles in facing global challengesfind out more about the role of autonomous vehicles in facing global challenges
find out more about the role of autonomous vehicles in facing global challenges
huseindihon
 
The Rise of AI in Cybersecurity How Machine Learning Will Shape Threat Detect...
The Rise of AI in Cybersecurity How Machine Learning Will Shape Threat Detect...The Rise of AI in Cybersecurity How Machine Learning Will Shape Threat Detect...
The Rise of AI in Cybersecurity How Machine Learning Will Shape Threat Detect...
digitalxplive
 
"Mastering Graphic Design: Essential Tips and Tricks for Beginners and Profes...
"Mastering Graphic Design: Essential Tips and Tricks for Beginners and Profes..."Mastering Graphic Design: Essential Tips and Tricks for Beginners and Profes...
"Mastering Graphic Design: Essential Tips and Tricks for Beginners and Profes...
Anant Gupta
 
CHAPTER-8 COMPONENTS OF COMPUTER SYSTEM CLASS 9 CBSE
CHAPTER-8 COMPONENTS OF COMPUTER SYSTEM CLASS 9 CBSECHAPTER-8 COMPONENTS OF COMPUTER SYSTEM CLASS 9 CBSE
CHAPTER-8 COMPONENTS OF COMPUTER SYSTEM CLASS 9 CBSE
kumarjarun2010
 
Choose our Linux Web Hosting for a seamless and successful online presence
Choose our Linux Web Hosting for a seamless and successful online presenceChoose our Linux Web Hosting for a seamless and successful online presence
Choose our Linux Web Hosting for a seamless and successful online presence
rajancomputerfbd
 
July Patch Tuesday
July Patch TuesdayJuly Patch Tuesday
July Patch Tuesday
Ivanti
 
Litestack talk at Brighton 2024 (Unleashing the power of SQLite for Ruby apps)
Litestack talk at Brighton 2024 (Unleashing the power of SQLite for Ruby apps)Litestack talk at Brighton 2024 (Unleashing the power of SQLite for Ruby apps)
Litestack talk at Brighton 2024 (Unleashing the power of SQLite for Ruby apps)
Muhammad Ali
 
Feature sql server terbaru performance.pptx
Feature sql server terbaru performance.pptxFeature sql server terbaru performance.pptx
Feature sql server terbaru performance.pptx
ssuser1915fe1
 
Scaling Connections in PostgreSQL Postgres Bangalore(PGBLR) Meetup-2 - Mydbops
Scaling Connections in PostgreSQL Postgres Bangalore(PGBLR) Meetup-2 - MydbopsScaling Connections in PostgreSQL Postgres Bangalore(PGBLR) Meetup-2 - Mydbops
Scaling Connections in PostgreSQL Postgres Bangalore(PGBLR) Meetup-2 - Mydbops
Mydbops
 
How RPA Help in the Transportation and Logistics Industry.pptx
How RPA Help in the Transportation and Logistics Industry.pptxHow RPA Help in the Transportation and Logistics Industry.pptx
How RPA Help in the Transportation and Logistics Industry.pptx
SynapseIndia
 

Recently uploaded (20)

Three New Criminal Laws in India 1 July 2024
Three New Criminal Laws in India 1 July 2024Three New Criminal Laws in India 1 July 2024
Three New Criminal Laws in India 1 July 2024
 
[Talk] Moving Beyond Spaghetti Infrastructure [AOTB] 2024-07-04.pdf
[Talk] Moving Beyond Spaghetti Infrastructure [AOTB] 2024-07-04.pdf[Talk] Moving Beyond Spaghetti Infrastructure [AOTB] 2024-07-04.pdf
[Talk] Moving Beyond Spaghetti Infrastructure [AOTB] 2024-07-04.pdf
 
Calgary MuleSoft Meetup APM and IDP .pptx
Calgary MuleSoft Meetup APM and IDP .pptxCalgary MuleSoft Meetup APM and IDP .pptx
Calgary MuleSoft Meetup APM and IDP .pptx
 
IPLOOK Remote-Sensing Satellite Solution
IPLOOK Remote-Sensing Satellite SolutionIPLOOK Remote-Sensing Satellite Solution
IPLOOK Remote-Sensing Satellite Solution
 
BT & Neo4j: Knowledge Graphs for Critical Enterprise Systems.pptx.pdf
BT & Neo4j: Knowledge Graphs for Critical Enterprise Systems.pptx.pdfBT & Neo4j: Knowledge Graphs for Critical Enterprise Systems.pptx.pdf
BT & Neo4j: Knowledge Graphs for Critical Enterprise Systems.pptx.pdf
 
Use Cases & Benefits of RPA in Manufacturing in 2024.pptx
Use Cases & Benefits of RPA in Manufacturing in 2024.pptxUse Cases & Benefits of RPA in Manufacturing in 2024.pptx
Use Cases & Benefits of RPA in Manufacturing in 2024.pptx
 
Amul milk launches in US: Key details of its new products ...
Amul milk launches in US: Key details of its new products ...Amul milk launches in US: Key details of its new products ...
Amul milk launches in US: Key details of its new products ...
 
leewayhertz.com-AI agents for healthcare Applications benefits and implementa...
leewayhertz.com-AI agents for healthcare Applications benefits and implementa...leewayhertz.com-AI agents for healthcare Applications benefits and implementa...
leewayhertz.com-AI agents for healthcare Applications benefits and implementa...
 
Girls call Kolkata 👀 XXXXXXXXXXX 👀 Rs.9.5 K Cash Payment With Room Delivery
Girls call Kolkata 👀 XXXXXXXXXXX 👀 Rs.9.5 K Cash Payment With Room Delivery Girls call Kolkata 👀 XXXXXXXXXXX 👀 Rs.9.5 K Cash Payment With Room Delivery
Girls call Kolkata 👀 XXXXXXXXXXX 👀 Rs.9.5 K Cash Payment With Room Delivery
 
(CISOPlatform Summit & SACON 2024) Digital Personal Data Protection Act.pdf
(CISOPlatform Summit & SACON 2024) Digital Personal Data Protection Act.pdf(CISOPlatform Summit & SACON 2024) Digital Personal Data Protection Act.pdf
(CISOPlatform Summit & SACON 2024) Digital Personal Data Protection Act.pdf
 
find out more about the role of autonomous vehicles in facing global challenges
find out more about the role of autonomous vehicles in facing global challengesfind out more about the role of autonomous vehicles in facing global challenges
find out more about the role of autonomous vehicles in facing global challenges
 
The Rise of AI in Cybersecurity How Machine Learning Will Shape Threat Detect...
The Rise of AI in Cybersecurity How Machine Learning Will Shape Threat Detect...The Rise of AI in Cybersecurity How Machine Learning Will Shape Threat Detect...
The Rise of AI in Cybersecurity How Machine Learning Will Shape Threat Detect...
 
"Mastering Graphic Design: Essential Tips and Tricks for Beginners and Profes...
"Mastering Graphic Design: Essential Tips and Tricks for Beginners and Profes..."Mastering Graphic Design: Essential Tips and Tricks for Beginners and Profes...
"Mastering Graphic Design: Essential Tips and Tricks for Beginners and Profes...
 
CHAPTER-8 COMPONENTS OF COMPUTER SYSTEM CLASS 9 CBSE
CHAPTER-8 COMPONENTS OF COMPUTER SYSTEM CLASS 9 CBSECHAPTER-8 COMPONENTS OF COMPUTER SYSTEM CLASS 9 CBSE
CHAPTER-8 COMPONENTS OF COMPUTER SYSTEM CLASS 9 CBSE
 
Choose our Linux Web Hosting for a seamless and successful online presence
Choose our Linux Web Hosting for a seamless and successful online presenceChoose our Linux Web Hosting for a seamless and successful online presence
Choose our Linux Web Hosting for a seamless and successful online presence
 
July Patch Tuesday
July Patch TuesdayJuly Patch Tuesday
July Patch Tuesday
 
Litestack talk at Brighton 2024 (Unleashing the power of SQLite for Ruby apps)
Litestack talk at Brighton 2024 (Unleashing the power of SQLite for Ruby apps)Litestack talk at Brighton 2024 (Unleashing the power of SQLite for Ruby apps)
Litestack talk at Brighton 2024 (Unleashing the power of SQLite for Ruby apps)
 
Feature sql server terbaru performance.pptx
Feature sql server terbaru performance.pptxFeature sql server terbaru performance.pptx
Feature sql server terbaru performance.pptx
 
Scaling Connections in PostgreSQL Postgres Bangalore(PGBLR) Meetup-2 - Mydbops
Scaling Connections in PostgreSQL Postgres Bangalore(PGBLR) Meetup-2 - MydbopsScaling Connections in PostgreSQL Postgres Bangalore(PGBLR) Meetup-2 - Mydbops
Scaling Connections in PostgreSQL Postgres Bangalore(PGBLR) Meetup-2 - Mydbops
 
How RPA Help in the Transportation and Logistics Industry.pptx
How RPA Help in the Transportation and Logistics Industry.pptxHow RPA Help in the Transportation and Logistics Industry.pptx
How RPA Help in the Transportation and Logistics Industry.pptx
 

[F#] Dev Life's Little Pleasures

  • 1. [F#] DEV LIFE’S LITTLE PLEASURES Natallie Baikevich, F# enthusiast and financial dev @lu_a_jalla
  • 3. THINGS TO CARE ABOUT: • Correctness • Efficiency • Safety • Conciseness • Simplicity
  • 4. Based on true stories WHEN YOU MEET THE REAL WORLD…
  • 5. #1. THE SPREADSHEET How to gain by selling £17mln and buying $10mln? • Buy $10mln • Sell £16mln • Spot Rate = 1.6 • GBP/USD =1.5945 • RGL = 88000 Pretty nice, isn’t it?
  • 6. #1. THE CODE let buyAmount, sellAmount = 10000000.0, 16000000.0 let spotRate = sellAmount / buyAmount // 1.6 let exchRate = 1.5945 let rgl amount spotRate exchRate = amount * (spotRate - exchRate) rgl sellAmount spotRate exchRate |> printfn "%A" // 88000.0
  • 7. UNITS OF MEASURE [<Measure>] type USD [<Measure>] type GBP let buyAmount, sellAmount = 10000000.0<USD>, 16000000.0<GBP> let spotRate = sellAmount / buyAmount let exchRate = 1.5945<USD/GBP> let rgl amount spotRate exchRate = amount * (spotRate – exchRate)
  • 8. UNITS OF MEASURE - FIXED [<Measure>] type USD [<Measure>] type GBP let buyAmount, sellAmount = 10000000.0<USD>, 16000000.0<GBP> let spotRate = buyAmount / sellAmount let exchRate = 1.5945<USD/GBP> let rgl amount spotRate exchRate = amount * (spotRate – exchRate) // -15512000.0
  • 9. #2. THE OPPORTUNITIES The same trick works for yield quotes! Get a 100 times greater coupon. Or smaller. Whatever. • 1 = 100% • 1 % = 100 bp … Or add <pct> and <bp>.
  • 10. The copy-paste is still around, so GO FOR GENERICS!
  • 11. WHAT MAKES A PROGRAM WRITE ITSELF?
  • 12. #3. THE BOILERPLATE DevExpress layouts: Save/Restore • DockManager: public void SaveLayoutToStream(Stream stream); public void RestoreLayoutFromStream(Stream stream); • Grid: public void SaveLayoutToStream(Stream stream); public void RestoreLayoutFromStream(Stream stream);
  • 13. #4. LOADING STOCK DATA FROM YAHOO type Price = { “Oct 10, 2013“ Date: DateTime parse DateTime “33.31” parse float “33.38” parse float … Open: float … High: float Low: float Close: float Volume: float AdjClose: float option }
  • 14. MEET GENERIC RESTRICTIONS let inline tryParse str = let mutable res = Unchecked.defaultof<_> let ok = (^a: (static member TryParse: string * byref< ^a > -> bool) (str, &res)) res match s.Split ',' with | [| date; o; h; l; c; v; adj |] -> Some { Date = tryParse date; Open = tryParse o; High = tryParse h; }
  • 15. Good and Evil MUTABILITY / STATE / MORE
  • 17. #6. JUST CHECKING UPDATES .NET List [ResizeArray] foreach(var update in updatesList) { doSomethingWith(update); } System.InvalidOperationException: Collection was modified; enumeration operation may not execute.
  • 18. WHEN CHOOSE WHAT Immutable Mutable • Safe • Simple to read • Performance optimizations (e.g. Dictionary vs Map) • Efficient data structures: • Interop • Check fsharpx • F# Core extensions (ExtCore)
  • 19. HOW • let for values • types: tuples, records, DUs • core & community collections and data structures (list, map, set and more) Scala F# • val • let • var • let mutable
  • 20. The billion dollar mistake and co MAKE ILLEGAL STATES UNREPRESENTABLE
  • 21. (NULL) We have an Option to avoid nulls!
  • 22. #8. SEND A MESSAGE match status with | Pending -> | Verified -> doSomething() Pattern matching & Discriminated Unions FTW! FS0025: Incomplete pattern matches on this expression. For example, the value '(_,Released)’ type Status = | Pending | Verified of User | Released of User * DateTime match msg with | text, Verified user ->
  • 23. Summing up LET THE COMPILER HELP YOU!
  • 24. WHAT’S NEXT? • The big ones: Type Providers • For those who is crazy about types: F* Getting Started: • The F# Software Foundation: http://fsharp.org/ • Try F# in your browser: http://www.tryfsharp.org/ • Snippets: http://www.fssnip.net/ • Join Twitter discussions: #fsharp