SlideShare a Scribd company logo
Welcome
F# |> Introduction
All characters appearing in this work are fictitious.
Any resemblance to real persons, living or dead, is purely coincidental.
F# is awesome
F# syntax example
let add x y = x + y
let x = 5
let username = "rowan.williams"
let pages = [10; 20; 50; 100]
x = x + 1 //false (and does not make sense)
F# vs. C#
C#:
namespace Math
{
public static class Helpers
{
public static int Add(int x, int y)
{
return x + y;
}
}
}
F#:
let add x y = x + y
F# syntax: functions
let add x y = x + y
let square x = x * x
let squareSum x y =
let sum = add x y
square sum
let squareRes func x y =
let result = func x y
square result
add 2 3 //5
square 5 //25
squareSum 2 3 //25
squareRes add 2 3 //25
squareRes (*) 2 3 //36
let changePrice p =
let price = if p < 0 then 0 else p
price * 0.1
F# type inference
// add : int -> int -> int
let add x y = x + y
Func<int, int, int>
// add5 : int -> int
let add5 = add 5
let add7 = (+) 7
add5 10 // returns 15
add7 10 // returns 17
F# syntax: partial application
//find: string -> string -> obj
let find parent elem = …
//findInBody: string -> obj
let findInBody = find "body"
//findInView: string -> obj
let findInView = find "#main-view"
find "body" "#btn"
findInBody "#btn"
findInView "#save"
//writeTo: string -> string -> unit
let writeTo elem text = …
let setUsername = writeTo "#username"
let setPassword = writeTo "#password"
let setSearch = writeTo "#global-search"
writeTo "#username" "sb"
setUsername "mh.incite"
setPassword "Password1"
setSearch "test"
F# syntax: unit
//like ‘void’ but is a real value!
let useless () = true //useless: unit -> bool
() unit
let useless2() = () //useless2: unit -> unit
let doSomething text =
printfn "doing %s" text
()
//doSomething: string -> unit
let doSomething text =
printfn "doing %s" text
let doSomething = printfn "doing %s"
//or we can do this
//or just this
F# syntax: Tuples
let internal = (63, "internal")
let external = 64, "external"
//internal: int * string
let lang = "F#", "functional", 5 //lang: string * string * int
let (typeId, typeName) = internal
let name, kind, years = lang
// typeId: int = 63
// typeName: string = "internal"
// name: string = "F#"
// kind: string = "functional"
// years: int = 5
internal = external
external > internal
// false
// true
F# syntax: Lists
let newList = 101 :: ints
// [1; 2; 3] = 1 :: 2 :: 3 :: []
// [101; 1; 2; 3; 4; 5]
let x :: xs = ints
let evens xs =
let isEven x = x%2 = 0
List.filter isEven xs
// x: int = 1
// xs: int list = [2; 3; 4; 5]
// evens: int list -> int list
let empty = []
let ints = [1..5]
let names = [(1,"Rong"); (2,"Jose")]
let chars = [‘a’..’g’]
let odds = [1..2..10]
// empty: ‘a list
// [1; 2; 3; 4; 5]
// [(1, "Rong"); (2, "Jose")]
// [‘a’; ‘b’; ‘c’...]
// [1; 3; 5; 7; 9]
F# syntax: List Comprehension (generators)
let squares = [for i in odds -> x * x] // [1; 9; 25;]
[for x in odds do
for y in evens do
yield x * y]
// [2; 4; 6; 12; 10; 20]
let odds = [1..2..5]
let evens = [2..2..5]
let chars = [‘a’; ‘b’]
// [1; 3; 5;]
// [2; 4]
// [‘a’; ‘b’]
[for i in evens do
for c in chars -> (i, c)]
[
(2, 'a')
(2, 'b')
(4, 'a')
(4, 'b')
]
[for x in 1..5 do if x%2=0 then yield x] // [2; 4]
TAB FOUR TAB FIVE
F# goodness: Pipeline
let sumOfSquares n =
List.sum (List.map square [1..n])
let sumOfSquares n =
[1..n] |> List.map square |> List.sum
let sumOfSquaresOfEvens n =
let isEven x = x%2 = 0
[1..n]
|> List.filter isEven
|> List.map square
|> List.sum
TAB FIVE
F# goodness: Pipeline
let result =
httpGet url
|> getContent
|> stripHtml
|> spellcheck
let url = "http://someServer/api/data"
let response = httpGet url
let content = getContent response
let plainText = stripHtml content
let result = spellcheck plainText
let response = httpGet url
let result = spellcheck (stripHtml (getContent response))
TAB TWO TAB FIVE
F# syntax: Records
type Person = {FirstName: string; LastName: string; Age: int}
type Address = {Street: string; City: string}
let rowan = {FirstName="Rowan"; LastName="Williams"; Age=37}
let olderRowan = {rowan with Age=38}
olderRowan = rowan //false
olderRowan > rowan //true
TAB TWO
TAB FOUR TAB FIVE
F# syntax: Discriminated Unions
type Response =
| Success of int * string
| Failure of string
type Command =
| CreateUser of Person * Role
| UpdateUser of int * Person
| SetRole of int * Role
| DeleteUser of int
//many, many lines of C# code
let makeRowan = CreateUser(rowan, Visitor)
let ageRowan = UpdateUser(1, olderRowan)
type Role = Admin | Member | Visitor
TAB FIVE
F# syntax: Discriminated Unions
type WorkingUnit =
| Worker of Person
| Team of WorkingUnit list
let jsGuy = Worker {First="Troy"; Last="Wilson"}
let buildGuy = Worker {First="Murtuz"; Last="Chalabov"}
let teamAwesome = Team [jsGuy; buildGuy]
//many, many lines of C# code
F# syntax: Pattern Matching
let manageWorkers workforce =
match workforce with
| Worker {FirstName="Jimmy"} -> printfn "Superman!"
| Worker man -> printfn "Just a man: %s" man.FirstName
| Team people -> printfn "%i people" (List.length people)
let checkList lst =
match lst with
| [] -> printfn "List is empty"
| [elem] -> printfn "Just one element %O" elem
| 1 :: xs -> printfn "Starts with 1"
| _ :: x :: xs -> printfn "Secons element is %O" x
| _ -> () //do nothing
F# syntax: Pattern Matching
type Role = SystemAdmin | CompanyAdmin | Member
let loginAs userRole =
//usefulness of internal functions
let login uname pwd =
setUsername uname
setPassword pwd
click "#btnLogin"
match userRole with
| SystemAdmin -> login "mh.incite" "Password1"
| CompanyAdmin -> login "trudi.wilson" "Password1"
| Member -> login "ivan.chen" "Password1"
F# syntax: Option type
//Already defined in F#
type Option<‘a> =
| Some of ‘a
| None
goodResp: string option
badResp: string option
let goodResp = Some "Hello F#"
let badResp = None
let printResponse response =
match response with
| Some data -> printfn "%O" data
| None -> printfn "Got nothing :("
let clickSave() =
let elem = findElement "#btnSave"
match elem with
| Some btn -> click btn
| None -> ()
clickSave: unit -> unit
printResp: 'a option -> unit
Now when you know F#
let success =
F# |> Canopy |> Selenium
What is Canopy
• Easy to use (written in F#)
• Works on top of Selenium
• Works with many browsers (IE, Chrome, Firefox, Safari, Android)
• Developers-friendly
OK, now…
Show me the code!

More Related Content

What's hot

4 operators, expressions &amp; statements
4  operators, expressions &amp; statements4  operators, expressions &amp; statements
4 operators, expressions &amp; statements
MomenMostafa
 
7 functions
7  functions7  functions
7 functions
MomenMostafa
 
Stl algorithm-Basic types
Stl algorithm-Basic typesStl algorithm-Basic types
Stl algorithm-Basic types
mohamed sikander
 
C interview question answer 2
C interview question answer 2C interview question answer 2
C interview question answer 2
Amit Kapoor
 
C++ Programming - 11th Study
C++ Programming - 11th StudyC++ Programming - 11th Study
C++ Programming - 11th Study
Chris Ohk
 
Function recap
Function recapFunction recap
Function recap
alish sha
 
C++ ARRAY WITH EXAMPLES
C++ ARRAY WITH EXAMPLESC++ ARRAY WITH EXAMPLES
C++ ARRAY WITH EXAMPLES
Farhan Ab Rahman
 
OPERATOR IN PYTHON-PART2
OPERATOR IN PYTHON-PART2OPERATOR IN PYTHON-PART2
OPERATOR IN PYTHON-PART2
vikram mahendra
 
Arrow 101 - Kotlin funcional com Arrow
Arrow 101 - Kotlin funcional com ArrowArrow 101 - Kotlin funcional com Arrow
Arrow 101 - Kotlin funcional com Arrow
Leandro Ferreira
 
C programming pointer
C  programming pointerC  programming pointer
C programming pointer
argusacademy
 
C++ Programming - 4th Study
C++ Programming - 4th StudyC++ Programming - 4th Study
C++ Programming - 4th Study
Chris Ohk
 
Introduction to F# for the C# developer
Introduction to F# for the C# developerIntroduction to F# for the C# developer
Introduction to F# for the C# developer
njpst8
 
8 arrays and pointers
8  arrays and pointers8  arrays and pointers
8 arrays and pointers
MomenMostafa
 
Swift 3.0 の新しい機能(のうちの9つ)
Swift 3.0 の新しい機能(のうちの9つ)Swift 3.0 の新しい機能(のうちの9つ)
Swift 3.0 の新しい機能(のうちの9つ)
Tomohiro Kumagai
 
Data Structure - 2nd Study
Data Structure - 2nd StudyData Structure - 2nd Study
Data Structure - 2nd Study
Chris Ohk
 
ML: A Strongly Typed Functional Language
ML: A Strongly Typed Functional LanguageML: A Strongly Typed Functional Language
ML: A Strongly Typed Functional Language
lijx127
 
6. function
6. function6. function
6. function
웅식 전
 
Introduction to c part 2
Introduction to c   part  2Introduction to c   part  2
C Structure and Union in C
C Structure and Union in CC Structure and Union in C

What's hot (19)

4 operators, expressions &amp; statements
4  operators, expressions &amp; statements4  operators, expressions &amp; statements
4 operators, expressions &amp; statements
 
7 functions
7  functions7  functions
7 functions
 
Stl algorithm-Basic types
Stl algorithm-Basic typesStl algorithm-Basic types
Stl algorithm-Basic types
 
C interview question answer 2
C interview question answer 2C interview question answer 2
C interview question answer 2
 
C++ Programming - 11th Study
C++ Programming - 11th StudyC++ Programming - 11th Study
C++ Programming - 11th Study
 
Function recap
Function recapFunction recap
Function recap
 
C++ ARRAY WITH EXAMPLES
C++ ARRAY WITH EXAMPLESC++ ARRAY WITH EXAMPLES
C++ ARRAY WITH EXAMPLES
 
OPERATOR IN PYTHON-PART2
OPERATOR IN PYTHON-PART2OPERATOR IN PYTHON-PART2
OPERATOR IN PYTHON-PART2
 
Arrow 101 - Kotlin funcional com Arrow
Arrow 101 - Kotlin funcional com ArrowArrow 101 - Kotlin funcional com Arrow
Arrow 101 - Kotlin funcional com Arrow
 
C programming pointer
C  programming pointerC  programming pointer
C programming pointer
 
C++ Programming - 4th Study
C++ Programming - 4th StudyC++ Programming - 4th Study
C++ Programming - 4th Study
 
Introduction to F# for the C# developer
Introduction to F# for the C# developerIntroduction to F# for the C# developer
Introduction to F# for the C# developer
 
8 arrays and pointers
8  arrays and pointers8  arrays and pointers
8 arrays and pointers
 
Swift 3.0 の新しい機能(のうちの9つ)
Swift 3.0 の新しい機能(のうちの9つ)Swift 3.0 の新しい機能(のうちの9つ)
Swift 3.0 の新しい機能(のうちの9つ)
 
Data Structure - 2nd Study
Data Structure - 2nd StudyData Structure - 2nd Study
Data Structure - 2nd Study
 
ML: A Strongly Typed Functional Language
ML: A Strongly Typed Functional LanguageML: A Strongly Typed Functional Language
ML: A Strongly Typed Functional Language
 
6. function
6. function6. function
6. function
 
Introduction to c part 2
Introduction to c   part  2Introduction to c   part  2
Introduction to c part 2
 
C Structure and Union in C
C Structure and Union in CC Structure and Union in C
C Structure and Union in C
 

Similar to F# intro

Reasonable Code With Fsharp
Reasonable Code With FsharpReasonable Code With Fsharp
Reasonable Code With Fsharp
Michael Falanga
 
仕事で使うF#
仕事で使うF#仕事で使うF#
仕事で使うF#
bleis tift
 
F# Presentation
F# PresentationF# Presentation
F# Presentation
mrkurt
 
Functional Programming in F#
Functional Programming in F#Functional Programming in F#
Functional Programming in F#
Dmitri Nesteruk
 
Python quickstart for programmers: Python Kung Fu
Python quickstart for programmers: Python Kung FuPython quickstart for programmers: Python Kung Fu
Python quickstart for programmers: Python Kung Fu
climatewarrior
 
Python
PythonPython
Python
대갑 김
 
Build a compiler in 2hrs - NCrafts Paris 2015
Build a compiler in 2hrs -  NCrafts Paris 2015Build a compiler in 2hrs -  NCrafts Paris 2015
Build a compiler in 2hrs - NCrafts Paris 2015
Phillip Trelford
 
a) Complete both insert and delete methods. If it works correctly 10.pdf
a) Complete both insert and delete methods. If it works correctly 10.pdfa) Complete both insert and delete methods. If it works correctly 10.pdf
a) Complete both insert and delete methods. If it works correctly 10.pdf
MAYANKBANSAL1981
 
