home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / gofer230.zip / Progs / Gofer / Docs / ch00 < prev    next >
Text File  |  1994-06-23  |  8KB  |  199 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.          __________   __________   __________   __________   ________
  8.         /  _______/  /  ____   /  /  _______/  /  _______/  /  ____  \
  9.        /  / _____   /  /   /  /  /  /______   /  /______   /  /___/  /
  10.       /  / /_   /  /  /   /  /  /  _______/  /  _______/  /  __   __/
  11.      /  /___/  /  /  /___/  /  /  /         /  /______   /  /  \  \ 
  12.     /_________/  /_________/  /__/         /_________/  /__/    \__\
  13.  
  14.     Functional programming environment, Version 2.20
  15.  
  16.     Copyright Mark P Jones 1991.
  17.  
  18.  
  19.  
  20.  
  21.  
  22.  
  23.             A N   I N T R O D U C T I O N   T O   G O F E R
  24.  
  25.  
  26.      draft version only --- please report any errors, suggestions for
  27.     improvements, extensions (or deletions!) to jones-mark@cs.yale.edu
  28.  
  29.  
  30.            This version includes a number of small corrections
  31.                    made since the original release.
  32.  
  33.    --------------------------------------------------------------------
  34.    Permission to use, copy, modify, and distribute this software and its
  35.    documentation for any personal or educational use without fee is hereby
  36.    granted, provided that:
  37.     a) This copyright notice is retained in both source code and
  38.        supporting documentation.
  39.     b) Modified versions of this software are redistributed only if
  40.        accompanied by a complete history (date, author, description) of
  41.        modifications made; the intention here is to give appropriate
  42.        credit to those involved, whilst simultaneously ensuring that any
  43.        recipient can determine the origin of the software.
  44.     c) The same conditions are also applied to any software system
  45.        derived either in full or in part from Gofer.
  46.  
  47.    The name "Gofer" is not a trademark, registered  or  otherwise,  and
  48.    you are free to mention this name in published material, public  and
  49.    private correspondence, or other documents  without  restriction  or
  50.    obligation.
  51.  
  52.    Gofer is provided "as is" without express or implied warranty.
  53.    --------------------------------------------------------------------
  54.  
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69. Introduction to Gofer                                                  
  70.  
  71.  
  72.                       T A B L E   O F   C O N T E N T S 
  73.  
  74.  
  75.     1. INTRODUCTION. . . . . . . . . . . . . . . . . . . . . . . . . .  1
  76.  
  77.     2. BACKGROUND AND ACKNOWLEDGEMENTS . . . . . . . . . . . . . . . .  2
  78.  
  79.     3. STARTING GOFER. . . . . . . . . . . . . . . . . . . . . . . . .  4
  80.  
  81.     4. USING GOFER - A BASIC INTRODUCTION. . . . . . . . . . . . . . .  5
  82.  
  83.     5. STANDARD AND USER-DEFINED FUNCTIONS . . . . . . . . . . . . . .  6
  84.  
  85.     6. FUNCTION NAMES - IDENTIFIERS AND OPERATORS. . . . . . . . . . .  8
  86.  
  87.     7. BUILT-IN TYPES. . . . . . . . . . . . . . . . . . . . . . . . . 12
  88.     7.1  Functions . . . . . . . . . . . . . . . . . . . . . . . . . . 12
  89.     7.2  Booleans. . . . . . . . . . . . . . . . . . . . . . . . . . . 13
  90.     7.3  Integers. . . . . . . . . . . . . . . . . . . . . . . . . . . 13
  91.     7.4  Floating point numbers. . . . . . . . . . . . . . . . . . . . 14
  92.     7.5  Characters. . . . . . . . . . . . . . . . . . . . . . . . . . 14
  93.     7.6  Lists . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
  94.     7.7  Strings . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
  95.     7.8  Tuples and the unit type. . . . . . . . . . . . . . . . . . . 18
  96.  
  97.     8. ERRORS. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
  98.     8.1  Errors detected on input. . . . . . . . . . . . . . . . . . . 19
  99.     8.2  Errors during evaluation. . . . . . . . . . . . . . . . . . . 19
  100.  
  101.     9. MORE ABOUT VALUE DECLARATIONS . . . . . . . . . . . . . . . . . 21
  102.     9.1  Simple pattern matching . . . . . . . . . . . . . . . . . . . 21
  103.     9.2  Guarded equations . . . . . . . . . . . . . . . . . . . . . . 23
  104.     9.3  Local definitions . . . . . . . . . . . . . . . . . . . . . . 24
  105.     9.4  Recursion with integers . . . . . . . . . . . . . . . . . . . 24
  106.     9.5  Recursion with lists. . . . . . . . . . . . . . . . . . . . . 26
  107.     9.6  Lazy evaluation . . . . . . . . . . . . . . . . . . . . . . . 27
  108.     9.7  Infinite data structures. . . . . . . . . . . . . . . . . . . 29
  109.     9.8  Polymorphism. . . . . . . . . . . . . . . . . . . . . . . . . 30
  110.     9.9  Higher-order functions. . . . . . . . . . . . . . . . . . . . 31
  111.     9.10 Variable declarations . . . . . . . . . . . . . . . . . . . . 32
  112.     9.11 Pattern bindings and irrefutable patterns . . . . . . . . . . 33
  113.     9.12 Type declarations . . . . . . . . . . . . . . . . . . . . . . 35
  114.  
  115.     10. INCREASING YOUR POWER OF EXPRESSION. . . . . . . . . . . . . . 37
  116.     10.1 Arithmetic sequences. . . . . . . . . . . . . . . . . . . . . 37
  117.     10.2 List comprehensions . . . . . . . . . . . . . . . . . . . . . 38
  118.     10.3 Lambda expressions. . . . . . . . . . . . . . . . . . . . . . 41
  119.     10.4 Case expressions. . . . . . . . . . . . . . . . . . . . . . . 42
  120.     10.5 Operator sections . . . . . . . . . . . . . . . . . . . . . . 43
  121.     10.6 Explicitly typed expressions. . . . . . . . . . . . . . . . . 44
  122.  
  123.     11. USER-DEFINED DATATYPES AND TYPE SYNONYMS . . . . . . . . . . . 46
  124.     11.1 Datatype definitions. . . . . . . . . . . . . . . . . . . . . 46
  125.     11.2 Type synonyms . . . . . . . . . . . . . . . . . . . . . . . . 47
  126.  
  127.  
  128.  
  129.  
  130.  
  131.  
  132.  
  133.  
  134.  
  135. Introduction to Gofer                                                  
  136.  
  137.  
  138.     12. DIALOGUES: INPUT AND OUTPUT. . . . . . . . . . . . . . . . . . 49
  139.     12.1 Basic description . . . . . . . . . . . . . . . . . . . . . . 49
  140.     12.2 Continuation style I/O. . . . . . . . . . . . . . . . . . . . 52
  141.     12.3 Interactive programs. . . . . . . . . . . . . . . . . . . . . 55
  142.  
  143.     13. LAYOUT . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
  144.     13.1 Comments. . . . . . . . . . . . . . . . . . . . . . . . . . . 57
  145.     13.2 The layout rule . . . . . . . . . . . . . . . . . . . . . . . 57
  146.  
  147.     14. OVERLOADING IN GOFER . . . . . . . . . . . . . . . . . . . . . 61
  148.     14.1 Type classes and predicates . . . . . . . . . . . . . . . . . 61
  149.     14.2 The type class Eq . . . . . . . . . . . . . . . . . . . . . . 62
  150.     14.2.1 Implicit overloading. . . . . . . . . . . . . . . . . . . . 62
  151.     14.2.2 Instances of class Eq . . . . . . . . . . . . . . . . . . . 63
  152.     14.2.3 Testing equality of represented values. . . . . . . . . . . 65
  153.     14.2.4 Instance declarations without members . . . . . . . . . . . 66
  154.     14.2.5 Equality on function types. . . . . . . . . . . . . . . . . 66
  155.     14.2.6 Non-overlapping instances . . . . . . . . . . . . . . . . . 67
  156.     14.3 Dictionaries. . . . . . . . . . . . . . . . . . . . . . . . . 68
  157.     14.3.1 Superclasses. . . . . . . . . . . . . . . . . . . . . . . . 71
  158.     14.3.2 Combining classes . . . . . . . . . . . . . . . . . . . . . 73
  159.     14.3.3 Simplified contexts . . . . . . . . . . . . . . . . . . . . 74
  160.     14.4 Other issues. . . . . . . . . . . . . . . . . . . . . . . . . 76
  161.     14.4.1 Unresolved overloading. . . . . . . . . . . . . . . . . . . 76
  162.     14.4.2 `Recursive' dictionaries. . . . . . . . . . . . . . . . . . 79
  163.     14.4.3 Classes with multiple parameters. . . . . . . . . . . . . . 81
  164.     14.4.4 Overloading and numeric values. . . . . . . . . . . . . . . 83
  165.     14.4.5 Constants in dictionaries . . . . . . . . . . . . . . . . . 86
  166.     14.4.6 The monomorphism restriction. . . . . . . . . . . . . . . . 88
  167.  
  168.     APPENDIX A: SUMMARY OF GRAMMAR . . . . . . . . . . . . . . . . . . 93
  169.  
  170.     APPENDIX B: CONTENTS OF STANDARD PRELUDE . . . . . . . . . . . . . 97
  171.  
  172.     APPENDIX C: RELATIONSHIP WITH HASKELL 1.1. . . . . . . . . . . . .113
  173.  
  174.     APPENDIX D: USING GOFER WITH BIRD+WADLER . . . . . . . . . . . . .117
  175.  
  176.     APPENDIX E: PRIMITIVES . . . . . . . . . . . . . . . . . . . . . .119
  177.  
  178.     APPENDIX F: INTERPRETER COMMAND SUMMARY. . . . . . . . . . . . . .121
  179.  
  180.     APPENDIX G: BIBLIOGRAPHY . . . . . . . . . . . . . . . . . . . . .123
  181.  
  182.  
  183.  
  184.  
  185.  
  186.  
  187.  
  188.  
  189.  
  190.  
  191.  
  192.  
  193.  
  194.  
  195.  
  196.  
  197.  
  198.  
  199.