Loading...

Master OCaml.

OCaml

OCaml mastery exercises. Become your team's resident OCaml expert.

139 exercises
OCaml Challenges

Put your OCaml skills to the test. Practice by building popular open-source tools from scratch.

Build your own Interpreter
Build your own Interpreter

This challenge follows the book Crafting Interpreters by Robert Nystrom.

In this challenge you'll build an interpreter for Lox, a simple scripting language. Along the way, you'll learn about tokenization, ASTs, tree-walk interpreters and more.

Before starting this challenge, make sure you've read the "Welcome" part of the book that contains these chapters:

These chapters don't involve writing code, so they won't be covered in this challenge. This challenge will start from chapter 4, Scanning.

Scanning: Empty file
Login via GitHub to view this stage
Scanning: Parentheses
Login via GitHub to view this stage
Scanning: Braces
Login via GitHub to view this stage
Scanning: Other single-character tokens
Login via GitHub to view this stage
Scanning: Lexical errors
Login via GitHub to view this stage
Scanning: Assignment & equality Operators
Login via GitHub to view this stage
Scanning: Negation & inequality operators
Login via GitHub to view this stage
Scanning: Relational operators
Login via GitHub to view this stage
Scanning: Division operator & comments
Login via GitHub to view this stage
Scanning: Whitespace
Login via GitHub to view this stage
Scanning: Multi-line errors
Login via GitHub to view this stage
Scanning: String literals
Login via GitHub to view this stage
Scanning: Number literals
Login via GitHub to view this stage
Scanning: Identifiers
Login via GitHub to view this stage
Scanning: Reserved words
Login via GitHub to view this stage

Parsing Expressions

Booleans & Nil
Login via GitHub to view this stage
Number literals
Login via GitHub to view this stage
String literals
Login via GitHub to view this stage
Parentheses
Login via GitHub to view this stage
Unary Operators
Login via GitHub to view this stage
Arithmetic operators (1/2)
Login via GitHub to view this stage
Arithmetic operators (2/2)
Login via GitHub to view this stage
Comparison operators
Login via GitHub to view this stage
Equality operators
Login via GitHub to view this stage
Syntactic errors
Login via GitHub to view this stage

Evaluating Expressions

Literals: Booleans & Nil
Login via GitHub to view this stage
Literals: Strings & Numbers
Login via GitHub to view this stage
Parentheses
Login via GitHub to view this stage
Unary Operators: Negation & Not
Login via GitHub to view this stage
Arithmetic Operators (1/2)
Login via GitHub to view this stage
Arithmetic Operators (2/2)
Login via GitHub to view this stage
String Concatenation
Login via GitHub to view this stage
Relational Operators
Login via GitHub to view this stage
Equality Operators
Login via GitHub to view this stage
Runtime Errors: Unary Operators
Login via GitHub to view this stage
Runtime Errors: Binary Operators (1/2)
Login via GitHub to view this stage
Runtime Errors: Binary Operators (2/2)
Login via GitHub to view this stage
Runtime Errors: Relational Operators
Login via GitHub to view this stage

Statements & State

Print: Generate output
Login via GitHub to view this stage
Print: Multiple statements
Login via GitHub to view this stage
Expression statements
Login via GitHub to view this stage
Variables: Declare variables
Login via GitHub to view this stage
Variables: Runtime Errors
Login via GitHub to view this stage
Variables: Initialize variables
Login via GitHub to view this stage
Variables: Redeclare variables
Login via GitHub to view this stage
Assignment operation
Login via GitHub to view this stage
Block syntax
Login via GitHub to view this stage
Scopes
Login via GitHub to view this stage

Control Flow

If statements
Login via GitHub to view this stage
Else statements
Login via GitHub to view this stage
Else-if statements
Login via GitHub to view this stage
Nested if statements
Login via GitHub to view this stage
Logical OR operator
Login via GitHub to view this stage
Logical AND operator
Login via GitHub to view this stage
While statements
Login via GitHub to view this stage
For statements
Login via GitHub to view this stage
Syntactic errors
Login via GitHub to view this stage

Functions

Native functions
Login via GitHub to view this stage
Functions without arguments
Login via GitHub to view this stage
Functions with arguments
Login via GitHub to view this stage
Syntax errors
Login via GitHub to view this stage
Return statements
Login via GitHub to view this stage
Higher order functions
Login via GitHub to view this stage
Runtime errors
Login via GitHub to view this stage
Function scope
Login via GitHub to view this stage
Closures
Login via GitHub to view this stage

