SlideShare a Scribd company logo
Welcome to the world of the functional programming



 Kenta Murata                   2011.06.11 #osc11do



Monday, June 13, 2011                                 1
Monday, June 13, 2011   2
mrkn



        Ruby
        Ruby



http://www.flickr.com/photos/koichiroo/5244581973/
Monday, June 13, 2011                                3
Monday, 1
2010 3 June 13, 2011   4
Welcome to the world of the functional programming



 Kenta Murata                   2011.06.11 #osc11do



Monday, June 13, 2011                                 5
Functional Programming



Monday, June 13, 2011      6
Imperative Programming

 Procedural Programming


Monday, June 13, 2011     7
Fortran
                         Basic
                         Cobol
                         Algol
                            C
                          C++
                          Java
                          LISP

Monday, June 13, 2011             8
Monday, June 13, 2011   9
Functional Programming



Monday, June 13, 2011      10
High-order Functions

                        Lazy Evaluation


Monday, June 13, 2011                     11
Functions
           as Building Blocks
   for constructing programs
http://www.flickr.com/photos/stevendepolo/5597111652
Monday, June 13, 2011                                  12
Functions as Glue
                        for bonding functions
http://www.flickr.com/photos/pseudoego/5417919481
Monday, June 13, 2011                               13
A lot of programming
                                    languages



 available for
 functional programming
http://www.flickr.com/photos/32712959@N07/3222623206
Monday, June 13, 2011                                  14
Monday, June 13, 2011   15
Monday, June 13, 2011   16
Monday, June 13, 2011   17
High-order Functions



Monday, June 13, 2011                18
Monday, June 13, 2011   19
Monday, June 13, 2011   20
Haskell                [   ]



               e.g. []
                    [1, 2, 3]

                                                    (:)




               e.g. [1]         => 1 : []
                    [1, 2, 3]   => 1 : 2 : 3 : []




Monday, June 13, 2011                                     21
(:)      LISP
               cons

               cons        Haskell



               cons :: a -> [a] -> [a]   --
               cons x [] = [x]           --
               cons x1 (x2:xs) = x1 : (cons x2 xs)




Monday, June 13, 2011                                22
cons :: a -> [a] -> [a]   --



               cons x [] = [x]           --
               cons x1 (x2:xs) = x1 : (cons x2 xs)


               //         C++
               template <typename a>
               std::list<a>
               cons(a const& x, std::list<a> const& xs);




Monday, June 13, 2011                                      23
cons :: a -> [a] -> [a]   --



               cons x [] = [x]           --
               cons x1 (x2:xs) = x1 : (cons x2 xs)




               e.g. cons 0 [1,2,3,4]
                    => x1    0, x2   1, xs    [2,3,4]




Monday, June 13, 2011                                   24
(Int)
                                sum

               sum :: [Int] -> Int
               sum [] = 0
               sum (n:ns) = n + (sum ns)




Monday, June 13, 2011                      25
cons     sum

               cons :: a -> [a] -> [a]
               cons x [] = [x]
               cons x1 (x2:xs) = x1 : (cons x2 xs)

               sum :: [Int] -> Int
               sum [] = 0
               sum (n:ns) = n + (sum ns)




Monday, June 13, 2011                                26
cons x [] = [x]
               sum    [] = 0


               cons x1 (x2:xs) = x1 : (cons x2 xs)
               sum     (n :ns) = n + (sum      ns)




Monday, June 13, 2011                                27
(Int)
                                product

               product :: [Int] -> Int
               product [] = 1
               product (n:ns) = n * product ns




Monday, June 13, 2011                            28
cons x [] = [x]
               sum     [] = 0
               product [] = 1


               cons x1 (x2:xs) = x1 : (cons x2 xs)
               sum     (n :ns) = n + (sum      ns)
               product (n :ns) = n * (product ns)




Monday, June 13, 2011                                29
(Bool)
                                     allTrue



               allTrue :: [Bool] -> Bool
               allTrue [] = True
               allTrue (b:bs) = b && allTrue ns




Monday, June 13, 2011                             30
(Bool)
                                     anyTrue



               anyTrue :: [Bool] -> Bool
               anyTrue [] = False
               anyTrue (b:bs) = b || anyTrue ns




