Is it possible to write an HTML compiler with no mutable state?
In theory, any program can be treated as functional by treating every operation as "replace the world with a world this piece of state replaced by a different value". In practice ... this actually works pretty well.

Your code will look something like:

root_node = parse_html()

for each operation:
    root_node = root_node.replace_using_operation(operation)


For a leaf or node that you know won't be affected by this operation, replace_using_operation looks like:

fn replace_using_operation(self, op):
    return self


For the typical non-leaf case, replace_using_operation will look like:

fn replace_using_operation(self, op):
    children = new List&lt;Node&gt;();
    # pedantically, this is not "functional", but realistically it is.
    # if your language has generators or a iterator map function you can
    # make it purely functional, but most people find this easier to read.
    for each ch in self.children:
        children.append(ch.replace_using_operation(op))
    new_self = new Node(children)
    delete self
    return new_self


Of course, depending on what knowledge you have of the operation, you might want to perform different operations on some children. Also note that you're perfectly free to pass additional arguments (including snapshots of other branches of the tree - just remember you don't own them) or to have entirely separate replace_* functions instead of passing operation as an argument.

This code is only a very rough skeleton, after all.