GE8151 Problem Solving and Python Programming
GE8151 Problem Solving and Python ProgrammingGE8151 Problem Solving and Python Programming
GE8151 Problem Solving and Python Programming
Muthu Vinayagam
 
20191116 custom operators in swift
20191116 custom operators in swift20191116 custom operators in swift
20191116 custom operators in swift
Chiwon Song
 
03 tk2123 - pemrograman shell-2
03   tk2123 - pemrograman shell-203   tk2123 - pemrograman shell-2
03 tk2123 - pemrograman shell-2
Setia Juli Irzal Ismail
 
CSE240 Pointers
CSE240 PointersCSE240 Pointers
CSE240 Pointers
Garrett Gutierrez
 
Implementing Virtual Machines in Go & C
Implementing Virtual Machines in Go & CImplementing Virtual Machines in Go & C
Implementing Virtual Machines in Go & C
Eleanor McHugh
 
Begin with Python
Begin with PythonBegin with Python
Begin with Python
Narong Intiruk
 
Go Says WAT?
Go Says WAT?Go Says WAT?
Go Says WAT?
jonbodner
 
1.4 first class-functions
1.4 first class-functions1.4 first class-functions
1.4 first class-functions
futurespective
 
Tu1
Tu1Tu1
A Skeptics guide to functional style javascript
A Skeptics guide to functional style javascriptA Skeptics guide to functional style javascript
A Skeptics guide to functional style javascript
jonathanfmills
 
