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!

Compression

Task
Opam Packages Used
Read a gzip compressed text file

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

Decompressing a Tarball

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

Compress a Directory Into a Tarball

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!

Cryptography

Task
Opam Packages Used
Calculate the SHA-256 Digest of a File

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

Sign and Verify a Message with an HMAC Digest

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

Salt and Hash a Password with PBKDF2

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!

Sorting

Task
Opam Packages Used
Sorting Lists and Arrays

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!

SQLite

Task
Opam Packages Used
SQLite CREATE, INSERT, SELECT

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

SQLite Full Text Search

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

Data Formats

JSON

Task
Opam Packages Used
Serialise JSON Data

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

Deserialise JSON Data

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

CSV

Task
Opam Packages Used
Read Tuples / Records from CSV

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

Serialise Tuples / Records to CSV

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

File Paths

There's nothing in this category yet.

Directories

Task
Opam Packages Used
Create Directory

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

List Directory Contents

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

Get Current Directory

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

Change Current Directory

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!

Walk File Tree

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

Files

Task
Opam Packages Used
Open File

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

Write to a File

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

Rename a File

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

Delete a File

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

Check if a File Exists

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

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!

Create Temporary File

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
Normalize a Vector

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

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!

Operating System

Task
Opam Packages Used
Run an External Command and Process Stdout

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

Run Piped External Commands

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

Read an Environment Variable

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
Validate an Email Address

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

Extract Phone Numbers from Text

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

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

URL and URI processing

Task
Opam Packages Used
Parse a URL from String And Access Individual Parts

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

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 a 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 a 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 a HTML Template

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

Extract all Links from a 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!