目录
第一部分 OCaml 简介
第 1 章 核心语言
1.1 基础
1.2 数据类型
1.3 函数作为值
1.4 记录与变体
1.4.1 记录与变体消歧义
1.5 命令式特性
1.6 异常
1.7 表达式的符号处理
1.8 美观打印
1.9 独立 OCaml 程序
第 2 章 模块系统
2.1 结构
2.2 签名
2.3 仿函数
2.4 仿函数和类型抽象
2.5 模块和单独编译
第 3 章 OCaml 中的对象
3.1 类与对象
3.2 直接对象
3.3 引用 self
3.4 初始化器
3.5 虚方法
3.6 私有方法
3.7 类接口
3.8 继承
3.9 多继承
3.10 参数化类
3.11 多态方法
3.12 使用强制转换
3.13 函数式对象
3.14 克隆对象
3.15 递归类
3.16 二元方法
3.17 友元
第 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
第 5 章 Polymorphism and its limitations
5.1 Weak polymorphism and mutation
5.1.1 Weakly polymorphic types
5.1.2 The value restriction
5.1.3 The relaxed value restriction
5.1.4 Variance and value restriction
5.1.5 Abstract data types
5.2 Polymorphic recursion
5.2.1 Explicitly polymorphic annotations
5.2.2 More examples
5.3 Higher-rank polymorphic functions
第 6 章 Advanced examples with classes and modules
6.1 Extended example: bank accounts
6.2 Simple modules as classes
6.2.1 Strings
6.2.2 Hashtbl
6.2.3 Sets
6.3 The subject/observer pattern
第二部分 OCaml 语言
第 7 章 The OCaml language
7.1 Lexical conventions
7.2 Values
7.2.1 Base values
7.2.2 Tuples
7.2.3 Records
7.2.4 Arrays
7.2.5 Variant values
7.2.6 Polymorphic variants
7.2.7 Functions
7.2.8 Objects
7.3 Names
7.4 Type expressions
7.5 Constants
7.6 Patterns
7.7 Expressions
7.7.1 Precedence and associativity
7.7.2 Basic expressions
7.7.3 Control structures
7.7.4 Operations on data structures
7.7.5 Operators
7.7.6 Objects
7.7.7 Coercions
7.7.8 Other
7.8 Type and exception definitions
7.8.1 Type definitions
7.8.2 Exception definitions
7.9 Classes
7.9.1 Class types
7.9.2 Class expressions
7.9.3 Class definitions
7.9.4 Class specifications
7.9.5 Class type definitions
7.10 Module types (module specifications)
7.10.1 Simple module types
7.10.2 Signatures
7.10.3 Functor types
7.10.4 The
with
operator
7.11 Module expressions (module implementations)
7.11.1 Simple module expressions
7.11.2 Structures
7.11.3 Functors
7.12 Compilation units
第 8 章 Language extensions
8.1 Recursive definitions of values
8.2 Lazy patterns
8.3 Recursive modules
8.4 Private types
8.4.1 Private variant and record types
8.4.2 Private type abbreviations
8.4.3 Private row types
8.5 Local opens for patterns
8.6 Object copy short notations
8.7 Locally abstract types
8.8 First-class modules
8.9 Recovering the type of a module
8.10 Substituting inside a signature
8.11 Type-level module aliases
8.12 Overriding in open statements
8.13 Generalized algebraic datatypes
8.14 Syntax for Bigarray access
8.15 Attributes
8.15.1 Built-in attributes
8.16 Extension nodes
8.16.1 Built-in extension nodes
8.17 Extensible variant types
8.17.1 Private extensible variant types
8.18 Generative functors
8.19 Extension-only syntax
8.19.1 Extension operators
8.19.2 Extension literals
8.20 Inline records
8.21 Documentation comments
8.21.1 Floating comments
8.21.2 Item comments
8.21.3 Label comments
8.22 Extended indexing operators
8.23 Empty variant types
第三部分 OCaml 工具
第 9 章 Batch compilation (ocamlc)
9.1 Overview of the compiler
9.2 Options
9.3 Modules and the file system
9.4 Common errors
9.5 Warning reference
9.5.1 Warning 9: missing fields in a record pattern
9.5.2 Warning 52: fragile constant pattern
9.5.3 Warning 57: Ambiguous or-pattern variables under guard
第 10 章 The toplevel system or REPL (ocaml)
10.1 Options
10.2 Toplevel directives
10.3 The toplevel and the module system
10.4 Common errors
10.5 Building custom toplevel systems:
ocamlmktop
10.5.1 Options
10.6 The native toplevel:
ocamlnat
(experimental)
第 11 章 The runtime system (ocamlrun)
11.1 Overview
11.2 Options
11.3 Dynamic loading of shared libraries
11.4 Common errors
第 12 章 Native-code compilation (ocamlopt)
12.1 Overview of the compiler
12.2 Options
12.3 Common errors
12.4 Running executables produced by ocamlopt
12.5 Compatibility with the bytecode compiler
第 13 章 Lexer and parser generators (ocamllex, ocamlyacc)
13.1 Overview of
ocamllex
13.1.1 Options
13.2 Syntax of lexer definitions
13.2.1 Header and trailer
13.2.2 Naming regular expressions
13.2.3 Entry points
13.2.4 Regular expressions
13.2.5 Actions
13.2.6 Variables in regular expressions
13.2.7 Refill handlers
13.2.8 Reserved identifiers
13.3 Overview of
ocamlyacc
13.4 Syntax of grammar definitions
13.4.1 Header and trailer
13.4.2 Declarations
13.4.3 Rules
13.4.4 Error handling
13.5 Options
13.6 A complete example
13.7 Common errors
第 14 章 Dependency generator (ocamldep)
14.1 Options
14.2 A typical Makefile
第 15 章 The browser/editor (ocamlbrowser)
第 16 章 The documentation generator (ocamldoc)
16.1 Usage
16.1.1 Invocation
16.1.2 Merging of module information
16.1.3 Coding rules
16.2 Syntax of documentation comments
16.2.1 Placement of documentation comments
16.2.2 The Stop special comment
16.2.3 Syntax of documentation comments
16.2.4 Text formatting
16.2.5 Documentation tags (@-tags)
16.3 Custom generators
16.3.1 The generator modules
16.3.2 Handling custom tags
16.4 Adding command line options
16.4.1 Compilation and usage
第 17 章 The debugger (ocamldebug)
17.1 Compiling for debugging
17.2 Invocation
17.2.1 Starting the debugger
17.2.2 Initialization file
17.2.3 Exiting the debugger
17.3 Commands
17.3.1 Getting help
17.3.2 Accessing the debugger state
17.4 Executing a program
17.4.1 Events
17.4.2 Starting the debugged program
17.4.3 Running the program
17.4.4 Time travel
17.4.5 Killing the program
17.5 Breakpoints
17.6 The call stack
17.7 Examining variable values
17.8 Controlling the debugger
17.8.1 Setting the program name and arguments
17.8.2 How programs are loaded
17.8.3 Search path for files
17.8.4 Working directory
17.8.5 Turning reverse execution on and off
17.8.6 Communication between the debugger and the program
17.8.7 Fine-tuning the debugger
17.8.8 User-defined printers
17.9 Miscellaneous commands
17.10 Running the debugger under Emacs
第 18 章 Profiling (ocamlprof)
18.1 Compiling for profiling
18.2 Profiling an execution
18.3 Printing profiling information
18.4 Time profiling
第 19 章 The ocamlbuild compilation manager
第 20 章 Interfacing C with OCaml
20.1 Overview and compilation information
20.1.1 Declaring primitives
20.1.2 Implementing primitives
20.1.3 Statically linking C code with OCaml code
20.1.4 Dynamically linking C code with OCaml code
20.1.5 Choosing between static linking and dynamic linking
20.1.6 Building standalone custom runtime systems
20.2 The
value
type
20.2.1 Integer values
20.2.2 Blocks
20.2.3 Pointers outside the heap
20.3 Representation of OCaml data types
20.3.1 Atomic types
20.3.2 Tuples and records
20.3.3 Arrays
20.3.4 Concrete data types
20.3.5 Objects
20.3.6 Polymorphic variants
20.4 Operations on values
20.4.1 Kind tests
20.4.2 Operations on integers
20.4.3 Accessing blocks
20.4.4 Allocating blocks
20.4.5 Raising exceptions
20.5 Living in harmony with the garbage collector
20.5.1 Simple interface
20.5.2 Low-level interface
20.6 A complete example
20.7 Advanced topic: callbacks from C to OCaml
20.7.1 Applying OCaml closures from C
20.7.2 Obtaining or registering OCaml closures for use in C functions
20.7.3 Registering OCaml exceptions for use in C functions
20.7.4 Main program in C
20.7.5 Embedding the OCaml code in the C code
20.8 Advanced example with callbacks
20.9 Advanced topic: custom blocks
20.9.1 The
struct custom_operations
20.9.2 Allocating custom blocks
20.9.3 Accessing custom blocks
20.9.4 Writing custom serialization and deserialization functions
20.9.5 Choosing identifiers
20.9.6 Finalized blocks
20.10 Advanced topic: Big arrays and the OCaml-C interface
20.10.1 Include file
20.10.2 Accessing an OCaml bigarray from C or Fortran
20.10.3 Wrapping a C or Fortran array as an OCaml big array
20.11 Advanced topic: cheaper C call
20.11.1 Passing unboxed values
20.11.2 Direct C call
20.11.3 Example: calling C library functions without indirection
20.12 Advanced topic: multithreading
20.12.1 Registering threads created from C
20.12.2 Parallel execution of long-running C code
20.13 Advanced topic: interfacing with Windows Unicode APIs
20.14 Building mixed C/OCaml libraries:
ocamlmklib
第 21 章 Optimisation with Flambda
21.1 Overview
21.2 Command-line flags
21.2.1 Specification of optimisation parameters by round
21.3 Inlining
21.3.1 Classic inlining heuristic
21.3.2 Overview of “Flambda” inlining heuristics
21.3.3 Handling of specific language constructs
21.3.4 Inlining reports
21.3.5 Assessment of inlining benefit
21.3.6 Control of speculation
21.4 Specialisation
21.4.1 Assessment of specialisation benefit
21.5 Default settings of parameters
21.5.1 Settings at -O2 optimisation level
21.5.2 Settings at -O3 optimisation level
21.6 Manual control of inlining and specialisation
21.7 Simplification
21.8 Other code motion transformations
21.8.1 Lifting of constants
21.8.2 Lifting of toplevel let bindings
21.9 Unboxing transformations
21.9.1 Unboxing of closure variables
21.9.2 Unboxing of specialised arguments
21.9.3 Unboxing of closures
21.10 Removal of unused code and values
21.10.1 Removal of redundant let expressions
21.10.2 Removal of redundant program constructs
21.10.3 Removal of unused arguments
21.10.4 Removal of unused closure variables
21.11 Other code transformations
21.11.1 Transformation of non-escaping references into mutable variables
21.11.2 Substitution of closure variables for specialised arguments
21.12 Treatment of effects
21.13 Compilation of statically-allocated modules
21.14 Inhibition of optimisation
21.15 Use of unsafe operations
21.16 Glossary
第 22 章 Memory profiling with Spacetime
22.1 Overview
22.2 How to use it
22.2.1 Building
22.2.2 Running
22.2.3 Analysis
22.3 Runtime overhead
22.4 For developers
第 23 章 Fuzzing with afl-fuzz
23.1 Overview
23.2 Generating instrumentation
23.2.1 Advanced options
23.3 Example
第 24 章 Compiler plugins
24.1 Overview
24.2 Basic example
第四部分 OCaml 库
第 25 章 The core library
25.1 Built-in types and predefined exceptions
25.2 Module
Stdlib
: the initially opened module
第 26 章 The standard library
第 27 章 The compiler front-end
第 28 章 The unix library: Unix system calls
第 29 章 The num library: arbitrary-precision rational arithmetic
第 30 章 The str library: regular expressions and string processing
第 31 章 The threads library
第 32 章 The graphics library
第 33 章 The dynlink library: dynamic loading and linking of object files
第 34 章 The bigarray library
第五部分 附录