Frege is a Haskell for the JVM
Frege is a Haskell for the JVMFrege is a Haskell for the JVM
Frege is a Haskell for the JVM
jwausle
 
Swift 5.1 Language Guide Notes.pdf
Swift 5.1 Language Guide Notes.pdfSwift 5.1 Language Guide Notes.pdf
Swift 5.1 Language Guide Notes.pdf
JkPoppy
 

Similar to F# intro (20)

Reasonable Code With Fsharp
Reasonable Code With FsharpReasonable Code With Fsharp
Reasonable Code With Fsharp
 
仕事で使うF#
仕事で使うF#仕事で使うF#
仕事で使うF#
 
F# Presentation
F# PresentationF# Presentation
F# Presentation
 
Functional Programming in F#
Functional Programming in F#Functional Programming in F#
Functional Programming in F#
 
Python quickstart for programmers: Python Kung Fu
Python quickstart for programmers: Python Kung FuPython quickstart for programmers: Python Kung Fu
Python quickstart for programmers: Python Kung Fu
 
Python
PythonPython
Python
 
Build a compiler in 2hrs - NCrafts Paris 2015
Build a compiler in 2hrs -  NCrafts Paris 2015Build a compiler in 2hrs -  NCrafts Paris 2015
Build a compiler in 2hrs - NCrafts Paris 2015
 
