19 Mutable Singly Linked Lists (Part 1)

Let's define mutable singly-linked lists in OCaml.

Okay, that seems like a good place to start, but what if we need to end our list? The last element of our list will need to have a next field. OCaml provides options for this, so let's make the next field an option. Let's also add an abstraction function.

Now let's create a type for liked lists (not just the node). This can hold information like the size of the list.

Now let's write some code to create lists. We'll first implement singleton lists, lists of a single value.

Now let's make a list!