Synopses & Reviews
This fast-moving tutorial introduces you to OCaml, an industrial-strength programming language designed for expressiveness, safety, and speed. Through the books many examples, youll quickly learn how OCaml stands out as a tool for writing fast, succinct, and readable systems code.
Real World OCaml takes you through the concepts of the language at a brisk pace, and then helps you explore the tools and techniques that make OCaml an effective and practical tool. In the books third section, youll delve deep into the details of the compiler toolchain and OCamls simple and efficient runtime system.
- Learn the foundations of the language, such as higher-order functions, algebraic data types, and modules
- Explore advanced features such as functors, first-class modules, and objects
- Leverage Core, a comprehensive general-purpose standard library for OCaml
- Design effective and reusable libraries, making the most of OCamls approach to abstraction and modularity
- Tackle practical programming problems from command-line parsing to asynchronous network programming
- Examine profiling and interactive debugging techniques with tools such as GNU gdb
Synopsis
Learn how to solve day-to-day problems in data processing, numerical computation, system scripting, and database-driven web applications with the OCaml multi-paradigm programming language. This hands-on book shows you how to take advantage of OCamls functional, imperative, and object-oriented programming styles with recipes for many real-world tasks.
Youll start with OCaml basics, including how to set up a development environment, and move toward more advanced topics such as the module system, foreign-function interface, macro language, and the ocamlbuild system. Quickly learn how to put OCaml to work for writing succinct and readable code.
About the Author
Yaron Minsky heads the Technology group at Jane Street, a proprietary trading firm that is the largest industrial user of OCaml. He was responsible for introducing OCaml to the company and for managing the company's transition to using OCaml for all of its core infrastructure. Today, billions of dollars worth of securities transactions flow each day through those systems. Yaron obtained his PhD in Computer Science from Cornell University, where he studied distributed systems. Yaron has lectured, blogged and written about OCaml for years, with articles published in Communications of the ACM and the Journal of Functional Programming. He chairs the steering committee of the Commercial Users of Functional Programming, and is a member of the steering committee for the International Conference on Functional Programming.
Anil Madhavapeddy is a Senior Research Fellow at the University of Cambridge, based in the Systems Research Group. He was on the original team that developed the Xen hypervisor, and helped develop an industry-leading cloud management toolstack written entirely in OCaml. This XenServer product has been deployed on hundreds of thousands of physical hosts, and drives critical infrastructure for many Fortune 500 companies. Prior to obtaining his PhD in 2006 from the University of Cambridge, Anil had a diverse background in industry at Network Appliance, NASA and Internet Vision. In addition to professional and academic activities, he is an active member of the open-source development community with the OpenBSD operating system, is co-chair of the Commercial Uses of Functional Programmingworkshop, and serves on the boards of startup companies such as Ashima Arts where OCaml is extensively used.
Jason Hickey is a Software Engineer at Google Inc. in Mountain View, California. He is part of the team that designs and develops the global computing infrastructure used to support Google services, including the software systems for managing and scheduling massively distributed computing resources. Prior to joining Google, Jason was an Assistant Professor of Computer Science at Caltech, where his research was in reliable and fault-tolerant computing systems, including programming language design, formal methods, compilers, and new models of distributed computation. He obtained his PhD in Computer Science from Cornell University, where he studied programming languages. He is the author of the MetaPRL system, a logical framework for design and analysis of large software systems; OMake, an advanced build system for large software projects. He is the author of the textbook, An Introduction to Objective Caml (unpublished).
Table of Contents
Dedication; Prologue; Why OCaml?; About This Book; Safari® Books Online; How to Contact Us; Contributors; Language Concepts; Chapter 1: A Guided Tour; 1.1 OCaml as a Calculator; 1.2 Functions and Type Inference; 1.3 Tuples, Lists, Options, and Pattern Matching; 1.4 Records and Variants; 1.5 Imperative Programming; 1.6 A Complete Program; 1.7 Where to Go from Here; Chapter 2: Variables and Functions; 2.1 Variables; 2.2 Functions; Chapter 3: Lists and Patterns; 3.1 List Basics; 3.2 Using Patterns to Extract Data from a List; 3.3 Limitations (and Blessings) of Pattern Matching; 3.4 Using the List Module Effectively; 3.5 Tail Recursion; 3.6 Terser and Faster Patterns; Chapter 4: Files, Modules, and Programs; 4.1 Single-File Programs; 4.2 Multifile Programs and Modules; 4.3 Signatures and Abstract Types; 4.4 Concrete Types in Signatures; 4.5 Nested Modules; 4.6 Opening Modules; 4.7 Including Modules; 4.8 Common Errors with Modules; 4.9 Designing with Modules; Chapter 5: Records; 5.1 Patterns and Exhaustiveness; 5.2 Field Punning; 5.3 Reusing Field Names; 5.4 Functional Updates; 5.5 Mutable Fields; 5.6 First-Class Fields; Chapter 6: Variants; 6.1 Catch-All Cases and Refactoring; 6.2 Combining Records and Variants; 6.3 Variants and Recursive Data Structures; 6.4 Polymorphic Variants; Chapter 7: Error Handling; 7.1 Error-Aware Return Types; 7.2 Exceptions; 7.3 Choosing an Error-Handling Strategy; Chapter 8: Imperative Programming; 8.1 Example: Imperative Dictionaries; 8.2 Primitive Mutable Data; 8.3 for and while Loops; 8.4 Example: Doubly Linked Lists; 8.5 Laziness and Other Benign Effects; 8.6 Input and Output; 8.7 Order of Evaluation; 8.8 Side Effects and Weak Polymorphism; 8.9 Summary; Chapter 9: Functors; 9.1 A Trivial Example; 9.2 A Bigger Example: Computing with Intervals; 9.3 Extending Modules; Chapter 10: First-Class Modules; 10.1 Working with First-Class Modules; 10.2 Example: A Query-Handling Framework; 10.3 Living Without First-Class Modules; Chapter 11: Objects; 11.1 OCaml Objects; 11.2 Object Polymorphism; 11.3 Immutable Objects; 11.4 When to Use Objects; 11.5 Subtyping; Chapter 12: Classes; 12.1 OCaml Classes; 12.2 Class Parameters and Polymorphism; 12.3 Object Types as Interfaces; 12.4 Inheritance; 12.5 Class Types; 12.6 Open Recursion; 12.7 Private Methods; 12.8 Binary Methods; 12.9 Virtual Classes and Methods; 12.10 Initializers; 12.11 Multiple Inheritance; Tools and Techniques; Chapter 13: Maps and Hash Tables; 13.1 Maps; 13.2 Hash Tables; 13.3 Choosing Between Maps and Hash Tables; Chapter 14: Command-Line Parsing; 14.1 Basic Command-Line Parsing; 14.2 Argument Types; 14.3 Adding Labeled Flags to the Command Line; 14.4 Grouping Subcommands Together; 14.5 Advanced Control over Parsing; 14.6 Command-Line Autocompletion with bash; 14.7 Alternative Command-Line Parsers; Chapter 15: Handling JSON Data; 15.1 JSON Basics; 15.2 Parsing JSON with Yojson; 15.3 Selecting Values from JSON Structures; 15.4 Constructing JSON Values; 15.5 Using Nonstandard JSON Extensions; 15.6 Automatically Mapping JSON to OCaml Types; Chapter 16: Parsing with OCamllex and Menhir; 16.1 Lexing and Parsing; 16.2 Defining a Parser; 16.3 Defining a Lexer; 16.4 Bringing It All Together; Chapter 17: Data Serialization with S-Expressions; 17.1 Basic Usage; 17.2 The Sexp Format; 17.3 Preserving Invariants; 17.4 Getting Good Error Messages; 17.5 Sexp-Conversion Directives; Chapter 18: Concurrent Programming with Async; 18.1 Async Basics; 18.2 Examples: An Echo Server; 18.3 Example: Searching Definitions with DuckDuckGo; 18.4 Exception Handling; 18.5 Timeouts, Cancellation, and Choices; 18.6 Working with System Threads; The Runtime System; Chapter 19: Foreign Function Interface; 19.1 Example: A Terminal Interface; 19.2 Basic Scalar C Types; 19.3 Pointers and Arrays; 19.4 Structs and Unions; 19.5 Passing Functions to C; 19.6 Learning More About C Bindings; Chapter 20: Memory Representation of Values; 20.1 OCaml Blocks and Values; 20.2 Blocks and Values; 20.3 Tuples, Records, and Arrays; 20.4 Variants and Lists; 20.5 Polymorphic Variants; 20.6 String Values; 20.7 Custom Heap Blocks; Chapter 21: Understanding the Garbage Collector; 21.1 Mark and Sweep Garbage Collection; 21.2 Generational Garbage Collection; 21.3 The Fast Minor Heap; 21.4 The Long-Lived Major Heap; 21.5 Attaching Finalizer Functions to Values; Chapter 22: The Compiler Frontend: Parsing and Type Checking; 22.1 An Overview of the Toolchain; 22.2 Parsing Source Code; 22.3 Preprocessing Source Code; 22.4 Static Type Checking; 22.5 The Typed Syntax Tree; Chapter 23: The Compiler Backend: Bytecode and Native code; 23.1 The Untyped Lambda Form; 23.2 Generating Portable Bytecode; 23.3 Compiling Fast Native Code; 23.4 Summarizing the File Extensions; Colophon;