a) Complete both insert and delete methods. If it works correctly 10.pdf
a) Complete both insert and delete methods. If it works correctly 10.pdfa) Complete both insert and delete methods. If it works correctly 10.pdf
a) Complete both insert and delete methods. If it works correctly 10.pdf
 
GE8151 Problem Solving and Python Programming
GE8151 Problem Solving and Python ProgrammingGE8151 Problem Solving and Python Programming
GE8151 Problem Solving and Python Programming
 
20191116 custom operators in swift
20191116 custom operators in swift20191116 custom operators in swift
20191116 custom operators in swift
 
03 tk2123 - pemrograman shell-2
03   tk2123 - pemrograman shell-203   tk2123 - pemrograman shell-2
03 tk2123 - pemrograman shell-2
 
CSE240 Pointers
CSE240 PointersCSE240 Pointers
CSE240 Pointers
 
Implementing Virtual Machines in Go & C
Implementing Virtual Machines in Go & CImplementing Virtual Machines in Go & C
Implementing Virtual Machines in Go & C
 
Begin with Python
Begin with PythonBegin with Python
Begin with Python
 
Go Says WAT?
Go Says WAT?Go Says WAT?
Go Says WAT?
 
1.4 first class-functions
1.4 first class-functions1.4 first class-functions
1.4 first class-functions
 