Monday, June 13, 2011                             31
cons x    []   =   [x]
               sum       []   =   0
               product   []   =   1
               allTrue   []   =   True
               anyTrue   []   =   False


               cons x1   (x2:xs)    =   x1   :    (cons x2   xs)
               sum       (n :ns)    =   n    +    (sum       ns)
               product   (n :ns)    =   n    *    (product   ns)
               allTrue   (b :bs)    =   b    &&   (allTrue   bs)
               anyTrue   (b :bs)    =   b    ||   (anyTrue   bs)




Monday, June 13, 2011                                              32
cons x    []   =   [x]
               sum       []   =   0
               product   []   =   1
               allTrue   []   =   True
               anyTrue   []   =   False


               cons x1   (x2:xs)    =   x1   :    (cons x2   xs)
               sum       (n :ns)    =   n    +    (sum       ns)
               product   (n :ns)    =   n    *    (product   ns)
               allTrue   (b :bs)    =   b    &&   (allTrue   bs)
               anyTrue   (b :bs)    =   b    ||   (anyTrue   bs)




Monday, June 13, 2011                                              32
reduce :: (a -> [a] -> a) -> a -> [a] -> a
               reduce f x0 [] = x0
               reduce f x0 (x1:xs) = f x1 (reduce f x0 xs)




               sum       =   reduce   (+)    0
               product   =   reduce   (*)    1
               allTrue   =   reduce   (&&)   True
               anyTrue   =   reduce   (||)   False




Monday, June 13, 2011                                        33
reduce :: (a -> [a] -> a) -> a -> [a] -> a
               reduce f x0 [] = x0
               reduce f x0 (x1:xs) = f x1 (reduce f x0 xs)




               sum       =   reduce   (+)    0
               product   =   reduce   (*)    1
               allTrue   =   reduce   (&&)   True
               anyTrue   =   reduce   (||)   False




Monday, June 13, 2011                                        33
reduce :: (a -> [a] -> a) -> a -> [a] -> a
               reduce f x0 [] = x0
               reduce f x0 (x1:xs) = f x1 (reduce f x0 xs)




               sum       =   reduce   (+)    0
               product   =   reduce   (*)    1
               allTrue   =   reduce   (&&)   True
               anyTrue   =   reduce   (||)   False




Monday, June 13, 2011                                        33
reduce :: (a -> [a] -> a) -> a -> [a] -> a
               reduce f x0 [] = x0
               reduce f x0 (x1:xs) = f x1 (reduce f x0 xs)




               sum       =   reduce   (+)    0
               product   =   reduce   (*)    1
               allTrue   =   reduce   (&&)   True
               anyTrue   =   reduce   (||)   False




Monday, June 13, 2011                                        33
cons     reduce

               append :: [a] -> [a] -> [a]
               append xs ys = reduce (:) ys xs




               append [1,2] [3,4]
               -> reduce (:) [3,4] [1,2]
               -> reduce (:) [3,4] (1:2:[])
               -> 1 : (reduce (:) [3,4] (2:[]))
               -> 1 : 2 : (reduce (:) [3,4] [])
               -> 1 : 2 : [3,4]
               -> [1,2,3,4]




Monday, June 13, 2011                             34
Monday, June 13, 2011   35
Monday, June 13, 2011   36
Monday, June 13, 2011   37
Functions
           as Building Blocks
   for constructing programs
http://www.flickr.com/photos/stevendepolo/5597111652
Monday, June 13, 2011                                  38
Functions as Glue
                        for bonding functions
http://www.flickr.com/photos/pseudoego/5417919481
Monday, June 13, 2011                               39
Monday, June 13, 2011   40
-- Haskell
               reduce (+) 0 [1..10]

               // C++
               int ns[] = {1,2,3,4,5,6,7,8,9,10};
               std::accumulate(ns, ns + 10, 0, &std::plus<int>);

               # Ruby
               [*1..10].inject(0, :+)




Monday, June 13, 2011                                              41
Monday, June 13, 2011   42
Lazy Evaluation



