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

UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfNirmal Dwivedi
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jisc
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...ZurliaSoop
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxJisc
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxVishalSingh1417
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxPooja Bhuva
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentationcamerronhm
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Pooja Bhuva
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Association for Project Management
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structuredhanjurrannsibayan2
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxheathfieldcps1
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptxMaritesTamaniVerdade
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17Celine George
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.pptRamjanShidvankar
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxmarlenawright1
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Pooja Bhuva
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.christianmathematics
 

Recently uploaded (20)

UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptx
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...
 
Spatium Project Simulation student brief
Spatium Project Simulation student briefSpatium Project Simulation student brief
Spatium Project Simulation student brief
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structure
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 

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

  • 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