I am writing a simple Okmome program that reads algebraic statement from a file, it's Oklailax / Okamalike, to reduce it And then prints it out. The part in which I am reducing the expression seems a little bit ... Is the wrong way to do something that I can simplify?
(* Not capable of taking arithmetic operators in the form of ocal function, so define these rappers for them *) with xy = x + y xy = x - y right xy = X * y div divide xy = x / y (* 1 and term2 are both ints? *) Both_in terms term1 = 22 with match (term1, term2) (Duration (number x), duration (number y)) - & gt; True | (_, _) - & gt; Wrong (* We know that both words are redeemable for numbers, so give them alliance *) combine_terms func xy = with match (x, y) (period (number t1), duration (number t2)) - & Gt; | (_ (_, _) - & gt; Increase InvalidArg (* Reduce as much expression as possible *) * Rick cum _XP XP = M = XP with Match Plus (X, Y) - & Gt; cum_x = cum_expo x and less_a = cum_exer y y if both- specify decrement then decrease_accounts (cum_x less_a plus in composite lines) and plus (cum_x, cum_a) zero (x, y) -> cum_x = cum_expo x and Less_a = less_expires if both_art If decreased, then less_acca_a_ (alliance_tom sub sub_x decreased) and minus zero (cum_x, less_a). Multiplication (x, y) -> gtc: xx_x = cum_xprro x and decrease_e = less_exer y and if two_inces decrease, then less_acca_a_ (alliance_arms MUL cum_x lower_A) and multiply (weak_x, cum_a). Divided (x, y) -> gtc: x_fx = cum_xprro x and decrease_e = cum_exprimary wi if both_nerts are deducted then less_acc_a_a_g_g You can remove
both_ints
and
by typing
function as well as somenumber
in the type of operation functions> Combine theif
statement,let div xy = match x, along with y. Number x, number y - & gt; Number (x / y) | _ - & gt; Divide (x, y) ... rick cum_xpr xp = match with xpr .... | Split (X, Y) - & gt; Div (cum_xprose x) (low_expr Yew) ...
No comments:
Post a Comment