Upgrade to Pro — share decks privately, control downloads, hide ads and more …

FpScala-Chapter1.pdf

 FpScala-Chapter1.pdf

Katsunori Kanda

September 09, 2013
Tweet

More Decks by Katsunori Kanda

Other Decks in Programming

Transcript

  1. Functional Programming in Scala Reading #1 Sep 12 2013 Katsunori

    Kanda Software Engineer @potix2 https://github.com/potix2/fpinscala 13೥9݄9೔݄༵೔
  2. 1.1 The fundamental premise of functional programming • ͜ͷຊͰ͸ɺ७ਮؔ਺(pure functions)

    Λ ࢖ͬͯϓϩάϥϜΛॻ͘͜ͱΛؔ਺ܕ ϓϩάϥϛϯά(functional programming) ͱݺͿ • ७ਮؔ਺ => ෭࡞༻Λ࣋ͨͳ͍ؔ਺ 13೥9݄9೔݄༵೔
  3. ෭࡞༻ͷྫ(1/2) // reassigning a variable var x = 1; x

    = 2 // modifying a data structure in place map(“foo”) = “bar” // setting a field on an object cup.price = 12 // throwing an exception or halting with an error throw new Exception(“caused error”) 13೥9݄9೔݄༵೔
  4. ෭࡞༻ͷྫ(2/2) // printing to the console or reading user input

    println(“hello”) // reading from or writing to a file Source.fromFile(“foo.txt”).mkString // Drawing on the screen def draw() = { // write to screen ... } 13೥9݄9೔݄༵೔
  5. ७ਮؔ਺ͱ͸? • ಉ͡Ҿ਺Λ౉ͤ͹ৗʹಉ݁͡Ռ͕ฦΔ • ex1. 2 + 3 (ৗʹ݁Ռ͸5) •

    ex2. “emacs or vi”.length() (݁Ռ͸11) 13೥9݄9೔݄༵೔