I have a recursive immutable data structure in ocaml that can be simplified something like this:
type expr =
{
eexpr : expr_expr;
some_other_complex_field : a_complex_type;
}
and expr_expr =
| TInt of int
| TSum of (expr * expr)
| TMul of (expr * expr)
This is AST, and sometimes it gets quite complicated (it is very deep).
There is a recursive function that evaluates an expression. For example, let's say
let rec result expr =
match expr.eexpr with
| TInt i -> i
| TSum (e1, e2) -> result e1 + result e2
| TMul (e1, e2) -> result e1 * result e2
Now suppose I match an expression with another expression, and I need to constantly check the result of expr, sometimes more than once for the same expr, and sometimes for expressions that were recently displayed using the template
{ someExpr with eexpr = TSum(someExpr, otherExpr) }
, , . , Hashtbl, AFAIK Hashtbl , .
, "" expr. .
, Ocaml , , ?
!