public function fixIdentities($unique = null) {
        if ($this->children) {
            if (!isset($unique))
                $unique = array_unique($this->flat());

            foreach ($this->children as $i => $child) {
                if (!$child instanceof BranchPattern) {
                    if (!in_array($child, $unique))               // Not sure if this is a true substitute for 'assert c in uniq'
                        throw new \UnexpectedValueException();
                    $this->children[$i] = $unique[array_search($child, $unique)];
                }
                else {
                    $child->fixIdentities($unique);
                }
            }
        }
        return $this;
    }