Resolving & Binding

Identifier Resolution
Login via GitHub to view this stage
Self Initialization
Login via GitHub to view this stage
Variable Redeclaration
Login via GitHub to view this stage
Invalid Return
Login via GitHub to view this stage

Classes

Class Declarations
Login via GitHub to view this stage
Class Instances
Login via GitHub to view this stage
Getters & Setters
Login via GitHub to view this stage
Instance Methods
Login via GitHub to view this stage
The 'this' keyword
Login via GitHub to view this stage
Invalid usages of 'this'
Login via GitHub to view this stage
Constructor calls
Login via GitHub to view this stage
Return within constructors
Login via GitHub to view this stage

Inheritance

Class Hierarchy
Login via GitHub to view this stage
Inheriting Methods
Login via GitHub to view this stage
Overriding Methods
Login via GitHub to view this stage
Inheritance errrors
Login via GitHub to view this stage
The super keyword
Login via GitHub to view this stage
Invalid Usages of the super Keyword
Login via GitHub to view this stage
Build your own Redis
Build your own Redis

Discover concurrent programming in OCaml while also learning about TCP servers, network programming, and the Redis Protocol.

Bind to a port
Login via GitHub to view this stage
Respond to PING
Login via GitHub to view this stage
Respond to multiple PINGs
Login via GitHub to view this stage
Handle concurrent clients
Login via GitHub to view this stage
Implement the ECHO command
Login via GitHub to view this stage
Implement the SET & GET commands
Login via GitHub to view this stage
Expiry
Login via GitHub to view this stage

RDB Persistence

RDB file config
Login via GitHub to view this stage
Read a key
Login via GitHub to view this stage
Read a string value
Login via GitHub to view this stage
Read multiple keys
Login via GitHub to view this stage
Read multiple string values
Login via GitHub to view this stage
Read value with expiry
Login via GitHub to view this stage

Replication

Configure listening port
Login via GitHub to view this stage
The INFO command
Login via GitHub to view this stage
The INFO command on a replica
Login via GitHub to view this stage
Initial Replication ID and Offset
Login via GitHub to view this stage
Send handshake (1/3)
Login via GitHub to view this stage
Send handshake (2/3)
Login via GitHub to view this stage
Send handshake (3/3)
Login via GitHub to view this stage
Receive handshake (1/2)
Login via GitHub to view this stage
Receive handshake (2/2)
Login via GitHub to view this stage
Empty RDB Transfer
Login via GitHub to view this stage
Single-replica propagation
Login via GitHub to view this stage
Multi Replica Command Propagation
Login via GitHub to view this stage
Command Processing
Login via GitHub to view this stage
ACKs with no commands
Login via GitHub to view this stage
ACKs with commands
Login via GitHub to view this stage
WAIT with no replicas
Login via GitHub to view this stage
WAIT with no commands
Login via GitHub to view this stage
WAIT with multiple commands
Login via GitHub to view this stage

Streams

The TYPE command
Login via GitHub to view this stage
Create a stream
Login via GitHub to view this stage
Validating entry IDs
Login via GitHub to view this stage
Partially auto-generated IDs
Login via GitHub to view this stage
Fully auto-generated IDs
Login via GitHub to view this stage
Query entries from stream
Login via GitHub to view this stage
Query with -
Login via GitHub to view this stage
Query with +
Login via GitHub to view this stage
Query single stream using XREAD
Login via GitHub to view this stage
Query multiple streams using XREAD
Login via GitHub to view this stage
Blocking reads
Login via GitHub to view this stage
Blocking reads without timeout
Login via GitHub to view this stage
Blocking reads using $
Login via GitHub to view this stage

Transactions

The INCR command (1/3)
Login via GitHub to view this stage
The INCR command (2/3)
Login via GitHub to view this stage
The INCR command (3/3)
Login via GitHub to view this stage
The MULTI command
Login via GitHub to view this stage
The EXEC command
Login via GitHub to view this stage
Empty transaction
Login via GitHub to view this stage
Queueing commands
Login via GitHub to view this stage
Executing a transaction
Login via GitHub to view this stage
The DISCARD command
Login via GitHub to view this stage
Failures within transactions
Login via GitHub to view this stage
Multiple transactions
Login via GitHub to view this stage
Many more to come...
coming soon
We release new challenges based on user votes. Let us know what you'd like to see next!
challenge voting
Vote on upcoming challenges