Deprecated: The each() function is deprecated. This message will be suppressed on further calls in /home/zhenxiangba/zhenxiangba.com/public_html/phproxy-improved-master/index.php on line 456
-- Application of the deep selection patterns -- Michael and Sergio -- Mon Apr 18 15:47:00 PDT 2011 -- Examples: -- 1. Find all the vairable of an expression -- 2. Find some common subexpression of an expressio import SetFunctions data Exp = Lit Int | Var [Char] | Add Exp Exp | Mul Exp Exp -- return expressions with a given subexpression withSub exp = exp ? op (withSub exp) unknown ? op unknown (withSub exp) where op = Add ? Mul -- Examples: exp1 = Add (Mul (Lit 42) (Add (Lit 0) (Var "z"))) (Add (Var "x") (Var "y")) exp2 = Add (Mul (Lit 42) (Add (Lit 42) (Var "y"))) (Add (Var "x") (Var "y")) -- get some variable occurring in an expression varOf (withSub (Var v)) = v -- get the set of the variables (identifiers) of an expression allVariablesOf exp = sortValues (set1 varOf exp) test = allVariablesOf exp1 -- Problem: finding common subexpressions in an expression: -- Define all expressions containing a common subexpressions: withCommonSub e = op (withCommonSub e) unknown ? op unknown (withCommonSub e) ? op (withSub e) (withSub e) where op = Add ? Mul -- Finding common subexpressions is straightforward: commonSub (withCommonSub e) = e -- all the common subexpressions ctest1 = set1 commonSub exp1 ctest2 = set1 commonSub exp2