SlideShare ist ein Scribd-Unternehmen logo
1 von 13
Functional
Programming
  {   F# Programming Techniques
   Oleksiy Tereshchenko
       Principal consultant at Neudesic
       10 years experience in Custom Application
        Development and Connected Systems




About Presenter
   Building Blocks
          Tuples
          Discriminated Unions
          Lists
          Stack (as example of OOD)
          Recursive Functions
    Assembling Parser
    Demo

   & Questions




Agenda
   Tuples
         Discriminated Unions
         Lists
         Stack
         Recursive Functions




Building Blocks
let makeAndYear = ("Ford", 2011)

    type CarMakeAndYear = string * int


    let (make,year) : CarMakeAndYear = makeAndYear

    Debug.WriteLine(make)
    Debug.WriteLine(year)

    match makeAndYear with
      | ("Honda", 2010) -> Debug.WriteLine("Matched Honda 2010")
      | ("Honda", year) -> Debug.WriteLine("Matched Honda " +
    year.ToString())
      | ( _ , _ ) -> Debug.WriteLine("This is not Honda")




Tuples
type Operation = Plus | Minus | Multiply | Devision


type Value = IntValue of int

type ParseTree = Leaf of Value | Node of ParseTree * Operation * ParseTree

let plusOperation = Plus

let treeLeafLeft = Leaf(IntValue(100))
let treeLeafRight = Leaf(IntValue(100))

let treeNode = Node(treeLeafLeft, Plus, treeLeafRight)

let parentTree = Node(treeNode, Multiply, Leaf(IntValue(2)))




Discriminated Unions
let listOfNumbersA = [1;2;3]
        let listOfNumbersB = [1..10]

        let listOfNumbersAB = listOfNumbersA @ listOfNumbersB
        let listOfNumbersC = 50 :: listOfNumbersA

        match listOfNumbersA with
        |intValue :: listOfNumbersD -> Debug.WriteLine(intValue)
        |_-> ()


        let head = listOfNumbersB.Head




Lists
type StackNode<'a> = Nil | StackNode of 'a * StackNode<'a>

    type Stack<'a>() =

        let mutable stackNode : StackNode<'a> = Nil

        member self.Node : StackNode<'a> = stackNode

        member self.Push( leaf : 'a ) =
         stackNode <- StackNode(leaf, self.Node)

        member self.Pop() : 'a option =
         match stackNode with
         | Nil ->
               None
         | StackNode(leaf,tailNode) ->
               stackNode <- tailNode; Some(leaf);




Stack
let rec SumArithmeticProgression( x) =
       if x < 1 then
          x
        else
          x + SumArithmeticProgression ( (x-1))


    let rec SumArithmeticProgressionTailRecursion ( x, acc) =
       if x < 1 then
          acc
        else
          SumArithmeticProgressionTailRecursion ( (x-1), (acc + x))




Recursive Functions
let PrintToken (token : Token) =

         match token with
          | Operation(operation) -> PrintOperation(operation)
          | Bracket(LeftBracket) -> Debug.Write "("
          | Bracket(RightBracket) -> Debug.Write ")"
          | Letter(Value(value)) -> PrintValue value
          | Letter(ParseTree(parseTree)) -> PrintTree parseTree
    ;;

    let rec PrintSentence (sentence : Token List) =
          match sentence with
          | token :: tail -> PrintToken(token); PrintSentence(tail);
          | [] -> ()
    ;;




Recursive Functions
5 * (3 + 4) = 35




Assembling Parser
(Calculator Parser)
Tokenize
          Expression


         Parse Sentence



           Print Tree


           Compute
          Expression


          Print Result



Assembling Parser
(Flow Chart)
L           =V
    L           =T
    L ao L      = L ao L mo L
    L           =LoL
    L           =(L)
    L – Letter
    V – Value
    T – Tree
    o – Operation
    ao – Additive Operation
    mo – Multiplicative Operation




Assembling Parser
(Production Rules)

Weitere ähnliche Inhalte

Was ist angesagt?

Was ist angesagt? (20)

Arrays
ArraysArrays
Arrays
 
Arrays
ArraysArrays
Arrays
 
Munihac 2018 - Beautiful Template Haskell
Munihac 2018 - Beautiful Template HaskellMunihac 2018 - Beautiful Template Haskell
Munihac 2018 - Beautiful Template Haskell
 
Functions In Scala
Functions In Scala Functions In Scala
Functions In Scala
 
Overview of c (2)
Overview of c (2)Overview of c (2)
Overview of c (2)
 
C++ ARRAY WITH EXAMPLES
C++ ARRAY WITH EXAMPLESC++ ARRAY WITH EXAMPLES
C++ ARRAY WITH EXAMPLES
 
Arrays
ArraysArrays
Arrays
 
Principled Error Handling with FP
Principled Error Handling with FPPrincipled Error Handling with FP
Principled Error Handling with FP
 
Strings Functions in C Programming
Strings Functions in C ProgrammingStrings Functions in C Programming
Strings Functions in C Programming
 
Arrays in c
Arrays in cArrays in c
Arrays in c
 
Abstracting over Execution with Higher Kinded Types
Abstracting over Execution with Higher Kinded TypesAbstracting over Execution with Higher Kinded Types
Abstracting over Execution with Higher Kinded Types
 
Array Presentation (EngineerBaBu.com)
Array Presentation (EngineerBaBu.com)Array Presentation (EngineerBaBu.com)
Array Presentation (EngineerBaBu.com)
 
simple linear regression
simple linear regressionsimple linear regression
simple linear regression
 
Passing an Array to a Function (ICT Programming)
Passing an Array to a Function (ICT Programming)Passing an Array to a Function (ICT Programming)
Passing an Array to a Function (ICT Programming)
 
Hive function-cheat-sheet
Hive function-cheat-sheetHive function-cheat-sheet
Hive function-cheat-sheet
 
2- Dimensional Arrays
2- Dimensional Arrays2- Dimensional Arrays
2- Dimensional Arrays
 
Parts of python programming language
Parts of python programming languageParts of python programming language
Parts of python programming language
 
NCCU: Statistics in the Criminal Justice System, R basics and Simulation - Pr...
NCCU: Statistics in the Criminal Justice System, R basics and Simulation - Pr...NCCU: Statistics in the Criminal Justice System, R basics and Simulation - Pr...
NCCU: Statistics in the Criminal Justice System, R basics and Simulation - Pr...
 
Array
ArrayArray
Array
 
Arrays
ArraysArrays
Arrays
 

Andere mochten auch

Music magazine analysis
Music magazine analysisMusic magazine analysis
Music magazine analysisclaudiadsousa
 
Ustawa o spółdzielniach socjalnych - propozycje zmian
Ustawa o spółdzielniach socjalnych - propozycje zmianUstawa o spółdzielniach socjalnych - propozycje zmian
Ustawa o spółdzielniach socjalnych - propozycje zmianWaldemar Weihs
 
Sistemas de información, organizaciones y estrategia
Sistemas de información, organizaciones y estrategiaSistemas de información, organizaciones y estrategia
Sistemas de información, organizaciones y estrategiacejhb
 
「コミュニティは安心と信頼を高める装置?」(小林千早都)
「コミュニティは安心と信頼を高める装置?」(小林千早都)「コミュニティは安心と信頼を高める装置?」(小林千早都)
「コミュニティは安心と信頼を高める装置?」(小林千早都)Chisato Kobayashi
 
Functional Programming Fundamentals
Functional Programming FundamentalsFunctional Programming Fundamentals
Functional Programming FundamentalsOleksiyTereshchenko
 
The Power of Storytelling
The Power of StorytellingThe Power of Storytelling
The Power of Storytellinglisahorvat
 
james o'brien chapter 7 electronic business system
james o'brien chapter 7 electronic business system james o'brien chapter 7 electronic business system
james o'brien chapter 7 electronic business system mousumsts
 
Araling panlipunan
Araling panlipunanAraling panlipunan
Araling panlipunanJhi Khyung
 

Andere mochten auch (16)

CUENTO
CUENTOCUENTO
CUENTO
 
Uso de la b y v
Uso de la b y vUso de la b y v
Uso de la b y v
 
Music magazine analysis
Music magazine analysisMusic magazine analysis
Music magazine analysis
 
Ustawa o spółdzielniach socjalnych - propozycje zmian
Ustawa o spółdzielniach socjalnych - propozycje zmianUstawa o spółdzielniach socjalnych - propozycje zmian
Ustawa o spółdzielniach socjalnych - propozycje zmian
 
Conti
ContiConti
Conti
 
Zjazd Ve (2007)
Zjazd Ve (2007)Zjazd Ve (2007)
Zjazd Ve (2007)
 
Sistemas de información, organizaciones y estrategia
Sistemas de información, organizaciones y estrategiaSistemas de información, organizaciones y estrategia
Sistemas de información, organizaciones y estrategia
 
「コミュニティは安心と信頼を高める装置?」(小林千早都)
「コミュニティは安心と信頼を高める装置?」(小林千早都)「コミュニティは安心と信頼を高める装置?」(小林千早都)
「コミュニティは安心と信頼を高める装置?」(小林千早都)
 
Functional Programming Fundamentals
Functional Programming FundamentalsFunctional Programming Fundamentals
Functional Programming Fundamentals
 
El punto
El puntoEl punto
El punto
 
1.full
1.full1.full
1.full
 
The Power of Storytelling
The Power of StorytellingThe Power of Storytelling
The Power of Storytelling
 
Uso de la s, c y z
Uso de la s, c y zUso de la s, c y z
Uso de la s, c y z
 
james o'brien chapter 7 electronic business system
james o'brien chapter 7 electronic business system james o'brien chapter 7 electronic business system
james o'brien chapter 7 electronic business system
 
Araling panlipunan
Araling panlipunanAraling panlipunan
Araling panlipunan
 
La coma
La comaLa coma
La coma
 

Ähnlich wie Functional Programming Advanced

Ejercicios de estilo en la programación
Ejercicios de estilo en la programaciónEjercicios de estilo en la programación
Ejercicios de estilo en la programaciónSoftware Guru
 
Functional programming ii
Functional programming iiFunctional programming ii
Functional programming iiPrashant Kalkar
 
The Ring programming language version 1.8 book - Part 29 of 202
The Ring programming language version 1.8 book - Part 29 of 202The Ring programming language version 1.8 book - Part 29 of 202
The Ring programming language version 1.8 book - Part 29 of 202Mahmoud Samir Fayed
 
Functional Programming in F#
Functional Programming in F#Functional Programming in F#
Functional Programming in F#Dmitri Nesteruk
 
Introduction to R programming
Introduction to R programmingIntroduction to R programming
Introduction to R programmingAlberto Labarga
 
An introduction to functional programming with Swift
An introduction to functional programming with SwiftAn introduction to functional programming with Swift
An introduction to functional programming with SwiftFatih Nayebi, Ph.D.
 
Model-Driven Software Development - Static Analysis & Error Checking
Model-Driven Software Development - Static Analysis & Error CheckingModel-Driven Software Development - Static Analysis & Error Checking
Model-Driven Software Development - Static Analysis & Error CheckingEelco Visser
 
Power of functions in a typed world
Power of functions in a typed worldPower of functions in a typed world
Power of functions in a typed worldDebasish Ghosh
 
仕事で使うF#
仕事で使うF#仕事で使うF#
仕事で使うF#bleis tift
 
Crystal: tipos, peculiaridades y desafios
Crystal: tipos, peculiaridades y desafiosCrystal: tipos, peculiaridades y desafios
Crystal: tipos, peculiaridades y desafiosBrian Cardiff
 
Morel, a Functional Query Language
Morel, a Functional Query LanguageMorel, a Functional Query Language
Morel, a Functional Query LanguageJulian Hyde
 
The Functional Programming Triad of Folding, Scanning and Iteration - a first...
The Functional Programming Triad of Folding, Scanning and Iteration - a first...The Functional Programming Triad of Folding, Scanning and Iteration - a first...
The Functional Programming Triad of Folding, Scanning and Iteration - a first...Philip Schwarz
 
Scala as a Declarative Language
Scala as a Declarative LanguageScala as a Declarative Language
Scala as a Declarative Languagevsssuresh
 
The Ring programming language version 1.9 book - Part 31 of 210
The Ring programming language version 1.9 book - Part 31 of 210The Ring programming language version 1.9 book - Part 31 of 210
The Ring programming language version 1.9 book - Part 31 of 210Mahmoud Samir Fayed
 

Ähnlich wie Functional Programming Advanced (20)

Ch2
Ch2Ch2
Ch2
 
Ejercicios de estilo en la programación
Ejercicios de estilo en la programaciónEjercicios de estilo en la programación
Ejercicios de estilo en la programación
 
Term Rewriting
Term RewritingTerm Rewriting
Term Rewriting
 
Map, Reduce and Filter in Swift
Map, Reduce and Filter in SwiftMap, Reduce and Filter in Swift
Map, Reduce and Filter in Swift
 
Functional programming ii
Functional programming iiFunctional programming ii
Functional programming ii
 
The Ring programming language version 1.8 book - Part 29 of 202
The Ring programming language version 1.8 book - Part 29 of 202The Ring programming language version 1.8 book - Part 29 of 202
The Ring programming language version 1.8 book - Part 29 of 202
 
Programming in R
Programming in RProgramming in R
Programming in R
 
Functional Programming in F#
Functional Programming in F#Functional Programming in F#
Functional Programming in F#
 
Introduction to R programming
Introduction to R programmingIntroduction to R programming
Introduction to R programming
 
An introduction to functional programming with Swift
An introduction to functional programming with SwiftAn introduction to functional programming with Swift
An introduction to functional programming with Swift
 
Model-Driven Software Development - Static Analysis & Error Checking
Model-Driven Software Development - Static Analysis & Error CheckingModel-Driven Software Development - Static Analysis & Error Checking
Model-Driven Software Development - Static Analysis & Error Checking
 
Power of functions in a typed world
Power of functions in a typed worldPower of functions in a typed world
Power of functions in a typed world
 
仕事で使うF#
仕事で使うF#仕事で使うF#
仕事で使うF#
 
Scala @ TomTom
Scala @ TomTomScala @ TomTom
Scala @ TomTom
 
Crystal: tipos, peculiaridades y desafios
Crystal: tipos, peculiaridades y desafiosCrystal: tipos, peculiaridades y desafios
Crystal: tipos, peculiaridades y desafios
 
Morel, a Functional Query Language
Morel, a Functional Query LanguageMorel, a Functional Query Language
Morel, a Functional Query Language
 
The Functional Programming Triad of Folding, Scanning and Iteration - a first...
The Functional Programming Triad of Folding, Scanning and Iteration - a first...The Functional Programming Triad of Folding, Scanning and Iteration - a first...
The Functional Programming Triad of Folding, Scanning and Iteration - a first...
 
Scala as a Declarative Language
Scala as a Declarative LanguageScala as a Declarative Language
Scala as a Declarative Language
 
The Ring programming language version 1.9 book - Part 31 of 210
The Ring programming language version 1.9 book - Part 31 of 210The Ring programming language version 1.9 book - Part 31 of 210
The Ring programming language version 1.9 book - Part 31 of 210
 
LISP: Introduction to lisp
LISP: Introduction to lispLISP: Introduction to lisp
LISP: Introduction to lisp
 

Kürzlich hochgeladen

The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 

Kürzlich hochgeladen (20)

The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 

Functional Programming Advanced

  • 1. Functional Programming { F# Programming Techniques
  • 2. Oleksiy Tereshchenko  Principal consultant at Neudesic  10 years experience in Custom Application Development and Connected Systems About Presenter
  • 3. Building Blocks  Tuples  Discriminated Unions  Lists  Stack (as example of OOD)  Recursive Functions  Assembling Parser  Demo & Questions Agenda
  • 4. Tuples  Discriminated Unions  Lists  Stack  Recursive Functions Building Blocks
  • 5. let makeAndYear = ("Ford", 2011) type CarMakeAndYear = string * int let (make,year) : CarMakeAndYear = makeAndYear Debug.WriteLine(make) Debug.WriteLine(year) match makeAndYear with | ("Honda", 2010) -> Debug.WriteLine("Matched Honda 2010") | ("Honda", year) -> Debug.WriteLine("Matched Honda " + year.ToString()) | ( _ , _ ) -> Debug.WriteLine("This is not Honda") Tuples
  • 6. type Operation = Plus | Minus | Multiply | Devision type Value = IntValue of int type ParseTree = Leaf of Value | Node of ParseTree * Operation * ParseTree let plusOperation = Plus let treeLeafLeft = Leaf(IntValue(100)) let treeLeafRight = Leaf(IntValue(100)) let treeNode = Node(treeLeafLeft, Plus, treeLeafRight) let parentTree = Node(treeNode, Multiply, Leaf(IntValue(2))) Discriminated Unions
  • 7. let listOfNumbersA = [1;2;3] let listOfNumbersB = [1..10] let listOfNumbersAB = listOfNumbersA @ listOfNumbersB let listOfNumbersC = 50 :: listOfNumbersA match listOfNumbersA with |intValue :: listOfNumbersD -> Debug.WriteLine(intValue) |_-> () let head = listOfNumbersB.Head Lists
  • 8. type StackNode<'a> = Nil | StackNode of 'a * StackNode<'a> type Stack<'a>() = let mutable stackNode : StackNode<'a> = Nil member self.Node : StackNode<'a> = stackNode member self.Push( leaf : 'a ) = stackNode <- StackNode(leaf, self.Node) member self.Pop() : 'a option = match stackNode with | Nil -> None | StackNode(leaf,tailNode) -> stackNode <- tailNode; Some(leaf); Stack
  • 9. let rec SumArithmeticProgression( x) = if x < 1 then x else x + SumArithmeticProgression ( (x-1)) let rec SumArithmeticProgressionTailRecursion ( x, acc) = if x < 1 then acc else SumArithmeticProgressionTailRecursion ( (x-1), (acc + x)) Recursive Functions
  • 10. let PrintToken (token : Token) = match token with | Operation(operation) -> PrintOperation(operation) | Bracket(LeftBracket) -> Debug.Write "(" | Bracket(RightBracket) -> Debug.Write ")" | Letter(Value(value)) -> PrintValue value | Letter(ParseTree(parseTree)) -> PrintTree parseTree ;; let rec PrintSentence (sentence : Token List) = match sentence with | token :: tail -> PrintToken(token); PrintSentence(tail); | [] -> () ;; Recursive Functions
  • 11. 5 * (3 + 4) = 35 Assembling Parser (Calculator Parser)
  • 12. Tokenize Expression Parse Sentence Print Tree Compute Expression Print Result Assembling Parser (Flow Chart)
  • 13. L =V L =T L ao L = L ao L mo L L =LoL L =(L) L – Letter V – Value T – Tree o – Operation ao – Additive Operation mo – Multiplicative Operation Assembling Parser (Production Rules)