Matching with a RefinedDiscrTree #
This file defines the matching procedure for the RefinedDiscrTree.
The main definitions are
- The structure
MatchResult, which contains the match results, ordered by matching score. - The (private) function
evalNodewhich evaluates a node of theRefinedDiscrTree - The (private) function
getMatchLoop, which is the main function that computes the matches. It implements the non-deterministic computation by keeping a stack ofPartialMatches, and repeatedly processing the most recent one. - The matching function
getMatchthat also returns an updatedRefinedDiscrTree
To find the matches, we first encode the expression as a List Key. Then using this,
we find all matches with the tree. When unify == true, we also allow metavariables in the target
expression to be assigned.
We use a simple unification algorithm. For all star/metavariable patterns in the
RefinedDiscrTree (and in the target if unify == true), we store the assignment,
and when it is attempted to be assigned again, we check that it is the same assignment.
A match result contains the results from matching a term against patterns in the discrimination tree.
- elts : Std.TreeMap Nat (Array (Array α)) compare
The elements in the match result.
The
Natin the tree map represents thescoreof the results. The elements are arrays of arrays, where each sub-array corresponds to one discr tree pattern.
Instances For
Equations
Instances For
Convert a MatchResult into a Array, with better matches at the start of the array.
Equations
Instances For
Convert a MatchResult into an Array of Arrays. Each Array corresponds to one pattern.
The better matching patterns are at the start of the outer array.
For each inner array, the entries are ordered in the order they were inserted.
Equations
Instances For
Find values that match e in d.
- If
unify == truethen metavariables inecan be assigned. - If
matchRootStar == truethen we allow metavariables at the root to unify. Set this tofalseto avoid getting excessively many results.
Note: to preserve the reference to d, getMatch will never throw an error,
and instead it returns an Except Exception (MatchResult α).
Equations
- One or more equations did not get rendered due to their size.