home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / lang / forth / 3974 < prev    next >
Encoding:
Internet Message Format  |  1993-01-24  |  2.9 KB

  1. Path: sparky!uunet!psinntp!alliant!merk!harvee.billerica.ma.us!esj
  2. From: esj@harvee.billerica.ma.us (Eric S Johansson)
  3. Newsgroups: comp.lang.forth
  4. Message-ID: <H.eg.583NHBN2SYI@harvee.billerica.ma.us>
  5. Organization: gators 'r us
  6. Subject: types (forth and other)
  7. Reply-To: esj@harvee.billerica.ma.us
  8. X-Software: HERMES GUS 1.10 Rev. Dec 23 1992
  9. Date: Sat, 23 Jan 1993 09:32:32 -0400
  10. MIME-Version: 1.0
  11. Content-Type: text/plain; charset=US-ASCII
  12. Content-Transfer-Encoding: 7bit
  13. Lines: 59
  14.  
  15. there have been a series of good articles on forth, types and how
  16. they relate.  But, as usual, it got bogged down in a debates over a
  17. faulty implementation of a type system.  So in the spirit of throwing
  18. a little more fuel on the fire, here are another few concepts and ideas
  19. for folks to chew on.
  20.  
  21. "type" describes properties and some think of type as specifying
  22. the operations one can perform on a type.  I tend to think of
  23. operations specifying type instead of the converse, but for now, the point 
  24. is not terrible important.
  25.  
  26. pre and post conditions are associated with implementation of a type. 
  27.  
  28. For an example: an integer is a type.
  29.         x is of type integer.
  30.         limiting x to a range of [3..8] is a postcondition of x
  31.  
  32. frequently types and postconditions are merged in the implementations
  33. of type systems.
  34.  
  35. checking postcondition, and the related preconditions, at compile time
  36. are more difficult than checking type but it can be done if the
  37. compiler has knowledge of types, preconditions and postconditions for
  38. all operations.         
  39.  
  40. lets play with an example.  the definition below is of type int
  41. yielding int.  the definition takes an int with precondition of being 
  42. in the range of 3 to 8 inclusive.  the definition yields an int with a
  43. post condition of being in the range of 3 to 8 inclusive.
  44.  
  45. : pl1 ( int [3..8] --- int [3..8] )
  46.     1 +
  47. ;
  48.  
  49. A type+pre/postcondition aware compiler (from now on called a tpp
  50. compiler) would flag the above as violating the postcondition.  it could
  51. do this only because it knows the type and properties of +.  if a
  52. tpp compiler did not know the properties of +, it would have to insert
  53. a runtime check to enforce the post condition.
  54.  
  55. Now, things get messy if we look at +.  it is real easy to specify
  56. its type.  + is of type int by int yielding int.  however adding
  57. the information needed by a tpp compiler to verify postconditions
  58. of anything using + is a bit sticky but can be done.
  59.  
  60. I suggest that anyone interested in working with these concepts look
  61. into formal methods in general and the work done by the Z folks
  62. specificly.  there are some more applical areas of formal methods but the
  63. Z stuff is more accessible and should work well in the forth domain.
  64.  
  65. overall, I think designing an extensible type system and building a
  66. tpp compiler base on that type system would be very interesting and
  67. *very* useful. 
  68.  
  69. --- eric
  70. -- 
  71. HOME: esj@harvee.billerica.ma.us  HAM  ka1eec
  72. WORK: 617.630.4687 (w)   esj@ruby.polaroid.com
  73. source of the public's fear of the unknown since 1956
  74.