using less stack

Graham Hutton gmh@Cs.Nott.AC.UK
Thu, 21 Mar 2002 11:57:20 +0000


> In the case of foldr the end of the list has to be
> reached before anything can be evaluated. 

This is perhaps a good time to point out the common missconception that
foldr can only be used to define functions that process the elements of
lists in right-to-left order.  For a discussion of this point, see section
5 of my JFP tutorial paper on foldr, which (amonst other things) shows
how to sum a list of numbers in left-to-right order using foldr:

   http://www.cs.nott.ac.uk/~gmh/fold.pdf

Graham

+----------------------------------------------------------------------------+
| Dr Graham Hutton                     Email : gmh@cs.nott.ac.uk             |
| Foundations of Programming Group     Web   : http://www.cs.nott.ac.uk/~gmh | 
| School of Computer Science and IT                                          |
| University of Nottingham                                                   |
| Jubilee Campus, Wollaton Road                                              |
| Nottingham NG8 1BB                   Phone : +44 (0)115 951 4220           |
| United Kingdom                       Fax   : +44 (0)115 951 4254           |
+----------------------------------------------------------------------------+