• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Functional Programming Advanced
 

Functional Programming Advanced

on

  • 337 views

 

Statistics

Views

Total Views
337
Views on SlideShare
337
Embed Views
0

Actions

Likes
0
Downloads
3
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Functional Programming Advanced Functional Programming Advanced Presentation Transcript

    • FunctionalProgramming { F# Programming Techniques
    •  Oleksiy Tereshchenko  Principal consultant at Neudesic  10 years experience in Custom Application Development and Connected SystemsAbout Presenter
    •  Building Blocks  Tuples  Discriminated Unions  Lists  Stack (as example of OOD)  Recursive Functions  Assembling Parser  Demo & QuestionsAgenda
    •  Tuples  Discriminated Unions  Lists  Stack  Recursive FunctionsBuilding 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 | Devisiontype Value = IntValue of inttype ParseTree = Leaf of Value | Node of ParseTree * Operation * ParseTreelet plusOperation = Pluslet 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.HeadLists
    • 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) = 35Assembling Parser(Calculator Parser)
    • Tokenize Expression Parse Sentence Print Tree Compute Expression Print ResultAssembling 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 OperationAssembling Parser(Production Rules)