home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / lang / function / 959 < prev    next >
Encoding:
Internet Message Format  |  1992-07-27  |  2.2 KB

  1. Path: sparky!uunet!mcsun!sun4nl!tuegate.tue.nl!svin02!wsinfo03!erik
  2. From: erik@wsinfo03.win.tue.nl (Erik Poll)
  3. Newsgroups: comp.lang.functional
  4. Subject: Re: ** LAZY LANGUAGES FASTER?? **
  5. Message-ID: <3737@svin02.info.win.tue.nl>
  6. Date: 27 Jul 92 10:25:55 GMT
  7. References: <1992Jul24.134857.23289@gdstech.grumman.com>
  8. Sender: news@svin02.info.win.tue.nl
  9. Reply-To: erik@win.tue.nl
  10. Lines: 45
  11.  
  12. david@gdstech.grumman.com (David Nettles) writes:
  13.  
  14. >My intuition says that a lazy language would be a lot faster than an
  15. >eager language simply because the eager language evaluates all of its
  16. >arguements regardless of whether they are all needed by the function.
  17.  
  18. >The lazy language, by evaluating only what is necessary, appears to
  19. >save time.
  20.  
  21. Lazy evaluation does indeed save time by not evaluating arguments
  22. that are not needed. However, eager evaluation saves times by never
  23. evaluating the same argument twice.
  24.  
  25. In eager languages, all arguments are evaluated ONCE, regardless of
  26. whether they are actually needed.
  27.  
  28. In lazy languages, an argument is evaluated once for every time that it 
  29. is used. If the argument is used N times, it will be evaluated N times. 
  30. So if the argument is not used, it will not be evaluated,
  31.    if the argument is used once, it will be evaluated once,
  32.    if the argument is used twice, it will be evaluated *TWICE*, etc.
  33.  
  34. For example, consider the function (\x.\y.xx) (where \ is lambda),
  35. applied to arguments A and B which evaluate to a and b, resp.
  36.  
  37. (i)  lazy evaluation
  38.      (\x.\y.xx)AB reduces to AA, which reduces to aa
  39.  
  40. (ii) eager evaluation
  41.      (\x.\y.xx)AB reduces to (\x.\y.xx)ab, which reduces to aa
  42.  
  43. (i) saves time by not evaluating B. On the other hand, (ii) saves time 
  44. by evaluating A only once, whereas in (i) A has to be evaluated twice.
  45. Which of the two is faster depends on the cost of evaluating A and B.
  46.  
  47.  
  48. Erik
  49.  
  50. >****************************************************************************
  51. >   David E. Nettles
  52. >   Grumman Data Systems             Internet: avid@gdstech.grumman.com
  53. >   1000 Woodbury Road                  Phone: (516) 682-8464
  54. >   Woodbury, NY 11797                    FAX: (516) 682-8022
  55. >   MS D12/237
  56. >****************************************************************************
  57.