Contents
Part I An introduction to OCaml
Chapter 1 The core language
1.1 Basics
1.2 Data types
1.3 Functions as values
1.4 Records and variants
1.5 Imperative features
1.6 Exceptions
1.7 Symbolic processing of expressions
1.8 Pretty-printing and parsing
1.9 Standalone OCaml programs
Chapter 2 The module system
2.1 Structures
2.2 Signatures
2.3 Functors
2.4 Functors and type abstraction
2.5 Modules and separate compilation
Chapter 3 Objects in OCaml
3.1 Classes and objects
3.2 Immediate objects
3.3 Reference to self
3.4 Initializers
3.5 Virtual methods
3.6 Private methods
3.7 Class interfaces
3.8 Inheritance
3.9 Multiple inheritance
3.10 Parameterized classes
3.11 Polymorphic methods
3.12 Using coercions
3.13 Functional objects
3.14 Cloning objects
3.15 Recursive classes
3.16 Binary methods
3.17 Friends
Chapter 4 Labels and variants
4.1 Labels
4.1.1 Optional arguments
4.1.2 Labels and type inference
4.1.3 Suggestions for labeling
4.2 Polymorphic variants
4.2.1 Weaknesses of polymorphic variants
Chapter 5 Advanced examples with classes and modules
5.1 Extended example: bank accounts
5.2 Simple modules as classes
5.2.1 Strings
5.2.2 Hashtbl
5.2.3 Sets
5.3 The subject/observer pattern
Part II The OCaml language
Chapter 6 The OCaml language
6.1 Lexical conventions
6.2 Values
6.2.1 Base values
6.2.2 Tuples
6.2.3 Records
6.2.4 Arrays
6.2.5 Variant values
6.2.6 Polymorphic variants
6.2.7 Functions
6.2.8 Objects
6.3 Names
6.4 Type expressions
6.5 Constants
6.6 Patterns
6.7 Expressions
6.7.1 Basic expressions
6.7.2 Control structures
6.7.3 Operations on data structures
6.7.4 Operators
6.7.5 Objects
6.7.6 Coercions
6.8 Type and exception definitions
6.8.1 Type definitions
6.8.2 Exception definitions
6.9 Classes
6.9.1 Class types
6.9.2 Class expressions
6.9.3 Class definitions
6.9.4 Class specifications
6.9.5 Class type definitions
6.10 Module types (module specifications)
6.10.1 Simple module types
6.10.2 Signatures
6.10.3 Functor types
6.10.4 The
with
operator
6.11 Module expressions (module implementations)
6.11.1 Simple module expressions
6.11.2 Structures
6.11.3 Functors
6.12 Compilation units
Chapter 7 Language extensions
7.1 Integer literals for types
int32
,
int64
and
nativeint
7.2 Streams and stream parsers
7.3 Recursive definitions of values
7.4 Range patterns
7.5 Assertion checking
7.6 Lazy evaluation
7.6.1 Lazy expressions
7.6.2 Lazy patterns
7.7 Local modules
7.8 Recursive modules
7.9 Private types
7.9.1 Private variant and record types
7.9.2 Private type abbreviations
7.9.3 Private row types
7.10 Local opens
7.11 Record notations
7.12 Explicit polymorphic type annotations
7.13 Locally abstract types
7.14 First-class modules
7.15 Recovering the type of a module
7.16 Substituting inside a signature
7.17 Explicit overriding in class definitions
7.18 Overriding in open statements
7.19 Generalized algebraic datatypes
7.20 Syntax for Bigarray access
Part III The OCaml tools
Chapter 8 Batch compilation (ocamlc)
8.1 Overview of the compiler
8.2 Options
8.3 Modules and the file system
8.4 Common errors
Chapter 9 The toplevel system (ocaml)
9.1 Options
9.2 Toplevel directives
9.3 The toplevel and the module system
9.4 Common errors
9.5 Building custom toplevel systems:
ocamlmktop
9.6 Options
Chapter 10 The runtime system (ocamlrun)
10.1 Overview
10.2 Options
10.3 Dynamic loading of shared libraries
10.4 Common errors
Chapter 11 Native-code compilation (ocamlopt)
11.1 Overview of the compiler
11.2 Options
11.3 Common errors
11.4 Running executables produced by ocamlopt
11.5 Compatibility with the bytecode compiler
Chapter 12 Lexer and parser generators (ocamllex, ocamlyacc)
12.1 Overview of
ocamllex
12.1.1 Options
12.2 Syntax of lexer definitions
12.2.1 Header and trailer
12.2.2 Naming regular expressions
12.2.3 Entry points
12.2.4 Regular expressions
12.2.5 Actions
12.2.6 Variables in regular expressions
12.2.7 Reserved identifiers
12.3 Overview of
ocamlyacc
12.4 Syntax of grammar definitions
12.4.1 Header and trailer
12.4.2 Declarations
12.4.3 Rules
12.4.4 Error handling
12.5 Options
12.6 A complete example
12.7 Common errors
Chapter 13 Dependency generator (ocamldep)
13.1 Options
13.2 A typical Makefile
Chapter 14 The browser/editor (ocamlbrowser)
14.1 Invocation
14.2 Viewer
14.3 Module browsing
14.4 File editor
14.5 Shell
Chapter 15 The documentation generator (ocamldoc)
15.1 Usage
15.1.1 Invocation
15.1.2 Merging of module information
15.1.3 Coding rules
15.2 Syntax of documentation comments
15.2.1 Placement of documentation comments
15.2.2 The Stop special comment
15.2.3 Syntax of documentation comments
15.2.4 Text formatting
15.2.5 Documentation tags (@-tags)
15.3 Custom generators
15.3.1 The generator modules
15.3.2 Handling custom tags
15.4 Adding command line options
15.4.1 Compilation and usage
Chapter 16 The debugger (ocamldebug)
16.1 Compiling for debugging
16.2 Invocation
16.2.1 Starting the debugger
16.2.2 Exiting the debugger
16.3 Commands
16.3.1 Getting help
16.3.2 Accessing the debugger state
16.4 Executing a program
16.4.1 Events
16.4.2 Starting the debugged program
16.4.3 Running the program
16.4.4 Time travel
16.4.5 Killing the program
16.5 Breakpoints
16.6 The call stack
16.7 Examining variable values
16.8 Controlling the debugger
16.8.1 Setting the program name and arguments
16.8.2 How programs are loaded
16.8.3 Search path for files
16.8.4 Working directory
16.8.5 Turning reverse execution on and off
16.8.6 Communication between the debugger and the program
16.8.7 Fine-tuning the debugger
16.8.8 User-defined printers
16.9 Miscellaneous commands
16.10 Running the debugger under Emacs
Chapter 17 Profiling (ocamlprof)
17.1 Compiling for profiling
17.2 Profiling an execution
17.3 Printing profiling information
17.4 Time profiling
Chapter 18 The ocamlbuild compilation manager
18.1 Features of
ocamlbuild
18.2 Limitations
18.3 Using
ocamlbuild
18.3.1 Hygiene & where is my code ?
18.3.2 Hello, world !
18.3.3 Executing my code
18.3.4 The log file, verbosity and debugging
18.3.5 Cleaning
18.3.6 Where and how to run
ocamlbuild
?
18.3.7 Dependencies
18.3.8 Native and byte-code
18.3.9 Compile flags
18.3.10 Link flags
18.3.11 Linking with external libraries
18.3.12 The
_tags
files
18.3.13 Glob patterns and expressions
18.3.14 Subdirectories
18.3.15 Grouping targets with
.itarget
18.3.16 Packing subdirectories into modules
18.3.17 Making an OCaml library
18.3.18 Making an OCaml toplevel
18.3.19 Preprocessor options and tags
18.3.20 Debugging byte code and profiling native code
18.3.21 Generating documentation using
ocamldoc
18.3.22 The display line
18.3.23
ocamllex
,
ocamlyacc
and
menhir
18.3.24 Changing the compilers or tools
18.3.25 Interaction with version control systems
18.3.26 A shell script for driving it all?
18.4 Appendix: Motivations
18.5 Appendix: Summary of default rules
Chapter 19 Interfacing C with OCaml
19.1 Overview and compilation information
19.1.1 Declaring primitives
19.1.2 Implementing primitives
19.1.3 Statically linking C code with OCaml code
19.1.4 Dynamically linking C code with OCaml code
19.1.5 Choosing between static linking and dynamic linking
19.1.6 Building standalone custom runtime systems
19.2 The
value
type
19.2.1 Integer values
19.2.2 Blocks
19.2.3 Pointers outside the heap
19.3 Representation of OCaml data types
19.3.1 Atomic types
19.3.2 Tuples and records
19.3.3 Arrays
19.3.4 Concrete data types
19.3.5 Objects
19.3.6 Polymorphic variants
19.4 Operations on values
19.4.1 Kind tests
19.4.2 Operations on integers
19.4.3 Accessing blocks
19.4.4 Allocating blocks
19.4.5 Raising exceptions
19.5 Living in harmony with the garbage collector
19.5.1 Simple interface
19.5.2 Low-level interface
19.6 A complete example
19.7 Advanced topic: callbacks from C to OCaml
19.7.1 Applying OCaml closures from C
19.7.2 Obtaining or registering OCaml closures for use in C functions
19.7.3 Registering OCaml exceptions for use in C functions
19.7.4 Main program in C
19.7.5 Embedding the OCaml code in the C code
19.8 Advanced example with callbacks
19.9 Advanced topic: custom blocks
19.9.1 The
struct custom_operations
19.9.2 Allocating custom blocks
19.9.3 Accessing custom blocks
19.9.4 Writing custom serialization and deserialization functions
19.9.5 Choosing identifiers
19.9.6 Finalized blocks
19.10 Advanced topic: multithreading
19.10.1 Registering threads created from C
19.10.2 Parallel execution of long-running C code
19.11 Building mixed C/OCaml libraries:
ocamlmklib
Part IV The OCaml library
Chapter 20 The core library
20.1 Built-in types and predefined exceptions
20.2 Module
Pervasives
: the initially opened module
Chapter 21 The standard library
Chapter 22 The unix library: Unix system calls
Chapter 23 The num library: arbitrary-precision rational arithmetic
Chapter 24 The str library: regular expressions and string processing
Chapter 25 The threads library
Chapter 26 The graphics library
Chapter 27 The dynlink library: dynamic loading and linking of object files
Chapter 28 The LablTk library: Tcl/Tk GUI interface
Chapter 29 The bigarray library
29.1 Module
Bigarray
: large, multi-dimensional, numerical arrays
29.2 Big arrays in the OCaml-C interface
29.2.1 Include file
29.2.2 Accessing an OCaml bigarray from C or Fortran
29.2.3 Wrapping a C or Fortran array as an OCaml big array
Part V Appendix