Successfully reported this slideshow.

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

24

Share

Upcoming SlideShare
Float is Legacy
Float is Legacy
Loading in …3
×
1 of 64
1 of 64

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

24

Share

Download to read offline

関数型プログラミングで重要となる高階関数と遅延評価について紹介。時間の関係で、遅延評価については Why Functional Programming Matters とその関連 URL の紹介しかしていない。

関数型プログラミングで重要となる高階関数と遅延評価について紹介。時間の関係で、遅延評価については Why Functional Programming Matters とその関連 URL の紹介しかしていない。

More Related Content

Related Books

Free with a 14 day trial from Scribd

See all

Related Audiobooks

Free with a 14 day trial from Scribd

See all

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

  1. 1. Welcome to the world of the functional programming Kenta Murata 2011.06.11 #osc11do Monday, June 13, 2011 1
  2. 2. Monday, June 13, 2011 2
  3. 3. mrkn Ruby Ruby http://www.flickr.com/photos/koichiroo/5244581973/ Monday, June 13, 2011 3
  4. 4. Monday, 1 2010 3 June 13, 2011 4
  5. 5. Welcome to the world of the functional programming Kenta Murata 2011.06.11 #osc11do Monday, June 13, 2011 5
  6. 6. Functional Programming Monday, June 13, 2011 6
  7. 7. Imperative Programming Procedural Programming Monday, June 13, 2011 7
  8. 8. Fortran Basic Cobol Algol C C++ Java LISP Monday, June 13, 2011 8
  9. 9. Monday, June 13, 2011 9
  10. 10. Functional Programming Monday, June 13, 2011 10
  11. 11. High-order Functions Lazy Evaluation Monday, June 13, 2011 11
  12. 12. Functions as Building Blocks for constructing programs http://www.flickr.com/photos/stevendepolo/5597111652 Monday, June 13, 2011 12
  13. 13. Functions as Glue for bonding functions http://www.flickr.com/photos/pseudoego/5417919481 Monday, June 13, 2011 13
  14. 14. A lot of programming languages available for functional programming http://www.flickr.com/photos/32712959@N07/3222623206 Monday, June 13, 2011 14
  15. 15. Monday, June 13, 2011 15
  16. 16. Monday, June 13, 2011 16
  17. 17. Monday, June 13, 2011 17
  18. 18. High-order Functions Monday, June 13, 2011 18
  19. 19. Monday, June 13, 2011 19
  20. 20. Monday, June 13, 2011 20
  21. 21. Haskell [ ] e.g. [] [1, 2, 3] (:) e.g. [1] => 1 : [] [1, 2, 3] => 1 : 2 : 3 : [] Monday, June 13, 2011 21
  22. 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. 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. 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. 25. (Int) sum sum :: [Int] -> Int sum [] = 0 sum (n:ns) = n + (sum ns) Monday, June 13, 2011 25
  26. 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. 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. 28. (Int) product product :: [Int] -> Int product [] = 1 product (n:ns) = n * product ns Monday, June 13, 2011 28
  29. 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. 30. (Bool) allTrue allTrue :: [Bool] -> Bool allTrue [] = True allTrue (b:bs) = b && allTrue ns Monday, June 13, 2011 30
  31. 31. (Bool) anyTrue anyTrue :: [Bool] -> Bool anyTrue [] = False anyTrue (b:bs) = b || anyTrue ns Monday, June 13, 2011 31
  32. 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. 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. 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. 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. 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. 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. 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. 39. Monday, June 13, 2011 35
  40. 40. Monday, June 13, 2011 36
  41. 41. Monday, June 13, 2011 37
  42. 42. Functions as Building Blocks for constructing programs http://www.flickr.com/photos/stevendepolo/5597111652 Monday, June 13, 2011 38
  43. 43. Functions as Glue for bonding functions http://www.flickr.com/photos/pseudoego/5417919481 Monday, June 13, 2011 39
  44. 44. Monday, June 13, 2011 40
  45. 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. 46. Monday, June 13, 2011 42
  47. 47. Lazy Evaluation Monday, June 13, 2011 43
  48. 48. Monday, June 13, 2011 44
  49. 49. Monday, June 13, 2011 45
  50. 50. http://www.sampou.org/haskell/article/whyfp.html Monday, June 13, 2011 46
  51. 51. http://www.infoq.com/interviews/john-hughes-fp Monday, June 13, 2011 47
  52. 52. http://weblog.raganwald.com/2007/03/why-why-functional-programming-matters.html Monday, June 13, 2011 48
  53. 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. 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. 55. Monday, June 13, 2011 51
  56. 56. Monday, 1 2010 3 June 13, 2011 52
  57. 57. Functional Programming Monday, June 13, 2011 53
  58. 58. A lot of programming languages available for functional programming http://www.flickr.com/photos/32712959@N07/3222623206 Monday, June 13, 2011 54
  59. 59. Monday, June 13, 2011 55
  60. 60. High-order Functions Monday, June 13, 2011 56
  61. 61. Functions as Building Blocks for constructing programs http://www.flickr.com/photos/stevendepolo/5597111652 Monday, June 13, 2011 57
  62. 62. Functions as Glue for bonding functions http://www.flickr.com/photos/pseudoego/5417919481 Monday, June 13, 2011 58
  63. 63. Lazy Evaluation Monday, June 13, 2011 59
  64. 64. Monday, June 13, 2011 60

Editor's Notes

  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • ×