home *** CD-ROM | disk | FTP | other *** search
/ ftp.uni-stuttgart.de/pub/systems/acorn/ / Acorn.tar / Acorn / acornet / dev / gofer.spk / docsrc / doc221 < prev    next >
Text File  |  1994-06-06  |  42KB  |  1,094 lines

  1. .co This is the source form of the release notes for Gofer 2.21
  2. .co
  3. .co Mark P Jones November 1991
  4. .co-------------------------------------------------------------------|
  5. .>release.221
  6. -----------------------------------------------------------------------
  7.        __________   __________   __________   __________   ________
  8.       /  _______/  /  ____   /  /  _______/  /  _______/  /  ____  \
  9.      /  / _____   /  /   /  /  /  /______   /  /______   /  /___/  /
  10.     /  / /_   /  /  /   /  /  /  _______/  /  _______/  /  __   __/
  11.    /  /___/  /  /  /___/  /  /  /         /  /______   /  /  \  \ 
  12.   /_________/  /_________/  /__/         /_________/  /__/    \__\
  13.  
  14.   Functional programming environment, Version 2.21
  15.  
  16.   Copyright Mark P Jones 1991.
  17.  
  18.  
  19.   Release notes
  20.  
  21. -----------------------------------------------------------------------
  22.  
  23. This document is intended as a supplement to the user manual ``An
  24. introduction to Gofer'' supplied with the previous public release of
  25. Gofer, version 2.20.1.  It provides brief descriptions of the changes
  26. and new features incorporated in version 2.21.  With the exception of
  27. bug fixes, which will be distributed as soon as they become available,
  28. there are no plans to release a further update of Gofer for some time
  29. (at least six months).
  30.  
  31. If you would like to be informed when bug-fixes or further versions
  32. become available, please send email to me at mpj@prg.ox.ac.uk or
  33. jones-mark@cs.yale.edu (if you have not already done so) and I will
  34. add your name to the mailing list.
  35.  
  36. Please contact me if you have any questions about the Gofer system, or
  37. if you need some advice or help to complete a port of Gofer to a new
  38. platform.
  39.  
  40. In addition to PC and Sun workstations, I have now had reports that
  41. Gofer has been successfully compiled and used on a number of other
  42. machines including Apollo, DecStation, Mips, MicroVax and Acorn ARM
  43. machines, with little or no changes to the original source.
  44.  
  45.  
  46. ACKNOWLEDGMENTS
  47.  
  48. Many of the features described in this document were motivated by
  49. comments and suggestions from users of the previously released version
  50. of Gofer.  My thanks in particular to Julian Seward, but also to Brent
  51. Benson, Stuart Clayman, Andy Gill, Peter Hancock, Ian Holyer, Hiroyuki
  52. Matsuda, Aiden McCaughey, Tobias Nipkow, Will Partain, Ian Poole,
  53. Bernard Sufrin and Phil Wadler.
  54. .pa
  55. .ti Release Notes
  56. .co-------------------------------------------------------------------|
  57. .ST 1. MINOR ENHANCEMENTS
  58.  
  59. A number of small enhancements have been made to make the source code
  60. for Gofer a little more flexible.  In particular, this includes:
  61.  
  62.   o  Gofer can now be compiled using the Gnu C compiler gcc, for those
  63.      who prefer this to the standard cc compiler provided on their
  64.      machine.
  65.  
  66.   o  Default table sizes for the Unix version have been expanded which
  67.      makes it possible to support larger programs in Gofer (a program
  68.      of over 5000 lines has already been tested with this release).
  69.  
  70.   o  The Makefile has been made less SunOS specific and should be
  71.      usable on a wider range of machines without modification.
  72.  
  73. .pa
  74. .co-------------------------------------------------------------------|
  75. .ST 2. USER INTERFACE EXTENSIONS
  76.  
  77. The user interface of the previous release has been extended to support
  78. a range of new features, intended to make the Gofer environment more
  79. convenient for program development.  Further details are given in the
  80. following sections.
  81.  
  82. .ST 2.1 Command line options
  83. ------------------------
  84. Although the previous version of Gofer accepted some command line
  85. options, these were not documented.  Those who discovered the
  86. Gofer command line options in the previous release by reading the
  87. source code should note that a different syntax is now used which is
  88. not compatible with the older system.
  89.  
  90. Options may be set when loading Gofer (on the UNIX/DOS command line)
  91. or within the interpreter itself using the :set command.  Using this
  92. command on its own with no arguments prints a menu of all of the
  93. available options and displays the current settings:
  94.  
  95.     ? :set
  96.     Groups of options begin with +/- to turn options on/off resp.
  97.  
  98.     TOGGLES:
  99.     s    Print no. reductions/cells after eval
  100.     t    Print type after evaluation
  101.     d    Show dictionary values in output exprs
  102.     f    Terminate evaluation on first error
  103.     g    Print no. cells recovered after gc
  104.     c    Test conformality for pattern bindings
  105.     l    Treat input files as literate scripts
  106.     e    Warn about errors in literate scripts
  107.     i    Apply fromInteger to integer literals
  108.     o    Optimise use of (&&) and (||)
  109.     u    Catch ambiguously typed top-level vars
  110.     a    Use any evidence, not nec. best
  111.     E    Fail silently if evidence not found
  112.  
  113.     OTHER OPTIONS: (leading + or - makes no difference)
  114.     hnum Set heap size (cannot be changed within Gofer)
  115.     pstr Set prompt string to str
  116.     xnum Set maximum depth for evidence search
  117.  
  118.     Current settings: +sdcoaE -tfgleiu -h100000 -p? -x8
  119.     ?
  120.  
  121. Most options are toggles meaning that they can either be switched on
  122. (by preceding the option with a `+' character) or off (by using a `-'
  123. character).  Several options may be grouped together so that:
  124.  
  125.   :set +std -le     is equivalent to       :set +s +t +d -l -e
  126.  
  127. In order to distinguish command line options from filenames, a leading
  128. `+' or `-' must also be used with the `h', `p' and `x' options, although
  129. the choice in each case is not significant.
  130.  
  131. Options may also be used in :a and :l commands, and within project files
  132. (see section 2.2), although it should be noted that they will be acted
  133. upon as soon as they are encountered and will not be reapplied when
  134. reloading files.
  135.  
  136. Most of the options listed above are described in more detail in the
  137. following sections.
  138.  
  139.  
  140. .ST 2.1.1  Set Gofer prompt
  141. -----------------------
  142. The standard Gofer prompt "? " may be changed using a command line
  143. option of the form -pstr where for any string str.  The new prompt is
  144. formed from the given string, followed by a single space:
  145.  
  146.     ? :set -pGofer>
  147.     Gofer> :set -p?
  148.     ?
  149.  
  150. .ST 2.1.2  Print statistics
  151. -----------------------
  152. In normal operation, Gofer displays the number of reductions and cells
  153. used by a particular calculation when the result has been evaluated or
  154. if the calculation is interrupted:
  155.  
  156.     ? map (\x -> x*x) [1..10]
  157.     [1, 4, 9, 16, 25, 36, 49, 64, 81, 100]
  158.     (112 reductions, 204 cells)
  159.     ? [1..]
  160.     [1, 2, 3, 4, ^C{Interrupted!}
  161.  
  162.     (18 reductions, 54 cells)
  163.     ?
  164.  
  165. Printing of these statistics can be suppressed using the -s option
  166. (and subsequently restored using +s):
  167.  
  168.     ? :set -s
  169.     ? map (\x -> x*x) [1..10]
  170.     [1, 4, 9, 16, 25, 36, 49, 64, 81, 100]
  171.     ? [1..]
  172.     [1, 2, 3, 4, ^C{Interrupted!}
  173.  
  174.     ? :set +s
  175.     ? 2 + 4
  176.     6
  177.     (2 reductions, 6 cells)
  178.     ?
  179.  
  180.  
  181. .ST 2.1.3  Print type
  182. -----------------
  183. Before evaluating an expression entered into the interpreter, the Gofer
  184. type checker is used to determine the type of the resulting value.
  185. This is used to detect errors in the original input expression, avoid
  186. the use of runtime type checks and determine how the value should be
  187. output.  The actual type of the term is not usually displayed unless a
  188. type error is detected.  This behaviour can be changed using the +t
  189. option which displays the type of each value as soon as evaluation is
  190. complete.
  191.  
  192.     ? :set +t
  193.     ? map (\x -> x*x) [1..10]
  194.     [1, 4, 9, 16, 25, 36, 49, 64, 81, 100] :: [Int]
  195.     (108 reductions, 204 cells)
  196.  
  197.     ? map concat
  198.     map concat :: [[[a]]] -> [[a]]
  199.     (2 reductions, 17 cells)
  200.  
  201.     ? fix where fix f = f (fix f)
  202.     v112 :: (a -> a) -> a
  203.     (1 reduction, 7 cells)
  204.     ?
  205.  
  206. Note that values of type String and Dialogue (or equivalent forms) are
  207. displayed in a different manner to other values, and no type information
  208. is printed after such values to avoid any possibility of confusion:
  209.  
  210.     ? map                              -- the map function
  211.     map :: (a -> b) -> [a] -> [b]
  212.     (1 reduction, 6 cells)
  213.  
  214.     ? "map"                            -- a string expression
  215.     map
  216.     (0 reductions, 4 cells)
  217.  
  218.     ? print "map"                      -- a dialogue
  219.     "map"
  220.     (18 reductions, 44 cells)
  221.     ?
  222.  
  223.  
  224. .ST 2.1.4  Show dictionaries
  225. ------------------------
  226. The implementation of overloading in Gofer uses a translation of each
  227. expression entered into the interpreter to a new expression involving
  228. dictionary variables and constants.  These additional parameters are
  229. usually included in expressions displayed by the interpreter and are
  230. often useful for understanding and resolving overloading problems:
  231.  
  232.     ? \x -> x + x
  233.     ERROR: Unresolved overloading
  234.     *** type        : Num a => a -> a
  235.     *** translation : \d125 x -> (+) d125 x x
  236.  
  237.     ? :t map (1+) [1..10]
  238.     map ((+) {dict} 1) (enumFromTo {dict} 1 10) :: [Int]
  239.     ?
  240.  
  241. If necessary (perhaps to make the output of Gofer easier for a beginner
  242. to understand), the printing of dictionary parameters may be suppressed
  243. using the -d option:
  244.  
  245.     ? :set -d
  246.     ? \x -> x + x
  247.     ERROR: Unresolved overloading
  248.     *** type        : Num a => a -> a
  249.     *** translation : \x -> x + x
  250.  
  251.     ? :t map (1+) [1..10]
  252.     map (1 +) (enumFromTo 1 10) :: [Int]
  253.     ?
  254.  
  255. The original behaviour can be obtained using :set +d within the
  256. interpreter.
  257.  
  258.  
  259. .ST 2.1.5  Terminate on error
  260. -------------------------
  261. When an irreducible subexpression is encountered during the evaluation
  262. of a particular expression, the irreducible redex is printed with
  263. surrounding braces and the Gofer interpreter attempts to continue the
  264. evaluation with other parts of the original expression:
  265.  
  266.     ? take (1/0) [1..]          -- value is bottom
  267.     {primDivInt 1 0}
  268.     (4 reductions, 33 cells)
  269.     ? [1/0]                     -- value is [bottom]
  270.     [{primDivInt 1 0}]
  271.     (5 reductions, 34 cells)
  272.     ? [1/0, 2]                  -- value is [bottom, 2]
  273.     [{primDivInt 1 0}, 2]
  274.     (7 reductions, 43 cells)
  275.     ?
  276.  
  277. Notice that, reading an expression enclosed in {braces} as bottom, each
  278. of the values printed by Gofer gives the correct value.  Of course, it
  279. is not possible to arrange for anything to be printed when a value of
  280. bottom is generated by a nonterminating computation:
  281.  
  282.     ? last [1..]
  283.     ^C{Interrupted!}            -- nothing printed until interrupted
  284.  
  285.     (10470 reductions, 15712 cells)
  286.     ?
  287.  
  288. An alternative behaviour is provided by the +f option, which causes the
  289. evaluation of an expression to be abandoned completely if an error
  290. occurs:
  291.  
  292.     ? :set +f
  293.     ? take (1/0) [1..]
  294.  
  295.     Aborting evaluation: {primDivInt 1 0}
  296.     (3 reductions, 55 cells)
  297. .pa
  298.     ? [1/0]
  299.  
  300.     Aborting evaluation: {primDivInt 1 0}
  301.     (3 reductions, 54 cells)
  302.  
  303.     ? [1/0,2]
  304.  
  305.     Aborting evaluation: {primDivInt 1 0}
  306.     (3 reductions, 56 cells)
  307.  
  308.     ?
  309.  
  310. Note that we are no longer able to distinguish between the values
  311. produced by these three terms from the output produced by Gofer -- the
  312. only differences are in the number of reductions and cells used which
  313. tells us nothing about the values of the terms.  Note that the basic
  314. method of evaluation in Gofer is unchanged -- the +f option simply
  315. modifies the printing mechanism (i.e the means by which values are
  316. displayed) to be more strict (in the technical sense of the word).
  317.  
  318. Although the use of the +f option makes the Gofer printing mechanism
  319. less accurate, it is sometimes useful during program development so
  320. that an error can be detected as soon as it occurs.  The original
  321. behaviour can of course be restored at any time using the -f
  322. option.
  323.  
  324.  
  325. .ST 2.1.6  Heap size
  326. ----------------
  327. The -hnumber option can be used to set the heap size (i.e. total number
  328. of cells available at any one time), but cannot be used once the
  329. interpreter has been loaded.  For example, starting the interpreter
  330. with the command:
  331.  
  332.     gofer -h20000
  333.  
  334. will typically start the Gofer interpreter with a heap of 20000 cells.
  335. Note that the heap is used to hold an intermediate (parsed) form of an
  336. input file while it is being read, type checked and compiled.  It
  337. follows that, the larger the input file, the larger the heap required
  338. to enable that file to be loaded into Gofer.  In practice, most large
  339. programs are written (and loaded) as a number of separate files (see
  340. section 2.2) which means that this does not usually cause problems.
  341.  
  342.  
  343. .ST 2.1.7  Garbage collector notification
  344. -------------------------------------
  345. It is sometimes helpful to be able to tell when the garbage collector
  346. is being used, in order to monitor the amount of time involved and the
  347. number of cells recovered with each garbage collection.  If the +g
  348. command line option is given (for example, using the command :set +g)
  349. then the garbage collector prints a message of the form {{Gc:num}} each
  350. time that the garbage collector is invoked.  The number after the colon
  351. indicates the total number of cells that have been recovered.
  352.  
  353. .pa
  354. The garbage collector messages are actually printed in three sections,
  355. which indicate which stage the garbage collector has reached (this is
  356. only noticeable on slower machines of course!):
  357.  
  358.             {{Gc                :              number}}
  359.  
  360.    garbage       marking cells      preparing           garbage
  361.    collection      which are       unused cells         collection
  362.    begins         still in use      for reuse           completed
  363.  
  364. Garbage collector messages may be printed at almost any stage in a
  365. computation (or indeed whilst loading, type checking or compiling a
  366. file of definitions).  For this reason, it is often better to turn
  367. the garbage collector messages off (using :set -g for example) when
  368. they are not required.
  369.  
  370.  
  371. .ST 2.1.8  Conformality testing
  372. ---------------------------
  373. As described briefly in section 9.11 of the documentation for Gofer
  374. version 2.20, pattern bindings of the form pat=expr are implemented
  375. using a `conformality check' to ensure that the value of expr does
  376. indeed match the pattern pat.  For example, the pattern binding:
  377.  
  378.     (x:xs) = [1..]
  379.  
  380. is actually implemented as if it had been defined by:
  381.  
  382.     (x:xs) = conformality [1..]
  383.              where conformality v@(_:_) = v
  384.  
  385. which is in turn treated as a group of bindings:
  386.  
  387.     xxs    = conformality [1..] where conformality v@(_:_) = v
  388.     x      = head xxs
  389.     xs     = tail xxs
  390.  
  391. [The variables conformality and xxs used here are given as examples
  392. only -- in practice, Gofer maintains a supply of variable names and
  393. selects new names from this supply to avoid clashes with variables
  394. which are already in use.]
  395.  
  396. The conformality check does not cause any problems in the example
  397. above because the list [1..] is always guaranteed to match the
  398. pattern (x:xs) (i.e. a non-empty list).  We can however see the
  399. conformality check in action if we try examples in which the pattern
  400. does not match:
  401.  
  402.     ? x where (x:xs) = []
  403.     {v114 []}
  404.     (3 reductions, 25 cells)
  405.  
  406.     ? xs where (0:xs) = [1..]
  407.     {v114 [1] ++ iterate (primPlusInt 1) (primPlusInt 1 1)}
  408.     (13 reductions, 94 cells)
  409.     ?
  410.  
  411. The variable v114 in each of these examples is the variable name
  412. representing the conformality check.  As the second example shows, the
  413. value of the expression on the right hand side of the pattern binding
  414. is evaluated as much as necessary to determine whether the pattern
  415. fits.
  416.  
  417. [ASIDE: This example also demonstrates a small problem with the printer
  418. in that, when the first element of the list is encountered, it is
  419. unable to detect that the tail of the list has not yet been evaluated.
  420. Consequently, the expression:
  421.  
  422.     [1] ++ iterate (primPlusInt 1) (primPlusInt 1 1)
  423.  
  424. is not enclosed in parentheses as it should be.  This is a little
  425. annoying, but not important because the expression only appears in an
  426. error message.  The problem cannot in general be solved unless we avoid
  427. the use of the [...] notation for enumerating the elements of a list.]
  428.  
  429. The conformality check must be used for compatibility with Haskell.
  430. However, it is sometimes useful to be able to suppress the conformality
  431. check using the -c option (for example, to use some programs written
  432. for a language without conformality checks within Gofer):
  433.  
  434.     ? :set -c
  435.     ? x where (x:xs) = []
  436.     {_SEL (:) [] 1}
  437.     (5 reductions, 36 cells)
  438.     ? xs where (0:xs) = [1..]
  439.     [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14^C{Interrupted!}
  440.  
  441.     (55 reductions, 146 cells)
  442.     ?
  443.  
  444. In the first example, the expression _SEL (:) [] 1 indicates that the
  445. first component of an object constructed using the (:) operator is to
  446. be extracted from the object [].  Clearly this is impossible, and hence
  447. the expression _SEL (:) [] 1 is irreducible.  In the second case, the
  448. value of xs is equivalent to _SEL (:) (1:[2..]) 2 which reduces to
  449. the infinite list [2..] as shown, despite the fact that [1..] does not
  450. match the pattern (0:xs).
  451.  
  452. [ASIDE: The _SEL function is used internally by Gofer and cannot be
  453. entered directly into the the interpreter.  One particular reason for
  454. this is that it is not in general possible to assign a sensible type
  455. to _SEL.  Constructor functions appearing as the first argument to _SEL
  456. are printed in the normal manner.  There is no standard syntax for
  457. writing tuple constructors in Gofer or Haskell which are therefore
  458. printed in the form (,,,) for example, where the number of commas
  459. indicates the number of components in the tuple.  In the following
  460. example the constructor (,) denotes the pairing constructor.
  461.  
  462.     ? f a b where f (n+1) y = n+y;  (a,b) = (0,1)
  463.     {v113 0 (_SEL (,) (0,1) 2)}
  464.     (10 reductions, 63 cells)
  465.     ?
  466.  
  467. The same notation is sometimes used in the messages produced when type
  468. errors are detected:
  469.  
  470.     ? (1,2) 3
  471.     ERROR: Type error in application
  472.     *** expression     : (1,2) 3
  473.     *** term           : (,)
  474.     *** type           : a -> b -> (a,b)
  475.     *** does not match : c -> d -> e -> f
  476.  
  477.     ?
  478.  
  479. This syntax for tuple constructor functions cannot be used in
  480. expressions entered directly into Gofer.  It may however be a nice
  481. extension to consider for future versions, allowing definitions such
  482. as zip = zipWith (,)  and  distl x = map (x,).]
  483.  
  484.  
  485. .ST 2.1.9  Literate scripts
  486. -----------------------
  487. In common with most programming languages, Gofer typically treats input
  488. from a file as a list definitions in which program text is the norm,
  489. and comments play a secondary role, introduced by the character
  490. sequences ``--'' and ``{- ... -}''.
  491.  
  492. An alternative approach, using an idea described by Knuth as ``literate
  493. programming'', gives more emphasis to comments and documentation, with
  494. additional characters needed to distinguish program text from comments.
  495. Gofer supports a form of literate programming based on an idea due to
  496. Richard Bird and originally implemented as part of the functional
  497. programming language Orwell.  The same idea has subsequently been
  498. adopted by several other functional language systems.
  499.  
  500. A literate script contains a sequence of lines.  Program lines are
  501. distinguished from comments by a `>' character in the first column.
  502. This makes it particularly easy to write a document which is both an
  503. executable program script and at the same time, without need for any
  504. preprocessing, suitable for use with document preparation software such
  505. as LaTeX.  Indeed, this document is itself a literate script containing
  506. the following definition of the squaring function.
  507.  
  508. > sqr x = x * x
  509.  
  510. The +l option sets Gofer to treat each input file as a literate
  511. script.  It should not be used on the command line unless the prelude
  512. file has been edited to make a literate script.
  513.  
  514. The effect of using literate scripts can be thought of as applying a
  515. preprocessor to each input file before it is loaded into Gofer.  This
  516. program has a particularly simple definition in Gofer:
  517.  
  518.    illiterate   :: String -> String
  519.    illiterate cs = unlines [ xs | ('>':xs) <- lines cs ]
  520.  
  521. The system of literate scripts used in Orwell is actually a little more
  522. complicated than this and requires that the programmer adopt two simple
  523. conventions in an attempt to try to catch simple errors in literate
  524. scripts:
  525.  
  526.   o  Every input file must contain at least one line whose first
  527.      character is `>'.  This means that programs containing no
  528.      definitions (because the programmer has forgotten to use the `>'
  529.      character to mark definitions) from being accepted.
  530.  
  531.   o  Lines containing definitions must be separated from comment lines
  532.      by one or more blank lines (i.e. lines containing only space and
  533.      tab characters).  This is useful for catching programs where the
  534.      leading `>' character has been omitted from one or more lines in
  535.      the definition of a function.  For example:
  536.  
  537.      >   map f []     = []
  538.          map f (x:xs) = f x : map f xs
  539.  
  540.      would result in an error if the `>' character appeared in the first
  541.      column of the first line.
  542.  
  543. Gofer will report on errors of this kind if the +l option is combined
  544. with the +e option (for example as +le).
  545.  
  546.  
  547. .ST 2.1.10 Optimise (&&) and (||)
  548. -----------------------------
  549. The operator symbols (&&) and (||) are usually used to represent the
  550. boolean connectives conjunction (and) and disjunction (or).  By
  551. default, Gofer uses the following equations to produce better code for
  552. expressions involving these operators:
  553.  
  554.          x && y  =  if  x  then  y     else  False
  555.          x || y  =  if  x  then  True  else  y
  556.  
  557. This optimization is only valid if the operator symbols (&&) and (||)
  558. are indeed bound to the appropriate values at the top level (the
  559. standard full definitions are required in order to support partial
  560. applications involving these operators).  Although this optimization is
  561. in general valid (because the appropriated definitions are included in
  562. the standard prelude), it may be necessary in certain cases (for
  563. example, when working with a non-standard prelude) to suppress the
  564. optimization using the -o option.
  565.  
  566. .pa
  567. .ST 2.2  Project Files
  568. ------------------
  569. Project files provide a simple way to use programs which are
  570. spread across a number of source files.  Larger programs are often
  571. written in this way, to separate the different components of the
  572. program into smaller pieces which can be developed and tested
  573. independently of other components.
  574.  
  575. A project file is a simple text file containing a list of program
  576. filenames.  The project file may also contain comments using either of
  577. the Gofer conventions for comments.  As a simple example, a simple
  578. project file, in a file named "miniProlog", suitable for the
  579. stack-based version of the mini Prolog interpreter included as a
  580. demonstration program with Gofer 2.21 is as follows:
  581.  
  582.     -- This is a project file suitable for loading the stack-based
  583.     -- version of the mini Prolog interpreter into Gofer 2.21
  584.     --
  585.     -- Load into Gofer using the command:   :p miniProlog
  586.     --        or from command line using:   gofer + miniProlog
  587.  
  588.     Parse       -- general purpose parsing library
  589.     Interact    -- general purpose library for interactive programs
  590.     PrologData  -- definition of main data structures
  591.     Subst       -- substitutions and unification
  592.     StackEngine -- inference engine
  593.     Main        -- top level program
  594.  
  595. As indicated in the comments at the top, there are two ways of using
  596. this file with Gofer.  Within the interpreter we can use the command
  597. :p miniProlog.  Once this command has been entered, Gofer reads the
  598. contents of the project file and then attempts to load each of the
  599. files named.  In general, if a particular project file "proj" contains
  600. the options op1, ..., opn and the filenames f1, ..., fm, then the
  601. command :p proj is equivalent to the sequence of commands:
  602.  
  603.     :l                -- clear any previously loaded scripts
  604.     :set op1 ... opn  -- set options
  605.     :l f1 ... fm      -- load files
  606.  
  607. The project file name may also be specified on the command line used to
  608. start the interpreter by preceding the project file name with a single
  609. `+' character.  Note that there must be at least one space on each side
  610. of the `+'.  This may be combined with standard command line options,
  611. but any additional filename arguments will be ignored.  Starting Gofer
  612. with a command of the form "gofer + proj" is equivalent to starting
  613. Gofer without the "+ project" arguments and then giving the command
  614. :p proj.
  615.  
  616. In addition, Gofer records the name of the project file and displays
  617. this with the list of files loaded.  For example:
  618.  
  619.     Gofer session for: (project: miniProlog)
  620.     /users/mpj/public/Gofer/prelude 
  621.     Parse
  622.     Interact
  623.     PrologData
  624.     Subst
  625.     StackEngine
  626.     Main
  627.     ? 
  628.  
  629. Once a project file has been selected, the command :p (without any
  630. arguments) can be used to force Gofer to reread the project file and
  631. load fresh copies of each of the files listed there.  There are two
  632. places in which this is particularly useful:
  633.  
  634.   o  If the project file itself has been modified since the last time
  635.      that it was read.
  636.  
  637.   o  To force Gofer to reload all of the files in the project,
  638.      regardless of the last time they were modified.
  639.  
  640. As usual, the :r command can be used to reload each of the files in the
  641. current project without rereading the project file itself, and avoiding
  642. the need to read certain files which have not been modified since the
  643. previous time they were loaded.
  644.  
  645. The use of project files integrates smoothly with the other parts of
  646. the Gofer environment.  As an example consider a project file proj
  647. containing the four filenames f1, f2, f3 and f4, and suppose that the
  648. file f3 contains an error of some kind.  This leads to the following
  649. sequence of commands and results:
  650.  
  651.     :p proj       -- attempt to load project proj
  652.                   -- reads filenames f1, f2, f3, f4 from proj
  653.                   -- load definitions from f1
  654.                   -- load definitions from f2
  655.                   -- load definitions from f3 -- error occurs
  656.                   -- error message printed
  657.     :e            -- starts up editor at relevant line in f3
  658.                   -- correct error
  659.                   -- exit editor
  660.                   -- load definitions from f3
  661.                   -- load definitions from f4
  662.  
  663. After just these two commands, the error in f3 has been corrected and
  664. all of the files mentioned in proj have been loaded, ready for use.
  665.  
  666. .pa
  667. .ST 2.3  Other new features
  668. -----------------------
  669.  
  670. .ST 2.3.1  :find - find definition
  671. ------------------------------
  672. The command ":f name" starts up an editor to allow you to inspect (and
  673. possibly modify) the definition of a particular name from the files
  674. currently loaded into Gofer.  If supported (using the EDITLINE
  675. variable), Gofer will attempt to initialize the editor so that the
  676. cursor is initially positioned at the first line in the definition.
  677. There are three possibilities:
  678.  
  679.   o  If the name is defined by a function or variable binding then
  680.      the cursor is positioned at the first line in the definition of
  681.      the name (ignoring any type declaration, if present).
  682.  
  683.   o  If the name is a constructor function, then the cursor is
  684.      positioned at the first line in the definition of the
  685.      corresponding data definition.
  686.  
  687.   o  If the name represents an internal Gofer function, then the
  688.      cursor will be positioned at the beginning of the standard
  689.      prelude file.
  690.  
  691. Note that names of infix operators should be given without any
  692. enclosing them in parentheses.  Thus ":f ++" starts an editor on the
  693. standard prelude at the first line in the definition of (++).
  694.  
  695.  
  696. .ST 2.3.2  :! - shell escape
  697. ------------------------
  698. A command of the form ":! cmd" can be used to execute a specified
  699. system command without leaving the Gofer interpreter.  For example,
  700. ":! ls" (or ":! dir" on MS DOS machines) can be used to list the
  701. contents of the current directory.
  702.  
  703. The command ":!" without any arguments starts a new shell:
  704.  
  705.   o  On a unix machine, the SHELL environment variable is used to
  706.      determine which shell to use (the default is "/bin/sh").
  707.  
  708.   o  On an MS DOS machine, the COMSPEC environment variable is used
  709.      to determine which shell to use.  This is usually COMMAND.COM
  710.      and you may return to Gofer using the EXIT command.
  711.  
  712. As usual, it is not possible to use a shell escape to change the
  713. current working directory.  The :cd command described in the following
  714. section can be used for this purpose.
  715.  
  716.  
  717. .ST 2.3.3  :cd - change directory
  718. -----------------------------
  719. The command ":cd dir" changes the current working directory to the path
  720. given by "dir".  This command is ignored if the pathname is omitted.
  721.  
  722.  
  723. .ST 2.3.4  :names - list names
  724. --------------------------
  725. The :n command lists the names of variables and functions whose
  726. definitions are currently loaded into the Gofer interpreter.  Using
  727. this command without any arguments produces the list of all names
  728. known to the system.  For example, with just the standard prelude
  729. loaded we obtain:
  730.  
  731.     ? :n
  732.     !! && * + ++ - . / /= : < <= == > >= AppendChan AppendFile Echo
  733.     Failure False FormatError OtherError ReadChan ReadError ReadFile
  734.     SearchError Str Success True WriteError WriteFile [] \\ ^ abort abs
  735.     all and any appendChan appendFile asTypeOf break chr cjustify
  736.     concat const copy curry cycle div done drop dropWhile echo elem
  737.     enumFrom enumFromThen enumFromThenTo enumFromTo error even exit
  738.     filter flip foldl foldl' foldl1 foldr foldr1 fromInteger fst fst3
  739.     gcd head help id inRange index init insert interact isAlpha
  740.     isAlphanum isAscii isControl isDigit isLower isPrint isSpace
  741.     isUpper iterate last layn lcm length lines ljustify map max maximum
  742.     merge min minimum mod negate not notElem nub null odd or ord
  743.     otherwise primDivFloat primDivInt primEqFloat primEqInt
  744.     primIntToFloat primLeFloat primLeInt primMinusFloat primMinusInt
  745.     primMulFloat primMulInt primNegFloat primNegInt primPlusFloat
  746.     primPlusInt primPrint print prints product products qsort range
  747.     readChan readFile rem repeat reverse rjustify run scanl scanl'
  748.     scanl1 scanr scanr1 show show' showChar showList showString shows
  749.     showsPrec signum snd snd3 sort space span splitAt stdecho stderr
  750.     stdin stdout strDispatch strict subtract succDispatch sum sums tail
  751.     take takeUntil takeWhile thd3 toLower toUpper transpose uncurry
  752.     undefined unlines until until' unwords words writeFile zip zip3
  753.     zip4 zip5 zip6 zip7 zipWith zipWith3 zipWith4 zipWith5 zipWith6
  754.     zipWith7 ||
  755.     (201 names listed)
  756.     ?
  757.  
  758. Note that the names are listed in the standard alphabetical order.
  759.  
  760. The :n can also accept one or more pattern strings which limits the list
  761. of names printed to those names matching one or more of the given
  762. pattern strings:
  763.  
  764.     ? :n fold*
  765.     foldl foldl' foldl1 foldr foldr1
  766.     (5 names listed)
  767.     ?
  768.  
  769. Each pattern string consists of a string of characters and may use the
  770. standard wildcard characters: `*' (matches anything), `?' (matches any
  771. single character), `\c' (matches exactly the character c) and ranges of
  772. characters of the form `[a-zA-Z]' etc.  For example:
  773.  
  774.     ? :n *ap* *[Cc]han \\\\ ?
  775.     * + - . / : < > AppendChan ReadChan \\ ^ appendChan appendFile
  776.     map readChan
  777.     (16 names listed)
  778.     ?
  779.  
  780.  
  781. .ST 2.3.5  $$ - recall last expression
  782. ----------------------------------
  783. The previously entered expression can be recalled at any stage whilst
  784. using the Gofer interpreter (even if the list of currently loaded files
  785. has subsequently been changed) by using the operator symbol $$:
  786.  
  787.     ? 42
  788.     42
  789.     (1 reduction, 5 cells)
  790.     ? [$$]
  791.     [42]
  792.     (3 reductions, 12 cells)
  793.     ? [$$]
  794.     [[42]]
  795.     (5 reductions, 19 cells)
  796.     ? ($$, length $$)
  797.     ([[42]],1)
  798.     (14 reductions, 43 cells)
  799.     ?
  800.  
  801. The $$ symbol is bound to a new value each time that an expression is
  802. evaluated, or its type determined using the :t command:
  803.  
  804.     ? :t $$
  805.     ([[42]],length [[42]]) :: ([[Int]],Int)
  806.     ? :t map (1+) [1..10]
  807.     map ((+) {dict} 1) (enumFromTo {dict} 1 10) :: [Int]
  808.     ? $$
  809.     [2, 3, 4, 5, 6, 7, 8, 9, 10, 11]
  810.     (100 reductions, 189 cells)
  811.     ?
  812.  
  813. Note that $$ can also be used when the last expression entered used
  814. a where clause (such expressions are simply translated into the
  815. appropriate let expressions):
  816.  
  817.     ? fibs where fibs = 0:1:zipWith (+) fibs (tail fibs)
  818.     [0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55^C{Interrupted!}
  819.  
  820.     (41 reductions, 136 cells)
  821.     ? :t $$
  822.     let {...} in fibs :: [Int]
  823.     ? take 5 $$
  824.     [0, 1, 1, 2, 3]
  825.     (24 reductions, 77 cells)
  826.     ?
  827.  
  828. Note that $$ expands to the unevaluated form of the expression, so that
  829. a certain amount of computation may be repeated if $$ is used more than
  830. once in a subsequent expression:
  831.  
  832.     ? sum [1..10]
  833.     55
  834.     (92 reductions, 130 cells)
  835.     ? $$ + $$
  836.     110
  837.     (176 reductions, 254 cells)
  838.     ? x + x where x = sum [1..10]
  839.     110
  840.     (89 reductions, 131 cells)
  841.     ?
  842.  
  843. Note that the value of $$ is updated after the expression has been parsed
  844. but before it is type checked:
  845.  
  846.     ? 42
  847.     42
  848.     (1 reduction, 5 cells)
  849.     ? 4)
  850.     ERROR: Syntax error in input (unexpected `)')
  851.     ? $$ 4
  852.     ERROR: Type error in application
  853.     *** expression     : 42 4
  854.     *** term           : 42
  855.     *** type           : Int
  856.     *** does not match : a -> b
  857.  
  858.     ?
  859.  
  860.  
  861. .ST 2.3.6  Command names
  862. --------------------
  863. Command names of the form :X (where X represents an arbitrary capital
  864. letter) are no longer supported.  Each command has a mnemonic full name
  865. of the form :name which can be abbreviated to :n where `n' is the first
  866. letter of the full name.  The complete list of commands produced by the
  867. :? command is as follows:
  868.  
  869.     ? :?
  870.     LIST OF COMMANDS:  Any command may be abbreviated to :c where
  871.     c is the first character in the full name.
  872.  
  873.     :set <options>      set command line options
  874.     :set                help on command line options
  875.     :?                  display this list of commands
  876.     <expr>              evaluate expression
  877.     :type <expr>        print type of expression
  878.     :names [pat]        list names currently in scope
  879.     :load <filenames>   load scripts from specified files
  880.     :load               clear all files except prelude
  881.     :also <filenames>   read additional script files
  882.     :reload             repeat last load command
  883.     :project <filename> use project file
  884.     :edit <filename>    edit file
  885.     :edit               edit last file
  886.     :find <name>        edit file containing definition of name
  887.     :! command          shell escape
  888.     :cd dir             change directory
  889.     :quit               exit Gofer interpreter
  890.     ?
  891.  
  892.  
  893. .pa
  894. .co-------------------------------------------------------------------|
  895. .ST 3. LANGUAGE DIFFERENCES
  896.  
  897. There are very few changes to the language supported by Gofer -- most
  898. programs that ran correctly under the previous release should run
  899. without any changes.  The features described in the following sections
  900. are (for the most part) extensions to the previous version.
  901.  
  902. .ST 3.1 c*p and p+k patterns
  903. ------------------------
  904. Motivated by recent discussion on the Haskell mailing list, starting
  905. with a posting from Tony Davie, Gofer now supports a more general form
  906. of n+k pattern, together with a new form of pattern, c*p.  The syntax
  907. of patterns is extended to include:
  908.  
  909.         pattern ::= .... | pattern + integer | integer * pattern
  910.  
  911. Note that, in the previous version of Gofer, only variables were
  912. permitted for the pattern p in a p+k pattern.  Certain restrictions are
  913. placed on the constants c and k used in c*p and p+k patterns; Gofer
  914. currently requires c>1 and k>0.
  915.  
  916. The semantics of these new patterns are described by the equations
  917. (suggested by Kent Karlsson):
  918.  
  919.     case e0 of {p+k -> e; _ -> e'}
  920.       = if e0 >= k then case e0-k of {p -> e; _ -> e'} else e'
  921.  
  922.     case e0 of {c*p -> e; _ -> e'}
  923.       = if e0 >= 0 then  case e0 `divRem` c of {(p, 0) -> e; _ -> e'}
  924.                    else  e'
  925.  
  926. In Gofer, both forms of pattern match nonnegative integers only (there
  927. is no possibility for overloading here as there is in Haskell).
  928.  
  929. These features are included in Gofer to enable experimentation with the
  930. use of c*p patterns.  They are not currently supported by Haskell, and
  931. are subject to change as we gain more experience using them.  To
  932. illustrate the potential uses for these extensions, here are two
  933. examples provided by Tony Davie in his original message which can be
  934. used in Gofer:
  935.  
  936.     x^^0       = 1                     -- fast exponentiation 
  937.     x^^(2*n)   = xn*xn where xn = x^^n -- compare with definition
  938.     x^^(2*n+1) = x * x^^(2*n)          -- of (^) in the prelude
  939.  
  940.     fib 1       = 1                    -- fast fibonnacci
  941.     fib 2       = 1
  942.     fib (2*n)   = (fib(n+1))^^2 - (fib(n-1))^^2
  943.     fib (2*n+1) = (fib(n+1))^^2 + (fib n   )^^2
  944.  
  945.  
  946. .ST 3.2 Errors during output
  947. ------------------------
  948. If an error of the form "error str" occurs during an output request in
  949. a program using the facilities for I/O, the IOError value passed to
  950. the failure continuation is the (WriteError str), rather than
  951. (WriteError "{error str}") as in the previous release.  This enables
  952. further evaluation of the string str (for example to produce a
  953. compound error message by concatenating several strings together).
  954.  
  955. You are strongly advised to consider using the standard prelude
  956. continuation "exit" in your programs in place of the "abort" predicate;
  957. whereas "abort" causes a program to terminate without any indication of
  958. the problem, "exit" attempts to print a suitable error message before
  959. the program terminates.
  960.  
  961.  
  962. .ST 3.3 Type synonyms in predicates
  963. -------------------------------
  964. Type synonyms may now be used in predicates (The previous release
  965. allowed only data constructors).  This means that programs such as the
  966. cat program described in section 14.2.6 (page 68) of the Gofer
  967. documentation can now be written as:
  968.  
  969.     class    Cat a        where cat  :: a -> Dialogue
  970.     instance Cat String   where cat n = showFile n done
  971.     instance Cat [String] where cat   = foldr showFile done
  972.  
  973.     showFile name cont = readFile name abort
  974.                              (\s->appendChan stdout s abort cont)
  975.  
  976. This uses the type synonym String in place of the expanded form [Char]
  977. required by the original program.  Note that it is still not permitted
  978. to define overlapping instances; an attempt to add an instance for Cat
  979. [Char] to the above will not be accepted.
  980.  
  981.  
  982. .ST 3.4 Reporting on ambiguous types
  983. --------------------------------
  984. Class declarations whose member functions have ambiguous types are no
  985. longer permitted.  For example, in the class declaration:
  986.  
  987.     class Box a where
  988.         mem :: Int
  989.  
  990. The type of the member function mem is Box a => Int which is ambiguous
  991. and produces the error message:
  992.  
  993.     ERROR "examp" (line 3): Ambiguous type signature in class declaration
  994.     *** ambiguous type : Box a => Int
  995.     *** assigned to    : mem
  996.  
  997.     ?
  998.  
  999. Similar error messages are produced when an explicit type signature
  1000. includes an ambiguous type.  For example:
  1001.  
  1002.     func   :: Eq a => Int -> Int
  1003.     func x  = 2*x+1
  1004.  
  1005. Results in an error of the form:
  1006.  
  1007.     ERROR "examp" (line 12): Ambiguous type signature in type declaration
  1008.     *** ambiguous type : Eq a => Int -> Int
  1009.     *** assigned to    : func
  1010.  
  1011.     ?
  1012.  
  1013. By default, no error is signalled if an ambiguous type is assigned to a
  1014. variable or function by the type checker.  This makes it possible to
  1015. write definitions such as:
  1016.  
  1017.     f y xs  =  if xs==[] then 0 else g y
  1018.     g y     =  f y []
  1019.  
  1020. The types obtained for each of these terms is as follows:
  1021.  
  1022.     f :: Eq [a] => b -> [a] -> Int
  1023.     g :: Eq [a] => b -> Int
  1024.  
  1025. Note that the second type is ambiguous.  Making the analogy between
  1026. these mutually recursive functions and a two state machine, we can
  1027. think of a direct call to f as initializing the machine correctly so
  1028. that there is no problem when we enter g.  On the other hand, entering
  1029. the system at g does not initialize the machine correctly, as signalled
  1030. by the ambiguity.
  1031.  
  1032. Using the +u command line flag forces Gofer to generate an error when
  1033. an attempt to assign an ambiguous type to a top-level function occurs.
  1034. For the above example this gives:
  1035.  
  1036.     ERROR "examp" (line 20): Ambiguous type signature in inferred type
  1037.     *** ambiguous type : Eq [a] => b -> Int
  1038.     *** assigned to    : g
  1039.  
  1040.     ?
  1041.  
  1042. The restriction to top-level functions means that f can still be
  1043. implemented by writing:
  1044.  
  1045.     f :: Eq [a] => b -> [a] -> Int
  1046.     f  = f'  where  f' y xs = if xs==[] then 0 else g y
  1047.                     g' y    = f y []
  1048.  
  1049. which prevents external access to g' (preventing entry to the finite
  1050. machine described above in state g).  Note that the type signature in
  1051. this example is necessary to avoid the monomorphism restriction.
  1052.  
  1053.  
  1054. .pa
  1055. .co-------------------------------------------------------------------|
  1056. .ST 4. OTHER MATTERS
  1057.  
  1058. .ST 4.1 Contributions
  1059. -----------------
  1060. I would like to hear from anyone with interesting Gofer programs or
  1061. other useful items which might be included (with full credit to the
  1062. original author(s) of course!) in subsequent releases of Gofer.  There
  1063. is already one example of this in the new release; a small gnuemacs
  1064. mode for running the Gofer interpreter from within gnuemacs on Unix
  1065. machines, contributed by Stuart Clayman.  See the file gofer.el for
  1066. more details.
  1067.  
  1068. .ST 4.2 Future directions
  1069. ---------------------
  1070. There will not be another release of Gofer for some time.  There are
  1071. however a number of areas which I would like to investigate at some
  1072. point as extensions to the Gofer system:
  1073.  
  1074.   o  The ability to use Haskell style type classes.
  1075.  
  1076.   o  Facilities for working with modules, based on the approach
  1077.      described in the Haskell report.  A particular problem here is
  1078.      in finding an elegant way to provide the full power of the
  1079.      module system from the interactive environment.
  1080.  
  1081.   o  The ability to write stand alone applications programs using
  1082.      Gofer.
  1083.  
  1084.   o  An improved user interface.  There are a number of grand ideas
  1085.      based on the use of windowing/mouse/pulldown-menus etc.  The
  1086.      current user interface is closer to this kind of approach than
  1087.      might at first be realized.  More interesting ideas include the
  1088.      design of class, data type and value browsers, along the lines
  1089.      of a Smalltalk system.
  1090.  
  1091. I would be interested to hear from anyone with comments or suggestions
  1092. on any of these (or other ideas).
  1093. .co-------------------------------------------------------------------|
  1094.