Monday, June 13, 2011                     43
Monday, June 13, 2011   44
Monday, June 13, 2011   45
http://www.sampou.org/haskell/article/whyfp.html
Monday, June 13, 2011                              46
http://www.infoq.com/interviews/john-hughes-fp
Monday, June 13, 2011                            47
http://weblog.raganwald.com/2007/03/why-why-functional-programming-matters.html
Monday, June 13, 2011                                                             48
language   evaluation   pureness

                         Haskell      lazy        pure

               Concurrent Clean       lazy        pure

                         OCaml       strict      impure

                           F#        strict      impure

                        Scheme       strict      impure



Monday, June 13, 2011                                      49
language   evaluation   pureness

                         Haskell      lazy        pure

               Concurrent Clean       lazy        pure

                         OCaml       strict      impure

                           F#        strict      impure

                        Scheme       strict      impure



Monday, June 13, 2011                                      50
Monday, June 13, 2011   51
Monday, 1
2010 3 June 13, 2011   52
Functional Programming



Monday, June 13, 2011      53
A lot of programming
                                    languages



 available for
 functional programming
http://www.flickr.com/photos/32712959@N07/3222623206
Monday, June 13, 2011                                  54
Monday, June 13, 2011   55
High-order Functions



Monday, June 13, 2011                56
Functions
           as Building Blocks
   for constructing programs
http://www.flickr.com/photos/stevendepolo/5597111652
Monday, June 13, 2011                                  57
Functions as Glue
                        for bonding functions
http://www.flickr.com/photos/pseudoego/5417919481
Monday, June 13, 2011                               58
Lazy Evaluation



Monday, June 13, 2011                     59
Monday, June 13, 2011   60

More Related Content

Similar to 関数型プログラミングの世界

differential-calculus-1-23.pdf
differential-calculus-1-23.pdfdifferential-calculus-1-23.pdf
differential-calculus-1-23.pdf
IILSASTOWER
 
Introduction to Neural Networks and Deep Learning from Scratch
Introduction to Neural Networks and Deep Learning from ScratchIntroduction to Neural Networks and Deep Learning from Scratch
Introduction to Neural Networks and Deep Learning from Scratch
Ahmed BESBES
 
interpolation-190605141327 (1).pptx
interpolation-190605141327 (1).pptxinterpolation-190605141327 (1).pptx
interpolation-190605141327 (1).pptx
singhakhil952
 
interpolation-190605141327 (1).pptx
interpolation-190605141327 (1).pptxinterpolation-190605141327 (1).pptx
interpolation-190605141327 (1).pptx
singhakhil952
 
Christian Gill ''Functional programming for the people''
Christian Gill ''Functional programming for the people''Christian Gill ''Functional programming for the people''
Christian Gill ''Functional programming for the people''
OdessaJS Conf
 
24 modelling
24 modelling24 modelling
24 modelling
Hadley Wickham
 
04 factorising, roots, zeros, quadratics eqn (2)
04   factorising, roots, zeros, quadratics eqn (2)04   factorising, roots, zeros, quadratics eqn (2)
04 factorising, roots, zeros, quadratics eqn (2)
majapamaya
 
Polynomials
PolynomialsPolynomials
Polynomials
Jonghoon Park
 
Interpolation
InterpolationInterpolation
Interpolation
Dmytro Mitin
 
Newton divided difference interpolation
Newton divided difference interpolationNewton divided difference interpolation
Newton divided difference interpolation
VISHAL DONGA
 
Unit 8(rational expressions) week 22 - simplifying rational expressions
Unit 8(rational expressions)   week 22 - simplifying rational expressionsUnit 8(rational expressions)   week 22 - simplifying rational expressions
Unit 8(rational expressions) week 22 - simplifying rational expressions
Jason Morgan
 

Similar to 関数型プログラミングの世界 (11)

differential-calculus-1-23.pdf
differential-calculus-1-23.pdfdifferential-calculus-1-23.pdf
differential-calculus-1-23.pdf
 
Introduction to Neural Networks and Deep Learning from Scratch
Introduction to Neural Networks and Deep Learning from ScratchIntroduction to Neural Networks and Deep Learning from Scratch
Introduction to Neural Networks and Deep Learning from Scratch
 
