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

  1.  
  2.  
  3. Introduction to Gofer                            APPENDIX E: PRIMITIVES
  4.  
  5.  
  6. APPENDIX E: PRIMITIVES
  7.  
  8. [WARNING: The features described in this appendix  are  typically  only
  9. needed when alternative versions of the standard prelude  are  created.
  10. These features should only be used by expert users; misuse may lead  to
  11. failure and runtime errors in the Gofer interpreter.  It is not usually
  12. a good idea to use primitive functions directly in your programs.]
  13.  
  14. A number of primitive functions are builtin to the  Gofer  interpreter,
  15. and may be bound to function symbols using a declaration of the form:
  16.  
  17.     primitive name1 code1, name2 code2, ...., namen coden :: type
  18.  
  19. where each name is an identifier (or an  operator  symbol  enclosed  by
  20. parentheses) and each code is a string literal  taken  from  the  table
  21. below.  The type specified to the right of the  ::  symbol  must  be  a
  22. valid type for the functions being defined -- WARNING: GOFER  DOES  NOT
  23. ATTEMPT TO CHECK FOR SUITABILITY OF THE DECLARED TYPE.   The  following
  24. definition, taken from the standard prelude,  illustrates  the  use  of
  25. this feature to bind  a  function  named  primPrint  to  the  primitive
  26. function with code name string "primPrint" and type Int -> a ->  String
  27. -> String:
  28.  
  29.     primitive primPrint "primPrint"  :: Int -> a -> String -> String
  30.  
  31. The primitive functions currently available are:
  32.  
  33. category     code name string    type
  34. --------     ----------------    ----
  35.  
  36. integer      primPlusInt         Int -> Int -> Int 
  37. arithmetic   primMinusInt        Int -> Int -> Int
  38.              primMulInt          Int -> Int -> Int
  39.              primDivInt          Int -> Int -> Int
  40.              primModInt          Int -> Int -> Int
  41.              primRemInt          Int -> Int -> Int
  42.              primNegInt          Int -> Int -> Int
  43.  
  44.  
  45. floating     primPlusFloat       Float -> Float -> Float
  46. point        primMinusFloat      Float -> Float -> Float
  47. arithmetic   primMulFloat        Float -> Float -> Float
  48.              primDivFloat        Float -> Float -> Float
  49.              primNegFloat        Float -> Float -> Float
  50.  
  51.  
  52. coercion     primIntToChar       Int -> Char  -- chr in the standard prelude
  53. functions    primCharToInt       Char -> Int  -- ord in the standard prelude
  54.              primIntToFloat      Int -> Float -- implements fromInteger
  55.  
  56. equality     primEqInt           Int -> Int -> Bool
  57. and <=       primLeInt           Int -> Int -> Bool
  58. primitives   primEqFloat         Float -> Float -> Bool
  59.              primLeFloat         Float -> Float -> Bool
  60.  
  61.  
  62.  
  63.  
  64.                                       119
  65.  
  66.  
  67.  
  68.  
  69. Introduction to Gofer                            APPENDIX E: PRIMITIVES
  70.  
  71.  
  72. generic      primGenericEq       a -> a -> Bool
  73. ordering     primGenericNe       a -> a -> Bool
  74. primitives   primGenericGt       a -> a -> Bool
  75.              primGenericLe       a -> a -> Bool
  76.              primGenericGe       a -> a -> Bool
  77.              primGenericLt       a -> a -> Bool
  78.  
  79.              These functions implement the standard generic  (i.e.  non
  80.              overloaded) ordering primitives.  They are  not  currently
  81.              used in the standard prelude.  A simplified prelude may be
  82.              created by binding the  standard  operator  symbols  (==),
  83.              (/=),  (>),  (<=),  (>=)  and  (<)  to   these   functions
  84.              respectively.
  85.  
  86. output       primPrint           Int -> a -> String -> String
  87.  
  88.              This function is used to implement the show'  function  in
  89.              the standard prelude and is not usually used directly.
  90.  
  91.              primPrint d e s produces a textual representation  of  the
  92.              value of the expression e as a  string,  followed  by  the
  93.              string s.  The integer parameter d is used as an indicator
  94.              of the current precedence level.  The  primPrint  function
  95.              is the  standard  method  of  printing  the  value  of  an
  96.              expression whose type is not equivalent to the type String
  97.              used by the top-level of the Gofer interpreter.
  98.  
  99. sequencing   primStrict          (a -> b) -> a -> b
  100.  
  101.              The primStrict function (bound to the identifier  "strict"
  102.              in the standard prelude)  forces  the  evaluation  of  its
  103.              second argument before the function supplied as the  first
  104.              argument is  applied  to  it.   See  section  9.4  for  an
  105.              illustration.
  106.  
  107.  
  108.  
  109.  
  110.  
  111.  
  112.  
  113.  
  114.  
  115.  
  116.  
  117.  
  118.  
  119.  
  120.  
  121.  
  122.  
  123.  
  124.  
  125.  
  126.  
  127.  
  128.  
  129.  
  130.                                       120
  131.  
  132.  
  133.