OCaml Cookbook Recipes

The OCaml Cookbook is a place where OCaml developers share how to solve common tasks using packages from the ecosystem.

A task is something that needs to be done inside a project. A recipe is a code sample and explanations on how to perform a task using a combination of open source libraries. Some tasks can be performed using different combination of libraries, each is a different recipe. Tasks don't describe how to use the standard library or language features.

OCaml developers are warmly invited to contribute categories, tasks, and recipes. See the Cookbook section of the CONTRIBUTING.md file in our GitHub repo.

The OCaml guides are recommend reading, for instance recipes handle errors as described in the Error Handling guide.

Command Line

Task
Opam Packages Used
Parse Command Line Arguments

This task has no recipes yet, maybe you want to contribute a recipe!

Using the ANSI Terminal

This task has no recipes yet, maybe you want to contribute a recipe!

Compilation & Linking

Task
Opam Packages Used
Compile and Link to a Bundled C Library

This task has no recipes yet, maybe you want to contribute a recipe!

Generate OCaml Bindings for a C Library

This task has no recipes yet, maybe you want to contribute a recipe!

Concurrency & Parallelism

Parallelism & Multi-Threading

Task
Opam Packages Used
Spawn a Thread and Receive a Response

This task has no recipes yet, maybe you want to contribute a recipe!

Pass Data Between Parallel Threads

This task has no recipes yet, maybe you want to contribute a recipe!

Single-Threaded Concurrency

Task
Opam Packages Used
Create and Await Promises

This task has no recipes yet, maybe you want to contribute a recipe!

Data Structures & Algorithms

Hash Tables

Task
Opam Packages Used
Use a Hash Table With Given Key and Value Types

This task has no recipes yet, maybe you want to contribute a recipe!

Database

PostgreSQL

Task
Opam Packages Used
PostgreSQL CREATE, INSERT, SELECT

This task has no recipes yet, maybe you want to contribute a recipe!

PostgreSQL Aggregate Query

This task has no recipes yet, maybe you want to contribute a recipe!

PostgreSQL Full Text Search

This task has no recipes yet, maybe you want to contribute a recipe!

Date and Time

Task
Opam Packages Used
Measure Elapsed Time

This task has no recipes yet, maybe you want to contribute a recipe!

Convert a Local Time to Another Time Zone

This task has no recipes yet, maybe you want to contribute a recipe!

Convert Between Date and Unix Timestamp

This task has no recipes yet, maybe you want to contribute a recipe!

Display Formatted Date and Time

This task has no recipes yet, maybe you want to contribute a recipe!

Parse Date and Time from String

This task has no recipes yet, maybe you want to contribute a recipe!

Debugging

Task
Opam Packages Used
Debug Print a Value

This task has no recipes yet, maybe you want to contribute a recipe!

Log a Debug / Error Message to Stdout / Stderr

This task has no recipes yet, maybe you want to contribute a recipe!

Log to the Unix Syslog

This task has no recipes yet, maybe you want to contribute a recipe!

Encoding

Task
Opam Packages Used
URL- / Percent-Encode a String

This task has no recipes yet, maybe you want to contribute a recipe!

Encode a String as application/x-www-form-urlencoded

This task has no recipes yet, maybe you want to contribute a recipe!

Encode and Decode Bytestrings From Hex-Strings

This task has no recipes yet, maybe you want to contribute a recipe!

Encode and Decode Base64

This task has no recipes yet, maybe you want to contribute a recipe!

Read and Write Integers in Little-Endian Byte Order

This task has no recipes yet, maybe you want to contribute a recipe!

File System

Task
Opam Packages Used
File Size

This task has no recipes yet, maybe you want to contribute a recipe!

Change File Permissions

This task has no recipes yet, maybe you want to contribute a recipe!

Walk File Tree

This task has no recipes yet, maybe you want to contribute a recipe!

Find Files Matching a Pattern

This task has no recipes yet, maybe you want to contribute a recipe!

Mathematics

Geographical Calculations

Task
Opam Packages Used
Calculate Geodistance Between Two Points

This task has no recipes yet, maybe you want to contribute a recipe!

Vector & Matrix Operations

Task
Opam Packages Used
Matrix Addition and Multiplication

This task has no recipes yet, maybe you want to contribute a recipe!

Invert a Matrix

This task has no recipes yet, maybe you want to contribute a recipe!

Nearest-Neighbour Search

This task has no recipes yet, maybe you want to contribute a recipe!

Graphical User Interfaces

There's nothing in this category yet.

Text Processing

Regular Expressions

Task
Opam Packages Used

UTF-8

Task
Opam Packages Used
UTF-8 Text Processing

This task has no recipes yet, maybe you want to contribute a recipe!

Unicode

Task
Opam Packages Used
Collect Unicode Graphemes

This task has no recipes yet, maybe you want to contribute a recipe!

Web Programming

Media Types (MIME)

Task
Opam Packages Used
Get MIME Type From String

This task has no recipes yet, maybe you want to contribute a recipe!

Get MIME Type From Filename

This task has no recipes yet, maybe you want to contribute a recipe!

Parse MIME Type of an HTTP Response

This task has no recipes yet, maybe you want to contribute a recipe!

Running a Web Server

Task
Opam Packages Used
Start a Web Server With a 'Hello World' Endpoint

This task has no recipes yet, maybe you want to contribute a recipe!

Start a Web Server That Serves an HTML Template

This task has no recipes yet, maybe you want to contribute a recipe!

Use Basic Authentication to Secure a Route

This task has no recipes yet, maybe you want to contribute a recipe!

Dealing With HTML

Task
Opam Packages Used
Render an HTML Template

This task has no recipes yet, maybe you want to contribute a recipe!

Extract All Links From an HTML String

This task has no recipes yet, maybe you want to contribute a recipe!

Check a Webpage for Broken Links

This task has no recipes yet, maybe you want to contribute a recipe!

HTTP Clients

Task
Opam Packages Used
Make a HTTP GET Request

This task has no recipes yet, maybe you want to contribute a recipe!

Make a HTTP GET Request With Basic Authentication

This task has no recipes yet, maybe you want to contribute a recipe!

Download a File to a Temporary Directory

This task has no recipes yet, maybe you want to contribute a recipe!

Make a Partial Download With HTTP Range Header

This task has no recipes yet, maybe you want to contribute a recipe!

OCaml

Innovation. Community. Security.