Tu1
Tu1Tu1
Tu1
 
A Skeptics guide to functional style javascript
A Skeptics guide to functional style javascriptA Skeptics guide to functional style javascript
A Skeptics guide to functional style javascript
 
Frege is a Haskell for the JVM
Frege is a Haskell for the JVMFrege is a Haskell for the JVM
Frege is a Haskell for the JVM
 
Swift 5.1 Language Guide Notes.pdf
Swift 5.1 Language Guide Notes.pdfSwift 5.1 Language Guide Notes.pdf
Swift 5.1 Language Guide Notes.pdf
 

Recently uploaded

Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
Safe Software
 
Hand Rolled Applicative User Validation Code Kata
Hand Rolled Applicative User ValidationCode KataHand Rolled Applicative User ValidationCode Kata
Hand Rolled Applicative User Validation Code Kata
Philip Schwarz
 
What is Master Data Management by PiLog Group
What is Master Data Management by PiLog GroupWhat is Master Data Management by PiLog Group
What is Master Data Management by PiLog Group
aymanquadri279
 
Graspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code AnalysisGraspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code Analysis
Aftab Hussain
 
2024 eCommerceDays Toulouse - Sylius 2.0.pdf
2024 eCommerceDays Toulouse - Sylius 2.0.pdf2024 eCommerceDays Toulouse - Sylius 2.0.pdf
2024 eCommerceDays Toulouse - Sylius 2.0.pdf
Łukasz Chruściel
 
