SlideShare a Scribd company logo
1 of 64
Download to read offline
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.pdfIILSASTOWER
 
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 ScratchAhmed BESBES
 
interpolation-190605141327 (1).pptx
interpolation-190605141327 (1).pptxinterpolation-190605141327 (1).pptx
interpolation-190605141327 (1).pptxsinghakhil952
 
interpolation-190605141327 (1).pptx
interpolation-190605141327 (1).pptxinterpolation-190605141327 (1).pptx
interpolation-190605141327 (1).pptxsinghakhil952
 
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
 
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
 
Newton divided difference interpolation
Newton divided difference interpolationNewton divided difference interpolation
Newton divided difference interpolationVISHAL 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 expressionsJason 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

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 RSpecKenta 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 numbersKenta Murata
 
The world without float literal
The world without float literalThe world without float literal
The world without float literalKenta 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 RSpecKenta 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 bigdecimalKenta 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 schoolKenta Murata
 
Ruby の標準乱数生成器とその改善案
Ruby の標準乱数生成器とその改善案Ruby の標準乱数生成器とその改善案
Ruby の標準乱数生成器とその改善案Kenta Murata
 
5分で分かる Measure
5分で分かる Measure5分で分かる Measure
5分で分かる MeasureKenta Murata
 
Measure 単位付き数値ライブラリ
Measure 単位付き数値ライブラリMeasure 単位付き数値ライブラリ
Measure 単位付き数値ライブラリKenta Murata
 
情報学特論#02
情報学特論#02情報学特論#02
情報学特論#02Kenta Murata
 
情報学特論#01
情報学特論#01情報学特論#01
情報学特論#01Kenta 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

ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
Class 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfClass 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfakmcokerachita
 
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptxENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptxAnaBeatriceAblay2
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
Science lesson Moon for 4th quarter lesson
Science lesson Moon for 4th quarter lessonScience lesson Moon for 4th quarter lesson
Science lesson Moon for 4th quarter lessonJericReyAuditor
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxRaymartEstabillo3
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxAvyJaneVismanos
 

Recently uploaded (20)

ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
Class 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfClass 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdf
 
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptxENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Science lesson Moon for 4th quarter lesson
Science lesson Moon for 4th quarter lessonScience lesson Moon for 4th quarter lesson
Science lesson Moon for 4th quarter lesson
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptx
 

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

  • 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