Real World OCaml: Functional programming for the masses
Yaron Minsky, Anil Madhavapeddy, Jason Hickey
Format: PDF / Kindle (mobi) / ePub
This fast-moving tutorial introduces you to OCaml, an industrial-strength programming language designed for expressiveness, safety, and speed. Through the book’s many examples, you’ll 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 book’s third section, you’ll delve deep into the details of the compiler toolchain and OCaml’s 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 OCaml’s 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
The callback function is a little more complex now, to handle the extra options. The files are now a string list, and an empty list reverts to using standard input, just as our previous maybe and maybe_with_default examples did. If the list of files isn’t empty, then it opens up each file and runs them through do_hash sequentially. Adding Labeled Flags to the Command Line You aren’t just limited to anonymous arguments on the command line. A flag is a named field that can be followed by
Extensions, Camlp4, and Type_conv OCaml doesn’t directly support generating code from type definitions. Instead, it supplies a powerful syntax extension mechanism known as Camlp4, which lets you extend the grammar of the language. Camlp4 is well integrated into the OCaml toolchain and can be activated within the toplevel and also included in compilation using the -pp compiler flag. Sexplib is part of a family of syntax extensions, including Comparelib, described in Chapter 13, and Fieldslib,
~uppercase ~port) |> Command.run Note the use of Deferred.never in the run function. As you might guess from the name, Deferred.never returns a deferred that is never determined. In this case, that indicates that the echo server doesn’t ever shut down. The biggest change in the preceding code is the use of Async’s Pipe. A Pipe is an asynchronous communication channel that’s used for connecting different parts of your program. You can think of it as a consumer/producer queue that uses deferreds
units, stored in the cmxa and a files respectively. These files are always needed together. .S or .s Assembly language output if -S is specified. Index A note on the digital index A link in an index entry is displayed as the section title in which that entry appears. Because some sections have multiple index markers, it is not unusual for an entry to have several links to the same section. Clicking on any link will take you directly to the place in the text in which the marker
explicitly, then users can depend on any and every detail of the types you choose. If they’re abstract, then only the specific operations you want to expose are available. This means that you can freely change the implementation without affecting clients, as long as you preserve the semantics of those operations. In a similar way, abstraction allows you to enforce invariants on your types. If your types are exposed, then users of the module can create new instances of that type (or if mutable,