Download - Functional programming
![Page 1: Functional programming](https://reader034.vdocuments.pub/reader034/viewer/2022042713/54696e30af7959e3018b5c16/html5/thumbnails/1.jpg)
![Page 2: Functional programming](https://reader034.vdocuments.pub/reader034/viewer/2022042713/54696e30af7959e3018b5c16/html5/thumbnails/2.jpg)
NewHeart
서승현
Functional Programming and
Tail Recursion
![Page 3: Functional programming](https://reader034.vdocuments.pub/reader034/viewer/2022042713/54696e30af7959e3018b5c16/html5/thumbnails/3.jpg)
Contents
1. Functional Programming
2. Features
3. Tail Recursion
4. Q&A
![Page 4: Functional programming](https://reader034.vdocuments.pub/reader034/viewer/2022042713/54696e30af7959e3018b5c16/html5/thumbnails/4.jpg)
Functional Programming
Object-Oriented Programming Procedural Programming
![Page 5: Functional programming](https://reader034.vdocuments.pub/reader034/viewer/2022042713/54696e30af7959e3018b5c16/html5/thumbnails/5.jpg)
Object-Oriented Programming
![Page 6: Functional programming](https://reader034.vdocuments.pub/reader034/viewer/2022042713/54696e30af7959e3018b5c16/html5/thumbnails/6.jpg)
Object-Oriented Programming
![Page 7: Functional programming](https://reader034.vdocuments.pub/reader034/viewer/2022042713/54696e30af7959e3018b5c16/html5/thumbnails/7.jpg)
모든 것은 객체다
Object-Oriented Programming
![Page 8: Functional programming](https://reader034.vdocuments.pub/reader034/viewer/2022042713/54696e30af7959e3018b5c16/html5/thumbnails/8.jpg)
모든 것은 객체다
Object-Oriented Programming
추상화
![Page 9: Functional programming](https://reader034.vdocuments.pub/reader034/viewer/2022042713/54696e30af7959e3018b5c16/html5/thumbnails/9.jpg)
Functional Programming
![Page 10: Functional programming](https://reader034.vdocuments.pub/reader034/viewer/2022042713/54696e30af7959e3018b5c16/html5/thumbnails/10.jpg)
모든 것은 함수다
Functional Programming
추상화
![Page 11: Functional programming](https://reader034.vdocuments.pub/reader034/viewer/2022042713/54696e30af7959e3018b5c16/html5/thumbnails/11.jpg)
Functional Programming
![Page 12: Functional programming](https://reader034.vdocuments.pub/reader034/viewer/2022042713/54696e30af7959e3018b5c16/html5/thumbnails/12.jpg)
Functional Programming
모든 것은 수학적인 함수다
![Page 13: Functional programming](https://reader034.vdocuments.pub/reader034/viewer/2022042713/54696e30af7959e3018b5c16/html5/thumbnails/13.jpg)
모든 것은 수학적인 함수다
Functional Programming
![Page 14: Functional programming](https://reader034.vdocuments.pub/reader034/viewer/2022042713/54696e30af7959e3018b5c16/html5/thumbnails/14.jpg)
Functional Programming
참조적 투명성
모든 것은 수학적인 함수다
![Page 15: Functional programming](https://reader034.vdocuments.pub/reader034/viewer/2022042713/54696e30af7959e3018b5c16/html5/thumbnails/15.jpg)
Procedural Programming
Referential Transparency
![Page 16: Functional programming](https://reader034.vdocuments.pub/reader034/viewer/2022042713/54696e30af7959e3018b5c16/html5/thumbnails/16.jpg)
Referential Transparency
![Page 17: Functional programming](https://reader034.vdocuments.pub/reader034/viewer/2022042713/54696e30af7959e3018b5c16/html5/thumbnails/17.jpg)
Mathematics
Referential Transparency
![Page 18: Functional programming](https://reader034.vdocuments.pub/reader034/viewer/2022042713/54696e30af7959e3018b5c16/html5/thumbnails/18.jpg)
Referential Transparency
𝒇 𝒙 = 𝒙𝟐 + 𝒙 + 𝟏
𝒌 = 𝟏 𝒙 = 𝒌 + 𝒇 𝒌 𝒚 = 𝒌 + 𝒇 𝒌
𝒙 = 𝒚?
![Page 19: Functional programming](https://reader034.vdocuments.pub/reader034/viewer/2022042713/54696e30af7959e3018b5c16/html5/thumbnails/19.jpg)
참조적 투명성
Functional Programming
![Page 20: Functional programming](https://reader034.vdocuments.pub/reader034/viewer/2022042713/54696e30af7959e3018b5c16/html5/thumbnails/20.jpg)
참조적 투명성
Functional Programming
상태에 영향을 받지 않는다
![Page 21: Functional programming](https://reader034.vdocuments.pub/reader034/viewer/2022042713/54696e30af7959e3018b5c16/html5/thumbnails/21.jpg)
모든 것은 수학적인 함수다
Functional Programming
![Page 22: Functional programming](https://reader034.vdocuments.pub/reader034/viewer/2022042713/54696e30af7959e3018b5c16/html5/thumbnails/22.jpg)
1. Type Inference
2. List Processing
3. Pure Function
4. Non-Strict Evaluation
5. First-Class Function
6. Recursion
Features
![Page 23: Functional programming](https://reader034.vdocuments.pub/reader034/viewer/2022042713/54696e30af7959e3018b5c16/html5/thumbnails/23.jpg)
Ocaml
![Page 24: Functional programming](https://reader034.vdocuments.pub/reader034/viewer/2022042713/54696e30af7959e3018b5c16/html5/thumbnails/24.jpg)
1. Type Inference
2. List Processing
3. Pure Function
4. Non-Strict Evaluation
5. First-Class Function
6. Recursion
Features
![Page 25: Functional programming](https://reader034.vdocuments.pub/reader034/viewer/2022042713/54696e30af7959e3018b5c16/html5/thumbnails/25.jpg)
Ocaml Primitive Types
int
float
char
string
bool
unit
2, -2, …
2.0, -2.0, …
‘2’, ‘b’, …
“”, “22”, …
true, false
()
![Page 26: Functional programming](https://reader034.vdocuments.pub/reader034/viewer/2022042713/54696e30af7959e3018b5c16/html5/thumbnails/26.jpg)
Type Inference
![Page 27: Functional programming](https://reader034.vdocuments.pub/reader034/viewer/2022042713/54696e30af7959e3018b5c16/html5/thumbnails/27.jpg)
Type Inference
![Page 28: Functional programming](https://reader034.vdocuments.pub/reader034/viewer/2022042713/54696e30af7959e3018b5c16/html5/thumbnails/28.jpg)
Type Inference
Javascript
![Page 29: Functional programming](https://reader034.vdocuments.pub/reader034/viewer/2022042713/54696e30af7959e3018b5c16/html5/thumbnails/29.jpg)
Type Inference
Javascript Ocaml
![Page 30: Functional programming](https://reader034.vdocuments.pub/reader034/viewer/2022042713/54696e30af7959e3018b5c16/html5/thumbnails/30.jpg)
Type Inference
![Page 31: Functional programming](https://reader034.vdocuments.pub/reader034/viewer/2022042713/54696e30af7959e3018b5c16/html5/thumbnails/31.jpg)
1. Type Inference
2. List Processing
3. Pure Function
4. Non-Strict Evaluation
5. First-Class Function
6. Recursion
Features
![Page 32: Functional programming](https://reader034.vdocuments.pub/reader034/viewer/2022042713/54696e30af7959e3018b5c16/html5/thumbnails/32.jpg)
List Processing
![Page 33: Functional programming](https://reader034.vdocuments.pub/reader034/viewer/2022042713/54696e30af7959e3018b5c16/html5/thumbnails/33.jpg)
List Processing
![Page 34: Functional programming](https://reader034.vdocuments.pub/reader034/viewer/2022042713/54696e30af7959e3018b5c16/html5/thumbnails/34.jpg)
List Processing
![Page 35: Functional programming](https://reader034.vdocuments.pub/reader034/viewer/2022042713/54696e30af7959e3018b5c16/html5/thumbnails/35.jpg)
1. Type Inference
2. List Processing
3. Pure Function
4. Non-Strict Evaluation
5. First-Class Function
6. Recursion
Features
![Page 36: Functional programming](https://reader034.vdocuments.pub/reader034/viewer/2022042713/54696e30af7959e3018b5c16/html5/thumbnails/36.jpg)
Pure Function
![Page 37: Functional programming](https://reader034.vdocuments.pub/reader034/viewer/2022042713/54696e30af7959e3018b5c16/html5/thumbnails/37.jpg)
Function
![Page 38: Functional programming](https://reader034.vdocuments.pub/reader034/viewer/2022042713/54696e30af7959e3018b5c16/html5/thumbnails/38.jpg)
Function
Javascript
![Page 39: Functional programming](https://reader034.vdocuments.pub/reader034/viewer/2022042713/54696e30af7959e3018b5c16/html5/thumbnails/39.jpg)
Function
Javascript Ocaml
![Page 40: Functional programming](https://reader034.vdocuments.pub/reader034/viewer/2022042713/54696e30af7959e3018b5c16/html5/thumbnails/40.jpg)
Function
![Page 41: Functional programming](https://reader034.vdocuments.pub/reader034/viewer/2022042713/54696e30af7959e3018b5c16/html5/thumbnails/41.jpg)
Currying
![Page 42: Functional programming](https://reader034.vdocuments.pub/reader034/viewer/2022042713/54696e30af7959e3018b5c16/html5/thumbnails/42.jpg)
Currying
![Page 43: Functional programming](https://reader034.vdocuments.pub/reader034/viewer/2022042713/54696e30af7959e3018b5c16/html5/thumbnails/43.jpg)
Referential Transparency
C++
![Page 44: Functional programming](https://reader034.vdocuments.pub/reader034/viewer/2022042713/54696e30af7959e3018b5c16/html5/thumbnails/44.jpg)
Referential Transparency
C++ Ocaml
![Page 45: Functional programming](https://reader034.vdocuments.pub/reader034/viewer/2022042713/54696e30af7959e3018b5c16/html5/thumbnails/45.jpg)
Referential Transparency
Ocaml Javascript
![Page 46: Functional programming](https://reader034.vdocuments.pub/reader034/viewer/2022042713/54696e30af7959e3018b5c16/html5/thumbnails/46.jpg)
Referential Transparency
![Page 47: Functional programming](https://reader034.vdocuments.pub/reader034/viewer/2022042713/54696e30af7959e3018b5c16/html5/thumbnails/47.jpg)
1. Type Inference
2. List Processing
3. Pure Function
4. Non-Strict Evaluation
5. First-Class Function
6. Recursion
Features
![Page 48: Functional programming](https://reader034.vdocuments.pub/reader034/viewer/2022042713/54696e30af7959e3018b5c16/html5/thumbnails/48.jpg)
Short-Circuit Evaluation
![Page 49: Functional programming](https://reader034.vdocuments.pub/reader034/viewer/2022042713/54696e30af7959e3018b5c16/html5/thumbnails/49.jpg)
Short-Circuit Evaluation
![Page 50: Functional programming](https://reader034.vdocuments.pub/reader034/viewer/2022042713/54696e30af7959e3018b5c16/html5/thumbnails/50.jpg)
Short-Circuit Evaluation
![Page 51: Functional programming](https://reader034.vdocuments.pub/reader034/viewer/2022042713/54696e30af7959e3018b5c16/html5/thumbnails/51.jpg)
Non-Strict Evaluation
length [0/0, 1/0, 2/0]
![Page 52: Functional programming](https://reader034.vdocuments.pub/reader034/viewer/2022042713/54696e30af7959e3018b5c16/html5/thumbnails/52.jpg)
Non-Strict Evaluation
length [0/0, 1/0, 2/0]
![Page 53: Functional programming](https://reader034.vdocuments.pub/reader034/viewer/2022042713/54696e30af7959e3018b5c16/html5/thumbnails/53.jpg)
Non-Strict Evaluation
length [0/0, 1/0, 2/0]
![Page 54: Functional programming](https://reader034.vdocuments.pub/reader034/viewer/2022042713/54696e30af7959e3018b5c16/html5/thumbnails/54.jpg)
Non-Strict Evaluation
length [0/0, 1/0, 2/0]
![Page 55: Functional programming](https://reader034.vdocuments.pub/reader034/viewer/2022042713/54696e30af7959e3018b5c16/html5/thumbnails/55.jpg)
Non-Strict Evaluation
![Page 56: Functional programming](https://reader034.vdocuments.pub/reader034/viewer/2022042713/54696e30af7959e3018b5c16/html5/thumbnails/56.jpg)
Non-Strict Evaluation
![Page 57: Functional programming](https://reader034.vdocuments.pub/reader034/viewer/2022042713/54696e30af7959e3018b5c16/html5/thumbnails/57.jpg)
1. Type Inference
2. List Processing
3. Pure Function
4. Non-Strict Evaluation
5. First-Class Function
6. Recursion
Features
![Page 58: Functional programming](https://reader034.vdocuments.pub/reader034/viewer/2022042713/54696e30af7959e3018b5c16/html5/thumbnails/58.jpg)
First-Class Function
1. 함수를 인자로서 넘길 수 있다
2. 함수를 값으로서 반환할 수 있다
3. 익명 함수와 중첩 함수
4. 변수에 함수를 대입할 수 있다
5. 비지역 변수와 클로져
![Page 59: Functional programming](https://reader034.vdocuments.pub/reader034/viewer/2022042713/54696e30af7959e3018b5c16/html5/thumbnails/59.jpg)
Passing Functions as Arguments
![Page 60: Functional programming](https://reader034.vdocuments.pub/reader034/viewer/2022042713/54696e30af7959e3018b5c16/html5/thumbnails/60.jpg)
Passing Functions as Arguments
![Page 61: Functional programming](https://reader034.vdocuments.pub/reader034/viewer/2022042713/54696e30af7959e3018b5c16/html5/thumbnails/61.jpg)
Passing Functions as Arguments
![Page 62: Functional programming](https://reader034.vdocuments.pub/reader034/viewer/2022042713/54696e30af7959e3018b5c16/html5/thumbnails/62.jpg)
First-Class Function
1. 함수를 인자로서 넘길 수 있다
2. 함수를 값으로서 반환할 수 있다
3. 익명 함수와 중첩 함수
4. 변수에 함수를 대입할 수 있다
5. 비지역 변수와 클로져
![Page 63: Functional programming](https://reader034.vdocuments.pub/reader034/viewer/2022042713/54696e30af7959e3018b5c16/html5/thumbnails/63.jpg)
Returning Functions as Results
![Page 64: Functional programming](https://reader034.vdocuments.pub/reader034/viewer/2022042713/54696e30af7959e3018b5c16/html5/thumbnails/64.jpg)
Returning Functions as Results
![Page 65: Functional programming](https://reader034.vdocuments.pub/reader034/viewer/2022042713/54696e30af7959e3018b5c16/html5/thumbnails/65.jpg)
Returning Functions as Results
![Page 66: Functional programming](https://reader034.vdocuments.pub/reader034/viewer/2022042713/54696e30af7959e3018b5c16/html5/thumbnails/66.jpg)
First-Class Function
1. 함수를 인자로서 넘길 수 있다
2. 함수를 값으로서 반환할 수 있다
3. 익명 함수와 중첩 함수
4. 변수에 함수를 대입할 수 있다
5. 비지역 변수와 클로져
![Page 67: Functional programming](https://reader034.vdocuments.pub/reader034/viewer/2022042713/54696e30af7959e3018b5c16/html5/thumbnails/67.jpg)
Anonymous and Nested Functions
![Page 68: Functional programming](https://reader034.vdocuments.pub/reader034/viewer/2022042713/54696e30af7959e3018b5c16/html5/thumbnails/68.jpg)
First-Class Function
1. 함수를 인자로서 넘길 수 있다
2. 함수를 값으로서 반환할 수 있다
3. 익명 함수와 중첩 함수
4. 변수에 함수를 대입할 수 있다
5. 비지역 변수와 클로져
![Page 69: Functional programming](https://reader034.vdocuments.pub/reader034/viewer/2022042713/54696e30af7959e3018b5c16/html5/thumbnails/69.jpg)
First-Class Function
1. 함수를 인자로서 넘길 수 있다
2. 함수를 값으로서 반환할 수 있다
3. 익명 함수와 중첩 함수
4. 변수에 함수를 대입할 수 있다
5. 비지역 변수와 클로져
![Page 70: Functional programming](https://reader034.vdocuments.pub/reader034/viewer/2022042713/54696e30af7959e3018b5c16/html5/thumbnails/70.jpg)
Non-local Variables and Closures
![Page 71: Functional programming](https://reader034.vdocuments.pub/reader034/viewer/2022042713/54696e30af7959e3018b5c16/html5/thumbnails/71.jpg)
First-Class Function
1. 함수를 인자로서 넘길 수 있다
2. 함수를 값으로서 반환할 수 있다
3. 익명 함수와 중첩 함수
4. 변수에 함수를 대입할 수 있다
5. 비지역 변수와 클로져
![Page 72: Functional programming](https://reader034.vdocuments.pub/reader034/viewer/2022042713/54696e30af7959e3018b5c16/html5/thumbnails/72.jpg)
1. Type Inference
2. List Processing
3. Pure Function
4. Non-Strict Evaluation
5. First-Class Function
6. Recursion
Features
![Page 73: Functional programming](https://reader034.vdocuments.pub/reader034/viewer/2022042713/54696e30af7959e3018b5c16/html5/thumbnails/73.jpg)
Recursion
![Page 74: Functional programming](https://reader034.vdocuments.pub/reader034/viewer/2022042713/54696e30af7959e3018b5c16/html5/thumbnails/74.jpg)
Recursion
![Page 75: Functional programming](https://reader034.vdocuments.pub/reader034/viewer/2022042713/54696e30af7959e3018b5c16/html5/thumbnails/75.jpg)
1. Type Inference
2. List Processing
3. Pure Function
4. Non-Strict Evaluation
5. First-Class Function
6. Recursion
Features
![Page 76: Functional programming](https://reader034.vdocuments.pub/reader034/viewer/2022042713/54696e30af7959e3018b5c16/html5/thumbnails/76.jpg)
Tail Recursion
1. Tail Recursion Optimization
2. Tail Recursion by Accumulator
3. Continuation-Passing Style
![Page 77: Functional programming](https://reader034.vdocuments.pub/reader034/viewer/2022042713/54696e30af7959e3018b5c16/html5/thumbnails/77.jpg)
Stack Overflow
![Page 78: Functional programming](https://reader034.vdocuments.pub/reader034/viewer/2022042713/54696e30af7959e3018b5c16/html5/thumbnails/78.jpg)
Tail Recursion
![Page 79: Functional programming](https://reader034.vdocuments.pub/reader034/viewer/2022042713/54696e30af7959e3018b5c16/html5/thumbnails/79.jpg)
Tail Recursion Optimization
![Page 80: Functional programming](https://reader034.vdocuments.pub/reader034/viewer/2022042713/54696e30af7959e3018b5c16/html5/thumbnails/80.jpg)
Tail Recursion Optimization
![Page 81: Functional programming](https://reader034.vdocuments.pub/reader034/viewer/2022042713/54696e30af7959e3018b5c16/html5/thumbnails/81.jpg)
Tail Recursion
![Page 82: Functional programming](https://reader034.vdocuments.pub/reader034/viewer/2022042713/54696e30af7959e3018b5c16/html5/thumbnails/82.jpg)
Tail Recursion by Accumulator
![Page 83: Functional programming](https://reader034.vdocuments.pub/reader034/viewer/2022042713/54696e30af7959e3018b5c16/html5/thumbnails/83.jpg)
Tail Recursion Optimization
Before After
![Page 84: Functional programming](https://reader034.vdocuments.pub/reader034/viewer/2022042713/54696e30af7959e3018b5c16/html5/thumbnails/84.jpg)
Tail Recursion Optimization
Before After
![Page 85: Functional programming](https://reader034.vdocuments.pub/reader034/viewer/2022042713/54696e30af7959e3018b5c16/html5/thumbnails/85.jpg)
Tail Recursion by Accumulator
![Page 86: Functional programming](https://reader034.vdocuments.pub/reader034/viewer/2022042713/54696e30af7959e3018b5c16/html5/thumbnails/86.jpg)
Tail Recursion by Accumulator
![Page 87: Functional programming](https://reader034.vdocuments.pub/reader034/viewer/2022042713/54696e30af7959e3018b5c16/html5/thumbnails/87.jpg)
Continuation-Passing Style
![Page 88: Functional programming](https://reader034.vdocuments.pub/reader034/viewer/2022042713/54696e30af7959e3018b5c16/html5/thumbnails/88.jpg)
Continuation-Passing Style
![Page 89: Functional programming](https://reader034.vdocuments.pub/reader034/viewer/2022042713/54696e30af7959e3018b5c16/html5/thumbnails/89.jpg)
Direct Style
![Page 90: Functional programming](https://reader034.vdocuments.pub/reader034/viewer/2022042713/54696e30af7959e3018b5c16/html5/thumbnails/90.jpg)
Direct Style
![Page 91: Functional programming](https://reader034.vdocuments.pub/reader034/viewer/2022042713/54696e30af7959e3018b5c16/html5/thumbnails/91.jpg)
Continuation-Passing Style
![Page 92: Functional programming](https://reader034.vdocuments.pub/reader034/viewer/2022042713/54696e30af7959e3018b5c16/html5/thumbnails/92.jpg)
Continuation-Passing Style
![Page 93: Functional programming](https://reader034.vdocuments.pub/reader034/viewer/2022042713/54696e30af7959e3018b5c16/html5/thumbnails/93.jpg)
Continuation-Passing Style
![Page 94: Functional programming](https://reader034.vdocuments.pub/reader034/viewer/2022042713/54696e30af7959e3018b5c16/html5/thumbnails/94.jpg)
Continuation-Passing Style
![Page 95: Functional programming](https://reader034.vdocuments.pub/reader034/viewer/2022042713/54696e30af7959e3018b5c16/html5/thumbnails/95.jpg)
Continuation-Passing Style
1. 꼬리 재귀 최적화
2. 비동기 호출의 실행 순서 보장
3. 에러 분기 제어
![Page 96: Functional programming](https://reader034.vdocuments.pub/reader034/viewer/2022042713/54696e30af7959e3018b5c16/html5/thumbnails/96.jpg)
Tail Recursion
1. Tail Recursion Optimization
2. Tail Recursion by Accumulator
3. Continuation-Passing Style
![Page 97: Functional programming](https://reader034.vdocuments.pub/reader034/viewer/2022042713/54696e30af7959e3018b5c16/html5/thumbnails/97.jpg)
Q&A