Functional Programming in
Scala Reading #1
Sep 12 2013
Katsunori Kanda
Software Engineer
@potix2
https://github.com/potix2/fpinscala
139݄9݄༵
Slide 2
Slide 2 text
Chapter1: Keywords
• side effect(෭࡞༻)
• referential transparency(ࢀরಁաੑ)
139݄9݄༵
Slide 3
Slide 3 text
1.1 The fundamental premise of
functional programming
• ͜ͷຊͰɺ७ਮؔ(pure functions) Λ
ͬͯϓϩάϥϜΛॻ͘͜ͱΛؔܕ
ϓϩάϥϛϯά(functional programming)
ͱݺͿ
• ७ਮؔ => ෭࡞༻Λ࣋ͨͳ͍ؔ
139݄9݄༵
Slide 4
Slide 4 text
෭࡞༻ͷྫ(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”)
139݄9݄༵
Slide 5
Slide 5 text
෭࡞༻ͷྫ(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 ... }
139݄9݄༵
Slide 6
Slide 6 text
1.1.1 A Simple example
139݄9݄༵
Slide 7
Slide 7 text
1.2 Exactly what is a
(pure) function ?
139݄9݄༵