Fundamentals of Programming and Language Processors
Fundamentals of Programming and Language ProcessorsFundamentals of Programming and Language Processors
Fundamentals of Programming and Language Processors
Rakesh Kumar R
 
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdfAutomated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
timtebeek1
 
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
mz5nrf0n
 
DDS-Security 1.2 - What's New? Stronger security for long-running systems
DDS-Security 1.2 - What's New? Stronger security for long-running systemsDDS-Security 1.2 - What's New? Stronger security for long-running systems
DDS-Security 1.2 - What's New? Stronger security for long-running systems
Gerardo Pardo-Castellote
 
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Łukasz Chruściel
 
Using Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional SafetyUsing Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional Safety
Ayan Halder
 
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit ParisNeo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j
 
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Crescat
 
socradar-q1-2024-aviation-industry-report.pdf
socradar-q1-2024-aviation-industry-report.pdfsocradar-q1-2024-aviation-industry-report.pdf
socradar-q1-2024-aviation-industry-report.pdf
SOCRadar
 
openEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain SecurityopenEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain Security
Shane Coughlan
 
ALGIT - Assembly Line for Green IT - Numbers, Data, Facts
ALGIT - Assembly Line for Green IT - Numbers, Data, FactsALGIT - Assembly Line for Green IT - Numbers, Data, Facts
ALGIT - Assembly Line for Green IT - Numbers, Data, Facts
Green Software Development
 
UI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
UI5con 2024 - Keynote: Latest News about UI5 and it’s EcosystemUI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
UI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
Peter Muessig
 
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI AppAI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
Google
 
Oracle 23c New Features For DBAs and Developers.pptx
Oracle 23c New Features For DBAs and Developers.pptxOracle 23c New Features For DBAs and Developers.pptx
Oracle 23c New Features For DBAs and Developers.pptx
Remote DBA Services
 
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling ExtensionsUI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
Peter Muessig
 

Recently uploaded (20)

Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
 
Hand Rolled Applicative User Validation Code Kata
Hand Rolled Applicative User ValidationCode KataHand Rolled Applicative User ValidationCode Kata
Hand Rolled Applicative User Validation Code Kata
 
What is Master Data Management by PiLog Group
What is Master Data Management by PiLog GroupWhat is Master Data Management by PiLog Group
What is Master Data Management by PiLog Group
 
Graspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code AnalysisGraspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code Analysis
 
2024 eCommerceDays Toulouse - Sylius 2.0.pdf
2024 eCommerceDays Toulouse - Sylius 2.0.pdf2024 eCommerceDays Toulouse - Sylius 2.0.pdf
2024 eCommerceDays Toulouse - Sylius 2.0.pdf
 
Fundamentals of Programming and Language Processors
Fundamentals of Programming and Language ProcessorsFundamentals of Programming and Language Processors
Fundamentals of Programming and Language Processors
 
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdfAutomated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
 
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
 
DDS-Security 1.2 - What's New? Stronger security for long-running systems
DDS-Security 1.2 - What's New? Stronger security for long-running systemsDDS-Security 1.2 - What's New? Stronger security for long-running systems
DDS-Security 1.2 - What's New? Stronger security for long-running systems
 
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
 
Using Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional SafetyUsing Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional Safety
 
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit ParisNeo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
 
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
 
socradar-q1-2024-aviation-industry-report.pdf
socradar-q1-2024-aviation-industry-report.pdfsocradar-q1-2024-aviation-industry-report.pdf
socradar-q1-2024-aviation-industry-report.pdf
 
openEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain SecurityopenEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain Security
 