interpolation-190605141327 (1).pptx
interpolation-190605141327 (1).pptxinterpolation-190605141327 (1).pptx
interpolation-190605141327 (1).pptx
 
interpolation-190605141327 (1).pptx
interpolation-190605141327 (1).pptxinterpolation-190605141327 (1).pptx
interpolation-190605141327 (1).pptx
 
Christian Gill ''Functional programming for the people''
Christian Gill ''Functional programming for the people''Christian Gill ''Functional programming for the people''
Christian Gill ''Functional programming for the people''
 
24 modelling
24 modelling24 modelling
24 modelling
 
04 factorising, roots, zeros, quadratics eqn (2)
04   factorising, roots, zeros, quadratics eqn (2)04   factorising, roots, zeros, quadratics eqn (2)
04 factorising, roots, zeros, quadratics eqn (2)
 
Polynomials
PolynomialsPolynomials
Polynomials
 
Interpolation
InterpolationInterpolation
Interpolation
 
Newton divided difference interpolation
Newton divided difference interpolationNewton divided difference interpolation
Newton divided difference interpolation
 
Unit 8(rational expressions) week 22 - simplifying rational expressions
Unit 8(rational expressions)   week 22 - simplifying rational expressionsUnit 8(rational expressions)   week 22 - simplifying rational expressions
Unit 8(rational expressions) week 22 - simplifying rational expressions
 

More from Kenta Murata

Float is Legacy
Float is LegacyFloat is Legacy
Float is Legacy
Kenta Murata
 
Introduction to ATDD with Cucumber and RSpec
Introduction to ATDD with Cucumber and RSpecIntroduction to ATDD with Cucumber and RSpec
Introduction to ATDD with Cucumber and RSpec
Kenta Murata
 
The world without the literal notation for floating-point numbers
The world without the literal notation for floating-point numbersThe world without the literal notation for floating-point numbers
The world without the literal notation for floating-point numbers
Kenta Murata
 
The world without float literal
The world without float literalThe world without float literal
The world without float literal
Kenta Murata
 
Ruby 1.9.3 の新機能と変更点
Ruby 1.9.3 の新機能と変更点Ruby 1.9.3 の新機能と変更点
Ruby 1.9.3 の新機能と変更点
Kenta Murata
 
Let's begin Behavior Driven Development using RSpec
Let's begin Behavior Driven Development using RSpecLet's begin Behavior Driven Development using RSpec
Let's begin Behavior Driven Development using RSpec
Kenta Murata
 
Rubyをたのしくするために私が考えていること
Rubyをたのしくするために私が考えていることRubyをたのしくするために私が考えていること
Rubyをたのしくするために私が考えていること
Kenta Murata
 
Ruby の懸案事項
Ruby の懸案事項Ruby の懸案事項
Ruby の懸案事項
Kenta Murata
 
5分弱で分かる量子ビット
5分弱で分かる量子ビット5分弱で分かる量子ビット
5分弱で分かる量子ビット
Kenta Murata
 
Rubykaigi2010mrkn bigdecimal
Rubykaigi2010mrkn bigdecimalRubykaigi2010mrkn bigdecimal
Rubykaigi2010mrkn bigdecimal
Kenta Murata
 
Ruby における絵文字エンコーディング間の相互変換ダイアグラム (案)
Ruby における絵文字エンコーディング間の相互変換ダイアグラム (案)Ruby における絵文字エンコーディング間の相互変換ダイアグラム (案)
Ruby における絵文字エンコーディング間の相互変換ダイアグラム (案)
Kenta Murata
 
校内勉強会のススメ An encouragement to hold workshops In your school
校内勉強会のススメ An encouragement to hold workshops In your school校内勉強会のススメ An encouragement to hold workshops In your school
校内勉強会のススメ An encouragement to hold workshops In your school
Kenta Murata
 
Ruby の標準乱数生成器とその改善案
Ruby の標準乱数生成器とその改善案Ruby の標準乱数生成器とその改善案
Ruby の標準乱数生成器とその改善案
Kenta Murata
 
5分で分かる Measure
5分で分かる Measure5分で分かる Measure
5分で分かる Measure
Kenta Murata
 
Measure 単位付き数値ライブラリ
Measure 単位付き数値ライブラリMeasure 単位付き数値ライブラリ
Measure 単位付き数値ライブラリ
Kenta Murata
 
