The Ocaml System Release 4.00

The Ocaml System Release 4.00

The OCaml system release 4.00 Documentation and user's manual Xavier Leroy, Damien Doligez, Alain Frisch, Jacques Garrigue, Didier R´emy and J´er^omeVouillon July 26, 2012 Copyright © 2012 Institut National de Recherche en Informatique et en Automatique 2 Contents I An introduction to OCaml 9 1 The core language 11 1.1 Basics . 11 1.2 Data types . 12 1.3 Functions as values . 13 1.4 Records and variants . 14 1.5 Imperative features . 16 1.6 Exceptions . 18 1.7 Symbolic processing of expressions . 19 1.8 Pretty-printing and parsing . 20 1.9 Standalone OCaml programs . 23 2 The module system 25 2.1 Structures . 25 2.2 Signatures . 26 2.3 Functors . 27 2.4 Functors and type abstraction . 29 2.5 Modules and separate compilation . 31 3 Objects in OCaml 33 3.1 Classes and objects . 33 3.2 Immediate objects . 36 3.3 Reference to self . 37 3.4 Initializers . 38 3.5 Virtual methods . 38 3.6 Private methods . 40 3.7 Class interfaces . 42 3.8 Inheritance . 43 3.9 Multiple inheritance . 44 3.10 Parameterized classes . 44 3.11 Polymorphic methods . 47 3.12 Using coercions . 50 3.13 Functional objects . 54 3.14 Cloning objects . 55 3.15 Recursive classes . 58 1 2 3.16 Binary methods . 58 3.17 Friends . 60 4 Labels and variants 63 4.1 Labels . 63 4.2 Polymorphic variants . 69 5 Advanced examples with classes and modules 73 5.1 Extended example: bank accounts . 73 5.2 Simple modules as classes . 79 5.3 The subject/observer pattern . 85 II The OCaml language 89 6 The OCaml language 91 6.1 Lexical conventions . 91 6.2 Values . 95 6.3 Names . 97 6.4 Type expressions . 99 6.5 Constants . 103 6.6 Patterns . 103 6.7 Expressions . 106 6.8 Type and exception definitions . 117 6.9 Classes . 120 6.10 Module types (module specifications) . 126 6.11 Module expressions (module implementations) . 130 6.12 Compilation units . 133 7 Language extensions 135 7.1 Integer literals for types int32, int64 and nativeint . 135 7.2 Streams and stream parsers . 135 7.3 Recursive definitions of values . 135 7.4 Range patterns . 137 7.5 Assertion checking . 137 7.6 Lazy evaluation . 137 7.7 Local modules . 138 7.8 Recursive modules . 138 7.9 Private types . 139 7.10 Local opens . 142 7.11 Record notations . 142 7.12 Explicit polymorphic type annotations . 143 7.13 Locally abstract types . 143 7.14 First-class modules . 145 7.15 Recovering the type of a module . 146 7.16 Substituting inside a signature . 147 3 7.17 Explicit overriding in class definitions . 148 7.18 Generalized algebraic datatypes . 149 III The OCaml tools 153 8 Batch compilation (ocamlc) 155 8.1 Overview of the compiler . 155 8.2 Options . 156 8.3 Modules and the file system . 164 8.4 Common errors . 164 9 The toplevel system (ocaml) 169 9.1 Options . 170 9.2 Toplevel directives . 172 9.3 The toplevel and the module system . 174 9.4 Common errors . 174 9.5 Building custom toplevel systems: ocamlmktop . 175 9.6 Options . 175 10 The runtime system (ocamlrun) 177 10.1 Overview . 177 10.2 Options . 178 10.3 Dynamic loading of shared libraries . 180 10.4 Common errors . 180 11 Native-code compilation (ocamlopt) 183 11.1 Overview of the compiler . 183 11.2 Options . 184 11.3 Common errors . 192 11.4 Running executables produced by ocamlopt . 192 11.5 Compatibility with the bytecode compiler . 193 12 Lexer and parser generators (ocamllex, ocamlyacc) 195 12.1 Overview of ocamllex ..................................195 12.2 Syntax of lexer definitions . 196 12.3 Overview of ocamlyacc ..................................200 12.4 Syntax of grammar definitions . ..

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    556 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us