home *** CD-ROM | disk | FTP | other *** search
/ BURKS 2 / BURKS_AUG97.ISO / BURKS / LANGUAGE / ML / GIML / STU77.HTM < prev    next >
Text File  |  1996-12-09  |  2KB  |  50 lines

  1. <b>Comments from David Boyle</b><br>
  2. Response from Andrew<p>
  3.  <b>What's this I hear about ML having all the nasty constructs of
  4.  other languages (like loops, else - if ladders). Is this because
  5.  many problems simply can't be implemented without the use of these
  6.  constructs or is it a facility for "quick dirty code" for programmers
  7.  who are not interested in proving their software?
  8. </b><br>
  9. So far as I know there is a while loop, I've never
  10. used it.
  11. We do not need loops, recursion will always do the job.
  12. <br>
  13. Consider the while loop
  14.  
  15. <pre>while B do S;</pre>
  16.  
  17. Where B is a boolean expression and S is a statement.
  18. We model the action of S by changing some data state
  19. space DS. The program fragment above might be rewritten
  20.  
  21. <pre>while fB(DS) do DS := fS(DS);</pre>
  22.  
  23. where fB and fS are proper functions which take in the
  24. data state DS and return appropriate values. DS might
  25. include all the global and local variables of the program.
  26.  
  27. This program fragment may now be modelled with ML
  28.  
  29. <pre>fun while fB fS DS = if fB DS then (while fB fS (fS DS)) else DS;
  30. </pre>
  31. If then else ladders are there and it's OK to
  32. use them - pattern matching is preferred but it's
  33. not always convenient (I suspect not always possible).
  34. If _ then _ else _ introduces a new complexity
  35. to proofs - but it's not a serious problem.
  36.  
  37. <br>Quick & dirty is possible in ML, but somehow the
  38. quick dirty programs turn out slower and cleaner
  39. than their C equivalents.<p>
  40. <b>
  41.  If the former is true then surely the use of ML will continue to
  42.  be very scarce. If the latter is true then it seems that any language
  43.  (including C) which has these nasty contructs removed (or just
  44.  avoided by the lecturer!) can be proved as easily as ML.
  45. </b><br>
  46. Latter - yes, you could build ML by taking the bad
  47. bits from C and adding a few new good bits. In the
  48. end all languages are more or less the same.
  49.  
  50.