ALGIT - Assembly Line for Green IT - Numbers, Data, Facts
ALGIT - Assembly Line for Green IT - Numbers, Data, FactsALGIT - Assembly Line for Green IT - Numbers, Data, Facts
ALGIT - Assembly Line for Green IT - Numbers, Data, Facts
 
UI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
UI5con 2024 - Keynote: Latest News about UI5 and it’s EcosystemUI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
UI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
 
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI AppAI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
 
Oracle 23c New Features For DBAs and Developers.pptx
Oracle 23c New Features For DBAs and Developers.pptxOracle 23c New Features For DBAs and Developers.pptx
Oracle 23c New Features For DBAs and Developers.pptx
 
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling ExtensionsUI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
 

F# intro

  • 1. Welcome F# |> Introduction All characters appearing in this work are fictitious. Any resemblance to real persons, living or dead, is purely coincidental.
  • 3. F# syntax example let add x y = x + y let x = 5 let username = "rowan.williams" let pages = [10; 20; 50; 100] x = x + 1 //false (and does not make sense)
  • 4. F# vs. C# C#: namespace Math { public static class Helpers { public static int Add(int x, int y) { return x + y; } } } F#: let add x y = x + y
  • 5. F# syntax: functions let add x y = x + y let square x = x * x let squareSum x y = let sum = add x y square sum let squareRes func x y = let result = func x y square result add 2 3 //5 square 5 //25 squareSum 2 3 //25 squareRes add 2 3 //25 squareRes (*) 2 3 //36 let changePrice p = let price = if p < 0 then 0 else p price * 0.1
  • 6. F# type inference // add : int -> int -> int let add x y = x + y Func<int, int, int> // add5 : int -> int let add5 = add 5 let add7 = (+) 7 add5 10 // returns 15 add7 10 // returns 17
  • 7. F# syntax: partial application //find: string -> string -> obj let find parent elem = … //findInBody: string -> obj let findInBody = find "body" //findInView: string -> obj let findInView = find "#main-view" find "body" "#btn" findInBody "#btn" findInView "#save" //writeTo: string -> string -> unit let writeTo elem text = … let setUsername = writeTo "#username" let setPassword = writeTo "#password" let setSearch = writeTo "#global-search" writeTo "#username" "sb" setUsername "mh.incite" setPassword "Password1" setSearch "test"
  • 8. F# syntax: unit //like ‘void’ but is a real value! let useless () = true //useless: unit -> bool () unit let useless2() = () //useless2: unit -> unit let doSomething text = printfn "doing %s" text () //doSomething: string -> unit let doSomething text = printfn "doing %s" text let doSomething = printfn "doing %s" //or we can do this //or just this
  • 9. F# syntax: Tuples let internal = (63, "internal") let external = 64, "external" //internal: int * string let lang = "F#", "functional", 5 //lang: string * string * int let (typeId, typeName) = internal let name, kind, years = lang // typeId: int = 63 // typeName: string = "internal" // name: string = "F#" // kind: string = "functional" // years: int = 5 internal = external external > internal // false // true
  • 10. F# syntax: Lists let newList = 101 :: ints // [1; 2; 3] = 1 :: 2 :: 3 :: [] // [101; 1; 2; 3; 4; 5] let x :: xs = ints let evens xs = let isEven x = x%2 = 0 List.filter isEven xs // x: int = 1 // xs: int list = [2; 3; 4; 5] // evens: int list -> int list let empty = [] let ints = [1..5] let names = [(1,"Rong"); (2,"Jose")] let chars = [‘a’..’g’] let odds = [1..2..10] // empty: ‘a list // [1; 2; 3; 4; 5] // [(1, "Rong"); (2, "Jose")] // [‘a’; ‘b’; ‘c’...] // [1; 3; 5; 7; 9]
  • 11. F# syntax: List Comprehension (generators) let squares = [for i in odds -> x * x] // [1; 9; 25;] [for x in odds do for y in evens do yield x * y] // [2; 4; 6; 12; 10; 20] let odds = [1..2..5] let evens = [2..2..5] let chars = [‘a’; ‘b’] // [1; 3; 5;] // [2; 4] // [‘a’; ‘b’] [for i in evens do for c in chars -> (i, c)] [ (2, 'a') (2, 'b') (4, 'a') (4, 'b') ] [for x in 1..5 do if x%2=0 then yield x] // [2; 4]
  • 12. TAB FOUR TAB FIVE F# goodness: Pipeline let sumOfSquares n = List.sum (List.map square [1..n]) let sumOfSquares n = [1..n] |> List.map square |> List.sum let sumOfSquaresOfEvens n = let isEven x = x%2 = 0 [1..n] |> List.filter isEven |> List.map square |> List.sum
  • 13. TAB FIVE F# goodness: Pipeline let result = httpGet url |> getContent |> stripHtml |> spellcheck let url = "http://someServer/api/data" let response = httpGet url let content = getContent response let plainText = stripHtml content let result = spellcheck plainText let response = httpGet url let result = spellcheck (stripHtml (getContent response))
  • 14. TAB TWO TAB FIVE F# syntax: Records type Person = {FirstName: string; LastName: string; Age: int} type Address = {Street: string; City: string} let rowan = {FirstName="Rowan"; LastName="Williams"; Age=37} let olderRowan = {rowan with Age=38} olderRowan = rowan //false olderRowan > rowan //true
  • 15. TAB TWO TAB FOUR TAB FIVE F# syntax: Discriminated Unions type Response = | Success of int * string | Failure of string type Command = | CreateUser of Person * Role | UpdateUser of int * Person | SetRole of int * Role | DeleteUser of int //many, many lines of C# code let makeRowan = CreateUser(rowan, Visitor) let ageRowan = UpdateUser(1, olderRowan) type Role = Admin | Member | Visitor
  • 16. TAB FIVE F# syntax: Discriminated Unions type WorkingUnit = | Worker of Person | Team of WorkingUnit list let jsGuy = Worker {First="Troy"; Last="Wilson"} let buildGuy = Worker {First="Murtuz"; Last="Chalabov"} let teamAwesome = Team [jsGuy; buildGuy] //many, many lines of C# code
  • 17. F# syntax: Pattern Matching let manageWorkers workforce = match workforce with | Worker {FirstName="Jimmy"} -> printfn "Superman!" | Worker man -> printfn "Just a man: %s" man.FirstName | Team people -> printfn "%i people" (List.length people) let checkList lst = match lst with | [] -> printfn "List is empty" | [elem] -> printfn "Just one element %O" elem | 1 :: xs -> printfn "Starts with 1" | _ :: x :: xs -> printfn "Secons element is %O" x | _ -> () //do nothing
  • 18. F# syntax: Pattern Matching type Role = SystemAdmin | CompanyAdmin | Member let loginAs userRole = //usefulness of internal functions let login uname pwd = setUsername uname setPassword pwd click "#btnLogin" match userRole with | SystemAdmin -> login "mh.incite" "Password1" | CompanyAdmin -> login "trudi.wilson" "Password1" | Member -> login "ivan.chen" "Password1"
  • 19. F# syntax: Option type //Already defined in F# type Option<‘a> = | Some of ‘a | None goodResp: string option badResp: string option let goodResp = Some "Hello F#" let badResp = None let printResponse response = match response with | Some data -> printfn "%O" data | None -> printfn "Got nothing :(" let clickSave() = let elem = findElement "#btnSave" match elem with | Some btn -> click btn | None -> () clickSave: unit -> unit printResp: 'a option -> unit
  • 20. Now when you know F# let success = F# |> Canopy |> Selenium
  • 21. What is Canopy • Easy to use (written in F#) • Works on top of Selenium • Works with many browsers (IE, Chrome, Firefox, Safari, Android) • Developers-friendly
  • 22. OK, now… Show me the code!