SlideShare uma empresa 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)

Mais conteúdo relacionado

Mais procurados

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)
Fatima Kate Tanay
 

Mais procurados (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
 

Destaque

Music magazine analysis
Music magazine analysisMusic magazine analysis
Music magazine analysis
claudiadsousa
 
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
Waldemar Weihs
 
Functional Programming Fundamentals
Functional Programming FundamentalsFunctional Programming Fundamentals
Functional Programming Fundamentals
OleksiyTereshchenko
 
The Power of Storytelling
The Power of StorytellingThe Power of Storytelling
The Power of Storytelling
lisahorvat
 

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

Semelhante 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ón
Software Guru
 
Functional Programming in F#
Functional Programming in F#Functional Programming in F#
Functional Programming in F#
Dmitri Nesteruk
 
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
Eelco Visser
 
仕事で使うF#
仕事で使うF#仕事で使うF#
仕事で使うF#
bleis tift
 

Semelhante 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

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 

Último (20)

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...
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelNavi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
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
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 

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)