SlideShare una empresa de Scribd logo
1 de 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)

Más contenido relacionado

La actualidad más candente

La actualidad más candente (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
 

Destacado

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
 

Destacado (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
 

Similar a 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
 

Similar a 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
 

Último

🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessPixlogix Infotech
 
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
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
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
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
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
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 

Último (20)

🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
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
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
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
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.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
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 

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)