Lock in $30 Savings on PRO—Offer Ends Soon! ⏳

하스켈과 타입

하스켈과 타입

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

2015년 4월 4일 하스켈 프로그래밍 다섯번째 모임
http://haskell.kr/meetup/2015-04-04/

Hong Minhee (洪 民憙)

April 04, 2015
Tweet

More Decks by Hong Minhee (洪 民憙)

Other Decks in Programming

Transcript

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

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

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

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

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

    x = 10 > factorial x 3628800
  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. ч੄ ࢿ૕ • чٜ਷ ੷݃׮ ةౠೠ ࢿ૕੉ ੓׮ • 1

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

    > length ['a', 'b', 'c'] 3
  11. ч੄ ࢿ૕ > 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']
  12. ч੄ ࢿ૕ > 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
  13. ੗ܐഋ • чٜ਷ ੷݃׮ ةౠೠ ࢿ૕੉ ੓׮ • Ӓ۞ա ࢿ૕੉

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

    ೡ ٸ ‘؊ೡ ࣻ ੓ח’ ࢿ૕੄ чٜ݅ ߉Ҋ र׮ → ࣻ ੗ܐഋ݅ ߉ਵݶ ػ׮ • о۸, іࣻܳ ҳೡ ٸ ‘чਸ ನೣೡ ࣻ ੓ח’ ࢿ૕੄ чٜ݅ ߉Ҋ र׮ → ݾ۾ ੗ܐഋ݅ ߉ਵݶ ػ׮
  15. 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']
  16. ч੄ ੗ܐഋ (पઁח ੉ࠁ׮ ખ؊ ࠂ੟೤פ׮) > let factorial n

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

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

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