Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Kof2008 Itll

1,550 views

Published on

“Introduction to Lazy lists”
How to use and construct lazy lists on Programming Langage Ruby.

Published in: Technology
  • Be the first to comment

Kof2008 Itll

  1. 1. Introduction to Lazy Lists 2008 UJIHISA, Tatsuhiro
  2. 2. UJIHISA Tatsuhiro • Osaka University • Ruby, Vim, Haskell and Math • http://ujihisa.nowa.jp • http://twitter.com/ujm • To the US!
  3. 3. Targets • • Array, Enumerable, IO (File) Haskell
  4. 4. Lazy lists
  5. 5. • Ruby Haskell (Lazy list) Live coding Vim
  6. 6. Lazy Lists • Lazy lists (or streams) • List (= Array in Ruby) • Only needed parts are calculated. • Haskell supports lazy lists by default. • Ruby can support it.
  7. 7. List (=Array) in Ruby • Array class • [0, 1, 2, 3], Array.new(4) {|i| i } • a #=> [0, 1, 2, 3] a.map {|i| i * 2 } #=> [0, 2, 4, 6]
  8. 8. List • Data structure • Insert, Delete, Access sequentially
  9. 9. c.f. Array • Data structure • Insert, Delete, Access randomly, Size
  10. 10. (List again) • Data structure • Insert, Delete, Access sequentially
  11. 11. Lazy List • Data structure • Insert, Delete, Access sequentially
  12. 12. Types of lazy lists • Boundless length lists ( ) • Undefined length lists ( ) • Defined length lists ( )
  13. 13. How to construct lazy lists?
  14. 14. Notations • array = 1000+ length array heavy = lambda { heavy procedure } • array.take(2).map(&heavy) • array.map(&heavy).take(2)
  15. 15. Common case • truncation (break) • filtering (if, unless; select, reject) • mapping (=, map) • processing (???, each) folding (<<, inject)

×