mirror of
https://github.com/CatalaLang/catala.git
synced 2024-11-08 07:51:43 +03:00
Add one more trivial optimisation
This commit is contained in:
parent
5cb8ba805b
commit
61c105c365
@ -353,6 +353,16 @@ let rec optimize_expr :
|
||||
} ->
|
||||
(* reduces a fold with one element *)
|
||||
EApp { f; args = [init; e']; tys = [tinit; tx] }
|
||||
| ETuple ((ETupleAccess { e; index = 0; _ }, _) :: el)
|
||||
when List.for_all Fun.id
|
||||
(List.mapi
|
||||
(fun i -> function
|
||||
| ETupleAccess { e = en; index; _ }, _ ->
|
||||
index = i + 1 && Expr.equal en e
|
||||
| _ -> false)
|
||||
el) ->
|
||||
(* identity tuple reconstruction *)
|
||||
Mark.remove e
|
||||
| ECatch { body; exn; handler } -> (
|
||||
(* peephole exception catching reductions *)
|
||||
match Mark.remove body, Mark.remove handler with
|
||||
|
@ -156,9 +156,7 @@ let grok : (decimal, money, money) → (money * decimal) =
|
||||
in
|
||||
let tlist : list of (decimal * money * money) =
|
||||
map2
|
||||
(λ (a: decimal) (b_c: (money * money)) →
|
||||
let a_b_c : (decimal * money * money) = (a, b_c.0, b_c.1) in
|
||||
(a_b_c.0, a_b_c.1, a_b_c.2))
|
||||
(λ (a: decimal) (b_c: (money * money)) → (a, b_c.0, b_c.1))
|
||||
lis1
|
||||
map2 (λ (b: money) (c: money) → (b, c)) lis2 lis3
|
||||
in
|
||||
@ -203,12 +201,7 @@ let S : S_in → S =
|
||||
let xy1 : (decimal * money) = xy_z.0 in
|
||||
let z1 : money = xy_z.1 in
|
||||
(xy1.1 * xy1.0, xy1.1 / z1))
|
||||
map2
|
||||
(λ (x: decimal) (y: money) →
|
||||
let x_y : (decimal * money) = (x, y) in
|
||||
(x_y.0, x_y.1))
|
||||
lis1
|
||||
lis2
|
||||
map2 (λ (x: decimal) (y: money) → (x, y)) lis1 lis2
|
||||
lis3
|
||||
in
|
||||
{ S r1 = r1; r2 = r2; r3 = r3; r4 = r4; r5 = r5; r6 = r6; }
|
||||
|
Loading…
Reference in New Issue
Block a user