home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!mcsun!sun4nl!tuegate.tue.nl!svin02!wsinfo03!erik
- From: erik@wsinfo03.win.tue.nl (Erik Poll)
- Newsgroups: comp.lang.functional
- Subject: Re: ** LAZY LANGUAGES FASTER?? **
- Message-ID: <3737@svin02.info.win.tue.nl>
- Date: 27 Jul 92 10:25:55 GMT
- References: <1992Jul24.134857.23289@gdstech.grumman.com>
- Sender: news@svin02.info.win.tue.nl
- Reply-To: erik@win.tue.nl
- Lines: 45
-
- david@gdstech.grumman.com (David Nettles) writes:
-
- >My intuition says that a lazy language would be a lot faster than an
- >eager language simply because the eager language evaluates all of its
- >arguements regardless of whether they are all needed by the function.
-
- >The lazy language, by evaluating only what is necessary, appears to
- >save time.
-
- Lazy evaluation does indeed save time by not evaluating arguments
- that are not needed. However, eager evaluation saves times by never
- evaluating the same argument twice.
-
- In eager languages, all arguments are evaluated ONCE, regardless of
- whether they are actually needed.
-
- In lazy languages, an argument is evaluated once for every time that it
- is used. If the argument is used N times, it will be evaluated N times.
- So if the argument is not used, it will not be evaluated,
- if the argument is used once, it will be evaluated once,
- if the argument is used twice, it will be evaluated *TWICE*, etc.
-
- For example, consider the function (\x.\y.xx) (where \ is lambda),
- applied to arguments A and B which evaluate to a and b, resp.
-
- (i) lazy evaluation
- (\x.\y.xx)AB reduces to AA, which reduces to aa
-
- (ii) eager evaluation
- (\x.\y.xx)AB reduces to (\x.\y.xx)ab, which reduces to aa
-
- (i) saves time by not evaluating B. On the other hand, (ii) saves time
- by evaluating A only once, whereas in (i) A has to be evaluated twice.
- Which of the two is faster depends on the cost of evaluating A and B.
-
-
- Erik
-
- >****************************************************************************
- > David E. Nettles
- > Grumman Data Systems Internet: avid@gdstech.grumman.com
- > 1000 Woodbury Road Phone: (516) 682-8464
- > Woodbury, NY 11797 FAX: (516) 682-8022
- > MS D12/237
- >****************************************************************************
-