It wouldn't solve the problem, because in reality I'm matching something like this piece of code implementing a doubly-linked list:
type 'a cell = { data : 'a;
next : 'a link ref;
last : 'a link ref;
}
and 'a link = Cons of 'a cell | Nil
type 'a t = {
firstl: 'a link ref;
lastl: 'a link ref;
}
let pop s = match s with
| {firstl = {contents=Nil}; lastl = _ } -> raise Empty
| {lastl = {contents=Cons {data; _}}} when s.lastl == s.firstl ->
(* one term *)
s.lastl := Nil;
s.firstl := Nil;
data
| {firstl =
{contents=Cons {data; next={contents=Cons n}; last={contents=Nil}}}} ->
n.last := Nil;
s.firstl := Cons n;
data
| _ -> failwith "Error in pop"
See how unwieldy that is without the ability to clean it up by matching on refs?