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

  1. Path: sparky!uunet!mcsun!uknet!mucs!m1!bevan
  2. From: bevan@cs.man.ac.uk (Stephen J Bevan)
  3. Newsgroups: comp.lang.functional
  4. Subject: Re: programs that are too lazy
  5. Message-ID: <BEVAN.92Jul27112246@panda.cs.man.ac.uk>
  6. Date: 27 Jul 92 10:22:46 GMT
  7. References: <BEVAN.92Jul26184420@panda.cs.man.ac.uk>
  8.     <SEWARDJ.92Jul26232657@r6.cs.man.ac.uk>
  9. Sender: news@cs.man.ac.uk
  10. Organization: Department of Computer Science, University of Manchester
  11. Lines: 62
  12. In-reply-to: sewardj@cs.man.ac.uk's message of 26 Jul 92 22:26:57 GMT
  13.  
  14. In article <SEWARDJ.92Jul26232657@r6.cs.man.ac.uk> sewardj@cs.man.ac.uk (Julian Seward (DRL PhD)) writes:
  15.    | 1. The extra amount of work that has to be done in "forcing" the store.
  16.    |    This bumps up the runtime.
  17.  
  18.    Hmm ... but not by much.
  19.  
  20. How can we know this?  All I committed myself to was that the runtime
  21. increased.  I can't say by how much, as without forcing the store it
  22. is either slower or doesn't fit in the available heap.  However,
  23. intiution tells me that doing repeated full equality tests on 7 AVL
  24. trees containing 10,000+ elements each cannot be a cheap operation :-)
  25.  
  26.  
  27.    | 2. A simple, one-liner using higher order functions has turned into a
  28.    |    10 line tail recursive loop.  Now being a Schemer at heart, I have
  29.    |    no particular problem with this, but it does seem to go against the
  30.    |    whole idea of "higher order functions are good" which most fp books
  31.    |    espouse.
  32.  
  33.    I have a couple of comments on this.  Firstly, the problem
  34.    is you are getting 000's of thunks.  The problem is *not*
  35.    the use of a higher-order function.
  36.  
  37. Ah, but I never said it was.  All I pointed out was that a solution to
  38. the problem involved removing the HOF and replacing with an explicit
  39. loop.  If I hadn't have been a HOF in the first place, the solution
  40. whouldn't have seemed such a drastic change.
  41.  
  42.  
  43.    Even if you unfolded the definition of "foldl" at the
  44.    parameterisation shown, the program would behave the same.
  45.  
  46. Actually it runs out of heap quicker than the foldl version.  I guess
  47. foldl isn't being optimised by the compiler.
  48.  
  49.  
  50.    ..., I believe the Haskell committee should
  51.    consider the provision of two built-in functions:
  52.  
  53.       hyperstrict, whnf :: Eq a => a -> b -> b
  54.  
  55.    both of which evaluate their first argument (fully or to whnf)
  56.    and return the second.  We can simulate this at the moment using
  57.    Haskell 1.2, but it might be more efficient if compilers could
  58.    regard these as primitive.
  59.  
  60. Doesn't this move us back into the realms of separate annotations.  I
  61. thought many people don't like as there is too much opportunity for
  62. the user to make a mistake i.e. "hyperstricting" everthing in sight in
  63. the hope of efficiency.  Alternately couldn't you argue that as most
  64. of the time you want strict evaluation, you'd be better off with a
  65. language were that was the default and annotating it with "lazy" at
  66. appropriate points? For example, I have a much better feel for where I'd
  67. want a strict version to be lazy than I do about where I'd want a lazy
  68. version to be strict.  Is this the mark of a novice lazy programmer?
  69.  
  70. That notwithstanding, if the above proposal means I can remove the
  71. loop and replace it with one hyperstrict/whnf call in the
  72. read_ASCII_Store definition, then I'm all for it (but then what do I
  73. know :-)
  74.  
  75. bevan
  76.