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

  1. Path: sparky!uunet!mcsun!uknet!mucs!m1!sewardj
  2. From: sewardj@cs.man.ac.uk (Julian Seward (DRL PhD))
  3. Newsgroups: comp.lang.functional
  4. Subject: Re: programs that are too lazy
  5. Message-ID: <SEWARDJ.92Jul26232657@r6.cs.man.ac.uk>
  6. Date: 26 Jul 92 22:26:57 GMT
  7. References: <BEVAN.92Jul26184420@panda.cs.man.ac.uk>
  8. Sender: news@cs.man.ac.uk
  9. Organization: Department of Computer Science, University of Manchester
  10. Lines: 45
  11. In-reply-to: bevan@cs.man.ac.uk's message of 26 Jul 92 17:44:20 GMT
  12.  
  13.  
  14. Steven J Bevan writes:
  15.  
  16. | This works well, and keeps the usage down to under 2Mb for the input
  17. | that previously ran out of heap.  However, there are a couple of
  18. | things that bother me about this :-
  19. | 1. The extra amount of work that has to be done in "forcing" the store.
  20. |    This bumps up the runtime.
  21.  
  22. Hmm ... but not by much.
  23.  
  24. | 2. A simple, one-liner using higher order functions has turned into a
  25. |    10 line tail recursive loop.  Now being a Schemer at heart, I have
  26. |    no particular problem with this, but it does seem to go against the
  27. |    whole idea of "higher order functions are good" which most fp books
  28. |    espouse.
  29.  
  30. I have a couple of comments on this.  Firstly, the problem
  31. is you are getting 000's of thunks.  The problem is *not*
  32. the use of a higher-order function.  Even if you unfolded the
  33. definition of "foldl" at the parameterisation shown, the program would
  34. behave the same.
  35.  
  36. Secondly, a few minutes of investigation and a few changed lines
  37. made a massive difference to the usability of the program. 
  38. In my book this is a very small price to pay for the
  39. convenience of a language as expressive as Haskell.  I believe
  40. a few (say five at most) strategically placed hyperstrictnesses (so to speak)
  41. can make a big difference to the space behaviour of programs 
  42. tens of thousands of lines long.  Using a heap-profiling
  43. compiler, it is easy to spot the functions filling the heap up
  44. with thunks.
  45.  
  46. For this reason, I believe the Haskell committee should
  47. consider the provision of two built-in functions:
  48.  
  49.    hyperstrict, whnf :: Eq a => a -> b -> b
  50.  
  51. both of which evaluate their first argument (fully or to whnf)
  52. and return the second.  We can simulate this at the moment using
  53. Haskell 1.2, but it might be more efficient if compilers could
  54. regard these as primitive.
  55.  
  56. Jules
  57.