940

# 하스켈과 타입

하스켈과 타입에 대해 설명합니다.

2015년 4월 4일 하스켈 프로그래밍 다섯번째 모임

April 04, 2015

## Transcript

2. ### Data type • օܻ ॳ੉ח ߣ৉য: ੗ܐഋ • ୶ஏೡ ࣻ

੓٠, ੗ܐ(data)ܳ ࠙ܨ(type)ೞח Ѫ • Ӓۢ ࠙ܨೠ ੗ܐٜ਷ যڌѱ ࢤӟ Ѫੌө?
3. ### Value • օܻ ॳ੉ח ߣ৉য: ч • য٥оী ੸ഃࢲ ա઺ী

੍൧ ࣻ ੓׮ • ੉ଃীࢲ ੷ଃਵ۽ ੹೧઴ ࣻ ੓׮
4. ### Value • օܻ ॳ੉ח ߣ৉য: ч • ݫݽܻա ٣झ௼ী ੷੢ೞҊ

ա઺ী ৌযࠅ ࣻ ੓׮ • ֎౟ਕ௼ܳ ా೧ ੹࣠ؼ ࣻ ੓׮
5. ### Value • օܻ ॳ੉ח ߣ৉য: ч • ੉ܴ૑য૕ ࣻب ੓Ҋ,

੉ܴ੉ যڃ чਸ ڷೞח૑ب ঌ ࣻ ੓׮ • ೣࣻ ੋ੗۽ ٜযт ࣻب ੓Ҋ, ೣࣻ۽ࠗఠ աৢ ࣻب ੓׮
6. ### ч > let factorial n = product [1..n] > let

x = 10 > factorial x 3628800
7. ### ੉ܴ૑য૕ ࣻ ੓׮ > let factorial n = product [1..n]

> let x = 10 > factorial x 3628800
8. ### ੉ܴ੄ ڷਸ ঌ ࣻ ੓׮ > let factorial n =

product [1..n] > let x = 10 > factorial x 3628800
9. ### ೣࣻ ੋ੗۽ ٜযт ࣻ ੓׮ > let factorial n =

product [1..n] > let x = 10 > factorial x 3628800
10. ### ೣࣻ۽ࠗఠ աৢ ࣻ ੓׮ > let factorial n = product

[1..n] > let x = 10 > factorial x 3628800
11. ### ч੄ ࢿ૕ • чٜ਷ ੷݃׮ ةౠೠ ࢿ૕੉ ੓׮ • 1

׮਺਷? 2. Ӓۢ 2 ׮਺਷? 3. • ['a', 'b', 'c']੄ ӡ੉ח? 3. • [] ׮਺਷? ݾ۾ೠప ‘׮਺’੉ۆ ަө? • 1੄ ӡ੉ח? ੿ࣻೠప ‘ӡ੉’ۆ ަө?
12. ### ч੄ ࢿ૕ > succ 1 2 > succ 2 3

> length ['a', 'b', 'c'] 3
13. ### ч੄ ࢿ૕ > succ ['a', 'b', 'c'] <interactive>:16:1: No instance

for (Enum [Char]) arising from a use of ‘succ’ In the expression: succ ['a', 'b', 'c'] In an equation for ‘it’: it = succ ['a', 'b', 'c']
14. ### ч੄ ࢿ૕ > length 1 <interactive>:17:8: No instance for (Num

[a0]) arising from the literal ‘1’ In the first argument of ‘length’, namely ‘1’ In the expression: length 1 In an equation for ‘it’: it = length 1
15. ### ੗ܐഋ • чٜ਷ ੷݃׮ ةౠೠ ࢿ૕੉ ੓׮ • Ӓ۞ա ࢿ૕੉

൚ࢎೠ Ѫՙܻ ݽইࢲ ࠙ܨೡ ࣻ ੓׮ • ‘׮਺’੉ ੓Ҋ, ف ч੉ ‘׮਺’ чٜ੉ ‘эਵݶ’ ف ч੉ ‘эҊ’, ‘؊ೡ ࣻ’ ੓Ҋ, ‘ࡓ ࣻ’ب ੓Ҋ… → ੿ࣻ ੗ܐഋ • 0ѐ ੉࢚੄ чਸ ‘ನೣ’ೡ ࣻ ੓Ҋ, ನೣػ чٜ ࢎ੉ী ‘ࣽࢲ’ о ੓Ҋ… → ݾ۾ ੗ܐഋ
16. ### ੗ܐഋ • ࠺तೠ ࢿ૕੄ чٜਸ ݽইفݶ ಞܻೞ׮ • о۸, ؔࣅਸ

ೡ ٸ ‘؊ೡ ࣻ ੓ח’ ࢿ૕੄ чٜ݅ ߉Ҋ र׮ → ࣻ ੗ܐഋ݅ ߉ਵݶ ػ׮ • о۸, іࣻܳ ҳೡ ٸ ‘чਸ ನೣೡ ࣻ ੓ח’ ࢿ૕੄ чٜ݅ ߉Ҋ र׮ → ݾ۾ ੗ܐഋ݅ ߉ਵݶ ػ׮
17. ### factorial਷ ੿ࣻ݅ ߉ח׮ > factorial ['a', 'b', 'c'] <interactive>:26:1: No

instance for (Num [Char]) arising from a use of ‘factorial’ In the expression: factorial ['a', 'b', 'c'] In an equation for ‘it’: it = factorial ['a', 'b', 'c']
18. ### ч੄ ੗ܐഋ (पઁח ੉ࠁ׮ ખ؊ ࠂ੟೤פ׮) > let factorial n

= product ([1..n] :: [Integer]) :: Integer > let x = 10 :: Integer > factorial x :: Integer 3628800 :: Integer
19. ### ੗ܐഋ ঌইࠁӝ (पઁח ੉ࠁ׮ ખ؊ ࠂ੟೤פ׮) > :t x x

:: Integer > :t factorial factorial :: Integer -> Integer
20. ### ৈӝࢶ ׮ܖ૑ ঋח ׮਺ ઱ઁ • ؀ࣻ੸ ੗ܐഋ (algebraic data

type) • Parametric polymorphism • ఋੑ௿ېझ (typeclass) • ⊥ (bottom) • ӝఋ ١١. ೞ૑݅ ށۄب ੌױ ೞझு ௏٬ द੘ оמ