情報学特論#02
情報学特論#02情報学特論#02
情報学特論#02Kenta Murata
 
情報学特論#01
情報学特論#01情報学特論#01
情報学特論#01
Kenta Murata
 
北海道関数型言語勉強会@札幌#2のお知らせ
北海道関数型言語勉強会@札幌#2のお知らせ北海道関数型言語勉強会@札幌#2のお知らせ
北海道関数型言語勉強会@札幌#2のお知らせKenta Murata
 
Ruby 拡張モジュール入門
Ruby 拡張モジュール入門Ruby 拡張モジュール入門
Ruby 拡張モジュール入門
Kenta Murata
 

More from Kenta Murata (19)

Float is Legacy
Float is LegacyFloat is Legacy
Float is Legacy
 
Introduction to ATDD with Cucumber and RSpec
Introduction to ATDD with Cucumber and RSpecIntroduction to ATDD with Cucumber and RSpec
Introduction to ATDD with Cucumber and RSpec
 
The world without the literal notation for floating-point numbers
The world without the literal notation for floating-point numbersThe world without the literal notation for floating-point numbers
The world without the literal notation for floating-point numbers
 
The world without float literal
The world without float literalThe world without float literal
The world without float literal
 
Ruby 1.9.3 の新機能と変更点
Ruby 1.9.3 の新機能と変更点Ruby 1.9.3 の新機能と変更点
Ruby 1.9.3 の新機能と変更点
 
Let's begin Behavior Driven Development using RSpec
Let's begin Behavior Driven Development using RSpecLet's begin Behavior Driven Development using RSpec
Let's begin Behavior Driven Development using RSpec
 
Rubyをたのしくするために私が考えていること
Rubyをたのしくするために私が考えていることRubyをたのしくするために私が考えていること
Rubyをたのしくするために私が考えていること
 
Ruby の懸案事項
Ruby の懸案事項Ruby の懸案事項
Ruby の懸案事項
 
5分弱で分かる量子ビット
5分弱で分かる量子ビット5分弱で分かる量子ビット
5分弱で分かる量子ビット
 
Rubykaigi2010mrkn bigdecimal
Rubykaigi2010mrkn bigdecimalRubykaigi2010mrkn bigdecimal
Rubykaigi2010mrkn bigdecimal
 
Ruby における絵文字エンコーディング間の相互変換ダイアグラム (案)
Ruby における絵文字エンコーディング間の相互変換ダイアグラム (案)Ruby における絵文字エンコーディング間の相互変換ダイアグラム (案)
Ruby における絵文字エンコーディング間の相互変換ダイアグラム (案)
 
校内勉強会のススメ An encouragement to hold workshops In your school
校内勉強会のススメ An encouragement to hold workshops In your school校内勉強会のススメ An encouragement to hold workshops In your school
校内勉強会のススメ An encouragement to hold workshops In your school
 
Ruby の標準乱数生成器とその改善案
Ruby の標準乱数生成器とその改善案Ruby の標準乱数生成器とその改善案
Ruby の標準乱数生成器とその改善案
 
5分で分かる Measure
5分で分かる Measure5分で分かる Measure
5分で分かる Measure
 
Measure 単位付き数値ライブラリ
Measure 単位付き数値ライブラリMeasure 単位付き数値ライブラリ
Measure 単位付き数値ライブラリ
 
情報学特論#02
情報学特論#02情報学特論#02
情報学特論#02
 
情報学特論#01
情報学特論#01情報学特論#01
情報学特論#01
 
北海道関数型言語勉強会@札幌#2のお知らせ
北海道関数型言語勉強会@札幌#2のお知らせ北海道関数型言語勉強会@札幌#2のお知らせ
北海道関数型言語勉強会@札幌#2のお知らせ
 
Ruby 拡張モジュール入門
Ruby 拡張モジュール入門Ruby 拡張モジュール入門
Ruby 拡張モジュール入門
 

Recently uploaded

RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem studentsRHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
Himanshu Rai
 
Hindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdfHindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdf
Dr. Mulla Adam Ali
 
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
National Information Standards Organization (NISO)
 
