Tomohiko Himura
November 02, 2014
6.8k

# 内包表記(仮)

## Tomohiko Himura

November 02, 2014

## Transcript

8. ### Python [(x,y) for x in range(1,10) for y in range(1,10)

if x * y == 24 ] [(3, 8), (4, 6), (6, 4), (8, 3)]

12. ### ۩ମྫ 10ະຬͷਖ਼ͷح਺ ֎Ԇ { 1, 3, 5, 7, 9} ಺แ

{ x | x ͸ 10ະຬͷਖ਼ͷح਺ } { x | x ∈ ℕ, x < 10, x % 2 = 1 }

2 == 1 ]
17. ### ࣅͯΔʁ ू߹ { x | x ∈ ℕ, x <

10, x % 2 = 1 } Haskell [ x | x <- [1..9], x `mod` 2 == 1 ]
18. ### ࣅͯΔʁ ू߹ { x | x ∈ ℕ, x <

10, x % 2 = 1 } Haskell [ x | x <- [1..9], x `mod` 2 == 1 ]
19. ### ࣅͯΔʁ ू߹ { x | x ∈ ℕ, x <

10, x % 2 = 1 } Haskell [ x | x <- [1..9], x `mod` 2 == 1 ]
20. ### ࣅͯΔʁ ू߹ { x | x ∈ ℕ, x <

10, x % 2 = 1 } Haskell [ x | x <- [1..9], x `mod` 2 == 1 ]
21. ### ࣅͯΔʁ ू߹ { x | x ∈ ℕ, x <

10, x % 2 = 1 } Haskell [ x | x <- [1..9], x `mod` 2 == 1 ]

25. ### Haskell [(x,y) | x <- [1..9], y <- [1..9], x

* y == 24] [(3, 8), (4, 6), (6, 4), (8, 3)]
26. ### Haskell [(x,y) | x <- [1..9], y <- [1..9], x

* y == 24] [(3, 8), (4, 6), (6, 4), (8, 3)] ݸͷϦετ
27. ### Haskell [(x,y) | x <- [1..9], y <- [1..9], x

* y == 24] [(3, 8), (4, 6), (6, 4), (8, 3)] ݸͷϦετ ݸͷϦετ
28. ### Haskell [(x,y) | x <- [1..9], y <- [1..9], x

* y == 24] [(3, 8), (4, 6), (6, 4), (8, 3)] ݸͷϦετ ݸͷϦετ ௚ੵ
29. ### ௚ੵ 81ݸͷϦετ [(x,y) | x <- [1..9], y <- [1..9]]

[(1,1),(1,2),(1,3),(1,4),(1,5),(1,6),(1,7),(1,8),(1,9), (2,1),(2,2),(2,3),(2,4),(2,5),(2,6),(2,7),(2,8),(2,9), (3,1),(3,2),(3,3),(3,4),(3,5),(3,6),(3,7),(3,8),(3,9), (4,1),(4,2),(4,3),(4,4),(4,5),(4,6),(4,7),(4,8),(4,9), (5,1),(5,2),(5,3),(5,4),(5,5),(5,6),(5,7),(5,8),(5,9), (6,1),(6,2),(6,3),(6,4),(6,5),(6,6),(6,7),(6,8),(6,9), (7,1),(7,2),(7,3),(7,4),(7,5),(7,6),(7,7),(7,8),(7,9), (8,1),(8,2),(8,3),(8,4),(8,5),(8,6),(8,7),(8,8),(8,9), (9,1),(9,2),(9,3),(9,4),(9,5),(9,6),(9,7),(9,8),(9,9)]
30. ### Haskell [(x,y) | x <- [1..9], y <- [1..9], x

* y == 24] [(3, 8), (4, 6), (6, 4), (8, 3)] ݸͷϦετ ݸͷϦετ ௚ੵ ʹͳΔ΋ͷ͚ͩʹ͢Δ
31. ### Python [(x,y) for x in range(1,10) for y in range(1,10)

if x * y == 24 ] [(3, 8), (4, 6), (6, 4), (8, 3)] ݸͷϦετ ݸͷϦετ ௚ੵ ʹͳΔ΋ͷ͚ͩʹ͢Δ

33. ### –Python νϡʔτϦΞϧ “Ϧετͷ಺แදه (list comprehension) ͸ɺ map() ΍ ﬁlter() ΍

lambda Λ࢖ΘͣʹϦετ Λੜ੒͢ΔͨΊͷ؆ܿͳํ๏Λఏڙ͍ͯ͠· ͢ɻ಺แදهʹΑΔϦετͷఆٛ͸ɺ͍ͨͯ ͍ map(), ﬁlter(), lambda Λ࢖ͬͯϦετΛੜ ੒͢ΔίʔυΑΓ΋໌շʹͳΓ·͢ɻ”
34. ### Ruby [*1..9].map do |x| [*1..9].map do |y| [x,y] end end.flatten(1).select

do |x,y| x * y == 24 end

37. ### Haskell [(x,y,z) | x <- [1..9], y <- [1..9], z

<- [1..9], x * y * z == 24]
38. ### Ruby [*1..9].map do |x| [*1..9].map do |y| [*1..9].map do |z|

[x,y,z] end end end.ﬂatten(2).select do |x,y,z| x * y * z == 24 end

z == 24 end

48. ### in PosgreSQL SELECT x,y FROM generate_series(1,9) AS X, generate_series(1,9) AS

Y WHERE x * y = 24;

* y == 24]
50. ### Haskell [(x,y) | x <- [1..9], y <- [1..9], x

* y == 24] TFMFDU
51. ### Haskell [(x,y) | x <- [1..9], y <- [1..9], x

* y == 24] TFMFDU GSPN
52. ### Haskell [(x,y) | x <- [1..9], y <- [1..9], x

* y == 24] TFMFDU GSPN XIFSF

57. ### LIMIT :set -XTransformListComp [ (x,y) | x <- [1..9], y

<- [1..9], x * y == 24, then take 2] [(3, 8), (4, 6)]
58. ### ORDER :set -XTransformListComp :m GHC.Exts [ (x,y) | x <-

[1..9], y <- [1..9], x * y == 24, then sortWith by y] [(8, 3) (6, 4), (4, 6), (3, 8)]

61. ### ϞφυͰ΋Ͱ͖ΔΑ do x <- [1..9] y <- [1..9] guard (x

* y == 24) return (x,y) [(3, 8), (4, 6), (6, 4), (8, 3)]
62. ### ϞφυͰ΋Ͱ͖ΔΑ do x <- [1..9] y <- [1..9] guard (x

* y == 24) return (x,y) TFMFDU [(3, 8), (4, 6), (6, 4), (8, 3)]
63. ### ϞφυͰ΋Ͱ͖ΔΑ do x <- [1..9] y <- [1..9] guard (x

* y == 24) return (x,y) GSPN TFMFDU [(3, 8), (4, 6), (6, 4), (8, 3)]
64. ### ϞφυͰ΋Ͱ͖ΔΑ do x <- [1..9] y <- [1..9] guard (x

* y == 24) return (x,y) XIFSF GSPN TFMFDU [(3, 8), (4, 6), (6, 4), (8, 3)]

67. ### Maybe do x <- Just 3 y <- Just 8

guard (x * y == 24) return (x,y) Just (3,8)
68. ### Maybe do x <- Just 3 y <- Just 8

guard (x * y == 25) return (x,y) Nothing

70. ### Maybeͷ಺แදه :set -XMonadComprehensions [ (x,y) | x <- Just 3,

y <- Just 8, x * y == 24]