|  |  | 
| exception Error of context * expr;;
exception Value of int;;
let rec decompose_down (c,e as ce) =
  match e with
  | Var _ -> raise (Error (c, e))
  | Const c when c.constr -> raise (Value (c.arity + 1))
  | Const c -> raise (Value (c.arity))
  | Fun (_, _) -> raise (Value 1)
  | Let (x, e1, e2) -> decompose_down (LetL (x, c, e2), e1)
  | App (e1, e2) as e ->
      try decompose_down (AppL (c, e2), e1) with Value k1 ->
        try decompose_down (AppR ((k1, e1), c), e2) with Value k2 ->
          if k1 > 1 then raise (Value (k1 -1)) else ce;; |  |