This can easily be done using â€śmatrix decompositionâ€ť approaches to pattern-matching analysis. See for example Compiling Pattern Matching to good Decision Trees, Luc Maranget, 2008. Pattern matrices and matrix decomposition are explained on pages 2 and 3.

In your example, the decomposition may go as follows:

```
| Node (_, Leaf) -> 1
| Node (Leaf, _) -> 2
| _ -> 3
= (split first column in Node|Leaf)
Node(â–ˇ) | (_, Leaf) -> 1
Node(â–ˇ) | (Leaf, _) -> 2
Node(â–ˇ) | (_, _) -> 3
Leaf | -> 3
= (split first tuple column)
Node(â–ˇ, â–ˇ) | _ Leaf -> 1
Node(â–ˇ, â–ˇ) | Leaf _ -> 2
Node(â–ˇ, â–ˇ) | _ _ -> 3
Leaf | -> 3
= (split first colum in Node|Leaf)
Node(Node(â–ˇ, â–ˇ), â–ˇ) | _ _ Leaf -> 1
Node(Node(â–ˇ, â–ˇ), â–ˇ) | _ _ _ -> 3
Node(Leaf, â–ˇ) | Leaf -> 1
Node(Leaf, â–ˇ) | _ -> 2
Node(Leaf, â–ˇ) | _ -> 3
Leaf | -> 3
= (push two colums)
Node(Node(_, _), â–ˇ) | Leaf ->1
Node(Node(_, _), â–ˇ) | _ -> 3
Node(Leaf, â–ˇ) | Leaf -> 1
Node(Leaf, â–ˇ) | _ -> 2
Node(Leaf, â–ˇ) | _ -> 3
Leaf | -> 3
= (split first column in Node|Leaf)
Node(Node(_, _), Node(â–ˇ,â–ˇ)) | _ _ -> 3
Node(Node(_, _), Leaf) | -> 1
Node(Node(_, _), Leaf) | -> 3
Node(Leaf, Node(â–ˇ,â–ˇ)) | _ _ -> 2
Node(Leaf, Node(â–ˇ,â–ˇ)) | _ _ -> 3
Node(Leaf, Leaf) | -> 1
Node(Leaf, Leaf) | -> 2
Node(Leaf, Leaf) | -> 3
Leaf | -> 3
= (push two columns)
Node(Node(_, _), Node(_,_)) | -> 3
Node(Node(_, _), Leaf) | -> 1
Node(Node(_, _), Leaf) | -> 3
Node(Leaf, Node(_,_)) | -> 2
Node(Leaf, Node(_,_)) | -> 3
Node(Leaf, Leaf) | -> 1
Node(Leaf, Leaf) | -> 2
Node(Leaf, Leaf) | -> 3
Leaf | -> 3
= (remove unreachable rows, final result)
Node(Node(_, _), Node(_,_)) -> 3
Node(Node(_, _), Leaf) -> 1
Node(Leaf, Node(_,_)) -> 2
Node(Leaf, Leaf) -> 1
Leaf -> 3
```