How to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRMHow to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRM
Celine George
 
Life upper-Intermediate B2 Workbook for student
Life upper-Intermediate B2 Workbook for studentLife upper-Intermediate B2 Workbook for student
Life upper-Intermediate B2 Workbook for student
NgcHiNguyn25
 
How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17
Celine George
 
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptxChapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
A Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdfA Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdf
Jean Carlos Nunes Paixão
 
PIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf IslamabadPIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf Islamabad
AyyanKhan40
 
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptxPrésentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
siemaillard
 
How to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP ModuleHow to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP Module
Celine George
 
Main Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docxMain Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docx
adhitya5119
 
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UPLAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
RAHUL
 
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptxNEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
iammrhaywood
 
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Dr. Vinod Kumar Kanvaria
 
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
Nguyen Thanh Tu Collection
 
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
GeorgeMilliken2
 
Film vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movieFilm vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movie
Nicholas Montgomery
 
Leveraging Generative AI to Drive Nonprofit Innovation
Leveraging Generative AI to Drive Nonprofit InnovationLeveraging Generative AI to Drive Nonprofit Innovation
Leveraging Generative AI to Drive Nonprofit Innovation
TechSoup
 
คำศัพท์ คำพื้นฐานการอ่าน ภาษาอังกฤษ ระดับชั้น ม.1
คำศัพท์ คำพื้นฐานการอ่าน ภาษาอังกฤษ ระดับชั้น ม.1คำศัพท์ คำพื้นฐานการอ่าน ภาษาอังกฤษ ระดับชั้น ม.1
คำศัพท์ คำพื้นฐานการอ่าน ภาษาอังกฤษ ระดับชั้น ม.1
สมใจ จันสุกสี
 

Recently uploaded (20)

RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem studentsRHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
 
Hindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdfHindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdf
 
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
 
How to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRMHow to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRM
 
Life upper-Intermediate B2 Workbook for student
Life upper-Intermediate B2 Workbook for studentLife upper-Intermediate B2 Workbook for student
Life upper-Intermediate B2 Workbook for student
 
How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17
 
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptxChapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
 
A Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdfA Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdf
 
PIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf IslamabadPIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf Islamabad
 
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptxPrésentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
 
How to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP ModuleHow to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP Module
 
Main Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docxMain Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docx
 
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UPLAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
 
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptxNEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
 
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
 
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
 
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
 
Film vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movieFilm vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movie
 
Leveraging Generative AI to Drive Nonprofit Innovation
Leveraging Generative AI to Drive Nonprofit InnovationLeveraging Generative AI to Drive Nonprofit Innovation
Leveraging Generative AI to Drive Nonprofit Innovation
 
คำศัพท์ คำพื้นฐานการอ่าน ภาษาอังกฤษ ระดับชั้น ม.1
คำศัพท์ คำพื้นฐานการอ่าน ภาษาอังกฤษ ระดับชั้น ม.1คำศัพท์ คำพื้นฐานการอ่าน ภาษาอังกฤษ ระดับชั้น ม.1
คำศัพท์ คำพื้นฐานการอ่าน ภาษาอังกฤษ ระดับชั้น ม.1
 

