SlideShare a Scribd company logo
1 of 5
Download to read offline
홍은기
하스켈과 리스트
리스트의 정의:
1. A list or sequence is an abstract data
type that represents an ordered sequence of
values, where the same value may occur
more than once. (Wikipedia)
2. 빈 리스트이거나 원소 하나와 리스트로 이루어진 자
료구조.
리스트란?
빈 리스트이거나- []
원소 하나와 리스트로 이루어진 자료구조- 1, []
[1] –> 1, []
[1, 2] –> 1, [2] –> 1, [2, []]
[1, 2, 3] -> 1, [2, [3, []]]
이러한 재귀적인 구조가 하스켈 문법에서 (x:xs)로 표
현됨.
리스트란?
리스트 내의 모든 원소를 합하는 함수 addAll을 만들어
보자.
addAll :: [Int] -> Int
addAll [] = 0
addAll (x:xs) = x + addAll xs
재귀적으로 생각하기
addAll :: [Int] -> Int
addAll [] = 0
addAll (x:xs) = x + addAll xs
입력값이 [1, 2, 3, 4] 일 때,
1 + addAll [2, 3, 4]
2 + addAll [3, 4]
3 + addAll [4]
4 + addAll [] // addAll[] = 0
출력: 1 + 2 + 3 + 4 + 0 = 10
재귀적으로 생각하기

More Related Content

More from EunGi Hong

Haskell and Function
Haskell and FunctionHaskell and Function
Haskell and FunctionEunGi Hong
 
Wordswordswords
WordswordswordsWordswordswords
WordswordswordsEunGi Hong
 
Introduction to Natural Language Processing
Introduction to Natural Language ProcessingIntroduction to Natural Language Processing
Introduction to Natural Language ProcessingEunGi Hong
 
Ah Counter App 마무리
Ah Counter App 마무리Ah Counter App 마무리
Ah Counter App 마무리EunGi Hong
 
안드로이드 개발하기 3rd week
안드로이드 개발하기 3rd week안드로이드 개발하기 3rd week
안드로이드 개발하기 3rd weekEunGi Hong
 
안드로이드 개발하기 2nd week
안드로이드 개발하기 2nd week안드로이드 개발하기 2nd week
안드로이드 개발하기 2nd weekEunGi Hong
 
안드로이드 개발하기_1st
안드로이드 개발하기_1st안드로이드 개발하기_1st
안드로이드 개발하기_1stEunGi Hong
 
Python learning for Natural Language Processing (2nd)
Python learning for Natural Language Processing (2nd)Python learning for Natural Language Processing (2nd)
Python learning for Natural Language Processing (2nd)EunGi Hong
 
Python Learning for Natural Language Processing
Python Learning for Natural Language ProcessingPython Learning for Natural Language Processing
Python Learning for Natural Language ProcessingEunGi Hong
 

More from EunGi Hong (11)

Haskell and Function
Haskell and FunctionHaskell and Function
Haskell and Function
 
Wordswordswords
WordswordswordsWordswordswords
Wordswordswords
 
Introduction to Natural Language Processing
Introduction to Natural Language ProcessingIntroduction to Natural Language Processing
Introduction to Natural Language Processing
 
Automata
AutomataAutomata
Automata
 
Ah Counter App 마무리
Ah Counter App 마무리Ah Counter App 마무리
Ah Counter App 마무리
 
Linguistics
LinguisticsLinguistics
Linguistics
 
안드로이드 개발하기 3rd week
안드로이드 개발하기 3rd week안드로이드 개발하기 3rd week
안드로이드 개발하기 3rd week
 
안드로이드 개발하기 2nd week
안드로이드 개발하기 2nd week안드로이드 개발하기 2nd week
안드로이드 개발하기 2nd week
 
안드로이드 개발하기_1st
안드로이드 개발하기_1st안드로이드 개발하기_1st
안드로이드 개발하기_1st
 
Python learning for Natural Language Processing (2nd)
Python learning for Natural Language Processing (2nd)Python learning for Natural Language Processing (2nd)
Python learning for Natural Language Processing (2nd)
 
Python Learning for Natural Language Processing
Python Learning for Natural Language ProcessingPython Learning for Natural Language Processing
Python Learning for Natural Language Processing
 

Haskell and List

  • 2. 리스트의 정의: 1. A list or sequence is an abstract data type that represents an ordered sequence of values, where the same value may occur more than once. (Wikipedia) 2. 빈 리스트이거나 원소 하나와 리스트로 이루어진 자 료구조. 리스트란?
  • 3. 빈 리스트이거나- [] 원소 하나와 리스트로 이루어진 자료구조- 1, [] [1] –> 1, [] [1, 2] –> 1, [2] –> 1, [2, []] [1, 2, 3] -> 1, [2, [3, []]] 이러한 재귀적인 구조가 하스켈 문법에서 (x:xs)로 표 현됨. 리스트란?
  • 4. 리스트 내의 모든 원소를 합하는 함수 addAll을 만들어 보자. addAll :: [Int] -> Int addAll [] = 0 addAll (x:xs) = x + addAll xs 재귀적으로 생각하기
  • 5. addAll :: [Int] -> Int addAll [] = 0 addAll (x:xs) = x + addAll xs 입력값이 [1, 2, 3, 4] 일 때, 1 + addAll [2, 3, 4] 2 + addAll [3, 4] 3 + addAll [4] 4 + addAll [] // addAll[] = 0 출력: 1 + 2 + 3 + 4 + 0 = 10 재귀적으로 생각하기