関数型プログラミングの世界

  • 1. Welcome to the world of the functional programming Kenta Murata 2011.06.11 #osc11do Monday, June 13, 2011 1
  • 3. mrkn Ruby Ruby http://www.flickr.com/photos/koichiroo/5244581973/ Monday, June 13, 2011 3
  • 4. Monday, 1 2010 3 June 13, 2011 4
  • 5. Welcome to the world of the functional programming Kenta Murata 2011.06.11 #osc11do Monday, June 13, 2011 5
  • 7. Imperative Programming Procedural Programming Monday, June 13, 2011 7
  • 8. Fortran Basic Cobol Algol C C++ Java LISP Monday, June 13, 2011 8
  • 11. High-order Functions Lazy Evaluation Monday, June 13, 2011 11
  • 12. Functions as Building Blocks for constructing programs http://www.flickr.com/photos/stevendepolo/5597111652 Monday, June 13, 2011 12
  • 13. Functions as Glue for bonding functions http://www.flickr.com/photos/pseudoego/5417919481 Monday, June 13, 2011 13
  • 14. A lot of programming languages available for functional programming http://www.flickr.com/photos/32712959@N07/3222623206 Monday, June 13, 2011 14
  • 15. Monday, June 13, 2011 15
  • 16. Monday, June 13, 2011 16
  • 17. Monday, June 13, 2011 17
  • 19. Monday, June 13, 2011 19
  • 20. Monday, June 13, 2011 20
  • 21. Haskell [ ] e.g. [] [1, 2, 3] (:) e.g. [1] => 1 : [] [1, 2, 3] => 1 : 2 : 3 : [] Monday, June 13, 2011 21
  • 22. (:) LISP cons cons Haskell cons :: a -> [a] -> [a] -- cons x [] = [x] -- cons x1 (x2:xs) = x1 : (cons x2 xs) Monday, June 13, 2011 22
  • 23. cons :: a -> [a] -> [a] -- cons x [] = [x] -- cons x1 (x2:xs) = x1 : (cons x2 xs) // C++ template <typename a> std::list<a> cons(a const& x, std::list<a> const& xs); Monday, June 13, 2011 23
  • 24. cons :: a -> [a] -> [a] -- cons x [] = [x] -- cons x1 (x2:xs) = x1 : (cons x2 xs) e.g. cons 0 [1,2,3,4] => x1 0, x2 1, xs [2,3,4] Monday, June 13, 2011 24
  • 25. (Int) sum sum :: [Int] -> Int sum [] = 0 sum (n:ns) = n + (sum ns) Monday, June 13, 2011 25
  • 26. cons sum cons :: a -> [a] -> [a] cons x [] = [x] cons x1 (x2:xs) = x1 : (cons x2 xs) sum :: [Int] -> Int sum [] = 0 sum (n:ns) = n + (sum ns) Monday, June 13, 2011 26
  • 27. cons x [] = [x] sum [] = 0 cons x1 (x2:xs) = x1 : (cons x2 xs) sum (n :ns) = n + (sum ns) Monday, June 13, 2011 27
  • 28. (Int) product product :: [Int] -> Int product [] = 1 product (n:ns) = n * product ns Monday, June 13, 2011 28
  • 29. cons x [] = [x] sum [] = 0 product [] = 1 cons x1 (x2:xs) = x1 : (cons x2 xs) sum (n :ns) = n + (sum ns) product (n :ns) = n * (product ns) Monday, June 13, 2011 29
  • 30. (Bool) allTrue allTrue :: [Bool] -> Bool allTrue [] = True allTrue (b:bs) = b && allTrue ns Monday, June 13, 2011 30
  • 31. (Bool) anyTrue anyTrue :: [Bool] -> Bool anyTrue [] = False anyTrue (b:bs) = b || anyTrue ns Monday, June 13, 2011 31
  • 32. cons x [] = [x] sum [] = 0 product [] = 1 allTrue [] = True anyTrue [] = False cons x1 (x2:xs) = x1 : (cons x2 xs) sum (n :ns) = n + (sum ns) product (n :ns) = n * (product ns) allTrue (b :bs) = b && (allTrue bs) anyTrue (b :bs) = b || (anyTrue bs) Monday, June 13, 2011 32
  • 33. cons x [] = [x] sum [] = 0 product [] = 1 allTrue [] = True anyTrue [] = False cons x1 (x2:xs) = x1 : (cons x2 xs) sum (n :ns) = n + (sum ns) product (n :ns) = n * (product ns) allTrue (b :bs) = b && (allTrue bs) anyTrue (b :bs) = b || (anyTrue bs) Monday, June 13, 2011 32
  • 34. reduce :: (a -> [a] -> a) -> a -> [a] -> a reduce f x0 [] = x0 reduce f x0 (x1:xs) = f x1 (reduce f x0 xs) sum = reduce (+) 0 product = reduce (*) 1 allTrue = reduce (&&) True anyTrue = reduce (||) False Monday, June 13, 2011 33
  • 35. reduce :: (a -> [a] -> a) -> a -> [a] -> a reduce f x0 [] = x0 reduce f x0 (x1:xs) = f x1 (reduce f x0 xs) sum = reduce (+) 0 product = reduce (*) 1 allTrue = reduce (&&) True anyTrue = reduce (||) False Monday, June 13, 2011 33
  • 36. reduce :: (a -> [a] -> a) -> a -> [a] -> a reduce f x0 [] = x0 reduce f x0 (x1:xs) = f x1 (reduce f x0 xs) sum = reduce (+) 0 product = reduce (*) 1 allTrue = reduce (&&) True anyTrue = reduce (||) False Monday, June 13, 2011 33
  • 37. reduce :: (a -> [a] -> a) -> a -> [a] -> a reduce f x0 [] = x0 reduce f x0 (x1:xs) = f x1 (reduce f x0 xs) sum = reduce (+) 0 product = reduce (*) 1 allTrue = reduce (&&) True anyTrue = reduce (||) False Monday, June 13, 2011 33
  • 38. cons reduce append :: [a] -> [a] -> [a] append xs ys = reduce (:) ys xs append [1,2] [3,4] -> reduce (:) [3,4] [1,2] -> reduce (:) [3,4] (1:2:[]) -> 1 : (reduce (:) [3,4] (2:[])) -> 1 : 2 : (reduce (:) [3,4] []) -> 1 : 2 : [3,4] -> [1,2,3,4] Monday, June 13, 2011 34
  • 39. Monday, June 13, 2011 35
  • 40. Monday, June 13, 2011 36
  • 41. Monday, June 13, 2011 37
  • 42. Functions as Building Blocks for constructing programs http://www.flickr.com/photos/stevendepolo/5597111652 Monday, June 13, 2011 38
  • 43. Functions as Glue for bonding functions http://www.flickr.com/photos/pseudoego/5417919481 Monday, June 13, 2011 39
  • 44. Monday, June 13, 2011 40
  • 45. -- Haskell reduce (+) 0 [1..10] // C++ int ns[] = {1,2,3,4,5,6,7,8,9,10}; std::accumulate(ns, ns + 10, 0, &std::plus<int>); # Ruby [*1..10].inject(0, :+) Monday, June 13, 2011 41
  • 46. Monday, June 13, 2011 42
  • 48. Monday, June 13, 2011 44
  • 49. Monday, June 13, 2011 45
  • 53. language evaluation pureness Haskell lazy pure Concurrent Clean lazy pure OCaml strict impure F# strict impure Scheme strict impure Monday, June 13, 2011 49
  • 54. language evaluation pureness Haskell lazy pure Concurrent Clean lazy pure OCaml strict impure F# strict impure Scheme strict impure Monday, June 13, 2011 50
  • 55. Monday, June 13, 2011 51
  • 56. Monday, 1 2010 3 June 13, 2011 52
  • 58. A lot of programming languages available for functional programming http://www.flickr.com/photos/32712959@N07/3222623206 Monday, June 13, 2011 54
  • 59. Monday, June 13, 2011 55
  • 61. Functions as Building Blocks for constructing programs http://www.flickr.com/photos/stevendepolo/5597111652 Monday, June 13, 2011 57
  • 62. Functions as Glue for bonding functions http://www.flickr.com/photos/pseudoego/5417919481 Monday, June 13, 2011 58
  • 64. Monday, June 13, 2011 60

Editor's Notes

  1. \n
  2. \n
  3. \n
  4. \n
  5. \n
  6. \n
  7. \n
  8. \n
  9. \n
  10. \n
  11. \n
  12. \n
  13. \n
  14. \n
  15. \n
  16. \n
  17. \n
  18. \n
  19. \n
  20. \n
  21. \n
  22. \n
  23. \n
  24. \n
  25. \n
  26. \n
  27. \n
  28. \n
  29. \n
  30. \n
  31. \n
  32. \n
  33. \n
  34. \n
  35. \n
  36. \n
  37. \n
  38. \n
  39. \n
  40. \n
  41. \n
  42. \n
  43. \n
  44. \n
  45. \n
  46. \n
  47. \n
  48. \n
  49. \n
  50. \n
  51. \n
  52. \n
  53. \n
  54. \n
  55. \n
  56. \n
  57. \n
  58. \n
  59. \n
  60. \n
  61. \n
  62. \n
  63. \n
  64. \n
  65. \n
  66. \n