mirror of
https://github.com/CatalaLang/catala.git
synced 2024-11-08 07:51:43 +03:00
Printer: some small improvements
This commit is contained in:
parent
447f6d41f1
commit
4e465d2b48
@ -516,7 +516,7 @@ module ExprGen (C : EXPR_PARAM) = struct
|
||||
(pp_color_string (List.hd colors))
|
||||
")"
|
||||
| EArray es ->
|
||||
Format.fprintf fmt "@[<hov 2>%a %a@] %a" punctuation "["
|
||||
Format.fprintf fmt "@[<hv 2>%a@,@[<hov>%a@]@;<0 -2>%a@]" punctuation "["
|
||||
(Format.pp_print_list
|
||||
~pp_sep:(fun fmt () -> Format.fprintf fmt ";@ ")
|
||||
(fun fmt e -> lhs exprc fmt e))
|
||||
@ -689,8 +689,8 @@ module ExprGen (C : EXPR_PARAM) = struct
|
||||
Format.fprintf fmt "@[<hv 2>%a@ %a@]" EnumConstructor.format cons
|
||||
(rhs exprc) e
|
||||
| EMatch { e; cases; _ } ->
|
||||
Format.fprintf fmt "@[<v 0>@[<hv 2>%a@ %a@ %a@]@ %a@]" keyword "match"
|
||||
(lhs exprc) e keyword "with"
|
||||
Format.fprintf fmt "@[<v 0>@[<hv 2>%a@ %a@;<1 -2>%a@]@ %a@]" keyword
|
||||
"match" (lhs exprc) e keyword "with"
|
||||
(EnumConstructor.Map.format_bindings
|
||||
~pp_sep:(fun fmt () -> Format.fprintf fmt "@\n")
|
||||
(fun fmt pp_cons_name case_expr ->
|
||||
|
@ -35,34 +35,34 @@ scope S:
|
||||
$ catala scopelang -s S
|
||||
let scope S (x: integer|internal|output) =
|
||||
let x : integer = error_empty ⟨ ⟨true ⊢ ⟨0⟩⟩ | false ⊢ ∅ ⟩;
|
||||
assert (map (λ (i: integer) → i + 2) [ 1; 2; 3 ]) = [ 3; 4; 5 ];
|
||||
assert (filter (λ (i: integer) → i >= 2) [ 1; 2; 3 ]) = [ 2; 3 ];
|
||||
assert (map (λ (i: integer) → i + 2) [1; 2; 3]) = [3; 4; 5];
|
||||
assert (filter (λ (i: integer) → i >= 2) [1; 2; 3]) = [2; 3];
|
||||
assert (map (λ (i: integer) → i + 2)
|
||||
filter (λ (i: integer) → i > 2) [ 1; 2; 3 ])
|
||||
= [ 5 ];
|
||||
filter (λ (i: integer) → i > 2) [1; 2; 3])
|
||||
= [5];
|
||||
assert (reduce
|
||||
(λ (sum1: integer) (sum2: integer) → sum1 + sum2)
|
||||
0
|
||||
[ 1; 2; 3 ])
|
||||
[1; 2; 3])
|
||||
= 6;
|
||||
assert (reduce
|
||||
(λ (sum1: integer) (sum2: integer) → sum1 + sum2)
|
||||
0
|
||||
map (λ (i: integer) → i + 2) [ 1; 2; 3 ])
|
||||
map (λ (i: integer) → i + 2) [1; 2; 3])
|
||||
= 12;
|
||||
assert (length [ 1; 2; 3 ]) = 3;
|
||||
assert (length filter (λ (i: integer) → i >= 2) [ 1; 2; 3 ]) = 2;
|
||||
assert (length [1; 2; 3]) = 3;
|
||||
assert (length filter (λ (i: integer) → i >= 2) [1; 2; 3]) = 2;
|
||||
assert (reduce
|
||||
(λ (max1: integer) (max2: integer) →
|
||||
if max1 > max2 then max1 else max2)
|
||||
10
|
||||
[ 1; 2; 3 ])
|
||||
[1; 2; 3])
|
||||
= 3;
|
||||
assert (reduce
|
||||
(λ (max1: decimal) (max2: decimal) →
|
||||
if max1 > max2 then max1 else max2)
|
||||
10.
|
||||
map (λ (i: integer) → to_rat i) [ 1; 2; 3 ])
|
||||
map (λ (i: integer) → to_rat i) [1; 2; 3])
|
||||
= 3.;
|
||||
assert (reduce
|
||||
(λ (i_1: integer) (i_2: integer) →
|
||||
@ -75,7 +75,7 @@ let scope S (x: integer|internal|output) =
|
||||
i_1
|
||||
else i_2)
|
||||
42
|
||||
[ 1; 2; 3 ])
|
||||
[1; 2; 3])
|
||||
= 2
|
||||
```
|
||||
|
||||
|
@ -23,10 +23,10 @@ let topval closure_f : (closure_env, integer) → integer =
|
||||
λ (env: closure_env) (y: integer) →
|
||||
match
|
||||
(handle_default_opt
|
||||
[ ]
|
||||
[]
|
||||
(λ (_: unit) → true)
|
||||
(λ (_: unit) → ESome if (from_closure_env env).0 then y else - y))
|
||||
with
|
||||
with
|
||||
| ENone _ → raise NoValueProvided
|
||||
| ESome arg → arg
|
||||
let scope S (S_in: S_in {x_in: bool}): S {z: integer} =
|
||||
@ -37,7 +37,7 @@ let scope S (S_in: S_in {x_in: bool}): S {z: integer} =
|
||||
let set z : integer =
|
||||
match
|
||||
(handle_default_opt
|
||||
[ ]
|
||||
[]
|
||||
(λ (_: unit) → true)
|
||||
(λ (_: unit) →
|
||||
ESome
|
||||
@ -46,7 +46,7 @@ let scope S (S_in: S_in {x_in: bool}): S {z: integer} =
|
||||
f
|
||||
in
|
||||
code_and_env.0 code_and_env.1 -1))
|
||||
with
|
||||
with
|
||||
| ENone _ → raise NoValueProvided
|
||||
| ESome arg → arg
|
||||
in
|
||||
|
@ -18,7 +18,7 @@ let scope S (S_in: S_in {x_in: collection integer}): S {y: integer} =
|
||||
let set y : integer =
|
||||
match
|
||||
(handle_default_opt
|
||||
[ ]
|
||||
[]
|
||||
(λ (_: unit) → true)
|
||||
(λ (_: unit) →
|
||||
ESome
|
||||
@ -28,7 +28,7 @@ let scope S (S_in: S_in {x_in: collection integer}): S {y: integer} =
|
||||
else potential_max_2)
|
||||
-1
|
||||
x))
|
||||
with
|
||||
with
|
||||
| ENone _ → raise NoValueProvided
|
||||
| ESome arg → arg
|
||||
in
|
||||
@ -52,8 +52,9 @@ let scope S (S_in: S_in {x_in: collection integer}): S {y: integer} =
|
||||
let set y : integer =
|
||||
match
|
||||
(handle_default_opt
|
||||
[ handle_default_opt
|
||||
[ ]
|
||||
[
|
||||
handle_default_opt
|
||||
[]
|
||||
(λ (_: unit) → true)
|
||||
(λ (_: unit) →
|
||||
ESome
|
||||
@ -68,10 +69,11 @@ let scope S (S_in: S_in {x_in: collection integer}): S {y: integer} =
|
||||
potential_max_1
|
||||
else potential_max_2)
|
||||
-1
|
||||
x) ]
|
||||
x)
|
||||
]
|
||||
(λ (_: unit) → false)
|
||||
(λ (_: unit) → ENone ()))
|
||||
with
|
||||
with
|
||||
| ENone _ → raise NoValueProvided
|
||||
| ESome arg → arg
|
||||
in
|
||||
|
@ -21,10 +21,10 @@ let topval closure_f : (closure_env, integer) → integer =
|
||||
λ (env: closure_env) (y: integer) →
|
||||
match
|
||||
(handle_default_opt
|
||||
[ ]
|
||||
[]
|
||||
(λ (_: unit) → true)
|
||||
(λ (_: unit) → ESome if (from_closure_env env).0 then y else - y))
|
||||
with
|
||||
with
|
||||
| ENone _ → raise NoValueProvided
|
||||
| ESome arg → arg
|
||||
let scope S
|
||||
|
@ -22,11 +22,8 @@ $ catala Lcalc -s T --avoid_exceptions -O --closure_conversion
|
||||
let scope T (T_in: T_in): T {y: integer} =
|
||||
let sub_set s.x : bool =
|
||||
match
|
||||
(handle_default_opt
|
||||
[ ]
|
||||
(λ (_: unit) → true)
|
||||
(λ (_: unit) → ESome false))
|
||||
with
|
||||
(handle_default_opt [] (λ (_: unit) → true) (λ (_: unit) → ESome false))
|
||||
with
|
||||
| ENone _ → raise NoValueProvided
|
||||
| ESome arg → arg
|
||||
in
|
||||
@ -40,7 +37,7 @@ let scope T (T_in: T_in): T {y: integer} =
|
||||
let set y : integer =
|
||||
match
|
||||
(handle_default_opt
|
||||
[ ]
|
||||
[]
|
||||
(λ (_: unit) → true)
|
||||
(λ (_: unit) →
|
||||
ESome
|
||||
@ -49,7 +46,7 @@ let scope T (T_in: T_in): T {y: integer} =
|
||||
s.f
|
||||
in
|
||||
code_and_env.0 code_and_env.1 2))
|
||||
with
|
||||
with
|
||||
| ENone _ → raise NoValueProvided
|
||||
| ESome arg → arg
|
||||
in
|
||||
|
@ -71,10 +71,10 @@ let topval closure_y : (closure_env, integer) → integer =
|
||||
λ (env: closure_env) (z: integer) →
|
||||
match
|
||||
(handle_default_opt
|
||||
[ ]
|
||||
[]
|
||||
(λ (_: unit) → true)
|
||||
(λ (_: unit) → ESome ((from_closure_env env).0 + z)))
|
||||
with
|
||||
with
|
||||
| ENone _ → raise NoValueProvided
|
||||
| ESome arg → arg
|
||||
let scope SubFoo1
|
||||
@ -94,10 +94,10 @@ let topval closure_y : (closure_env, integer) → integer =
|
||||
let env1 : (integer * integer) = from_closure_env env in
|
||||
match
|
||||
(handle_default_opt
|
||||
[ ]
|
||||
[]
|
||||
(λ (_: unit) → true)
|
||||
(λ (_: unit) → ESome (env1.1 + env1.0 + z)))
|
||||
with
|
||||
with
|
||||
| ENone _ → raise NoValueProvided
|
||||
| ESome arg → arg
|
||||
let scope SubFoo2
|
||||
@ -133,20 +133,22 @@ let scope Foo
|
||||
let set b : bool =
|
||||
match
|
||||
(handle_default_opt
|
||||
[ let code_and_env : ((any, unit) → eoption bool * any) = b in
|
||||
code_and_env.0 code_and_env.1 () ]
|
||||
[
|
||||
let code_and_env : ((any, unit) → eoption bool * any) = b in
|
||||
code_and_env.0 code_and_env.1 ()
|
||||
]
|
||||
(λ (_: unit) → true)
|
||||
(λ (_: unit) →
|
||||
ESome
|
||||
match
|
||||
(handle_default_opt
|
||||
[ ]
|
||||
[]
|
||||
(λ (_1: unit) → true)
|
||||
(λ (_1: unit) → ESome true))
|
||||
with
|
||||
with
|
||||
| ENone _1 → raise NoValueProvided
|
||||
| ESome arg → arg))
|
||||
with
|
||||
with
|
||||
| ENone _ → raise NoValueProvided
|
||||
| ESome arg → arg
|
||||
in
|
||||
@ -157,7 +159,7 @@ let scope Foo
|
||||
} =
|
||||
match
|
||||
(handle_default_opt
|
||||
[ ]
|
||||
[]
|
||||
(λ (_: unit) → true)
|
||||
(λ (_: unit) →
|
||||
ESome
|
||||
@ -181,14 +183,14 @@ let scope Foo
|
||||
}
|
||||
in
|
||||
{ Result r = f.y; q = f.x1; }))
|
||||
with
|
||||
with
|
||||
| ENone _ → raise NoValueProvided
|
||||
| ESome arg → arg
|
||||
in
|
||||
let set z : integer =
|
||||
match
|
||||
(handle_default_opt
|
||||
[ ]
|
||||
[]
|
||||
(λ (_: unit) → true)
|
||||
(λ (_: unit) →
|
||||
ESome
|
||||
@ -197,7 +199,7 @@ let scope Foo
|
||||
r.r
|
||||
in
|
||||
code_and_env.0 code_and_env.1 1))
|
||||
with
|
||||
with
|
||||
| ENone _ → raise NoValueProvided
|
||||
| ESome arg → arg
|
||||
in
|
||||
|
@ -81,40 +81,40 @@ $ catala Interpret_Lcalc -s RentComputation --avoid_exceptions --optimize --debu
|
||||
f1 = λ (x: integer) →
|
||||
match
|
||||
(handle_default_opt
|
||||
[ ]
|
||||
[]
|
||||
(λ (_: unit) → true)
|
||||
(λ (_: unit) →
|
||||
ESome
|
||||
let x1 : integer = x + 1 in
|
||||
match
|
||||
(handle_default_opt
|
||||
[ ]
|
||||
[]
|
||||
(λ (_1: unit) → true)
|
||||
(λ (_1: unit) → ESome (x1 + 1)))
|
||||
with
|
||||
with
|
||||
| ENone _1 → raise NoValueProvided
|
||||
| ESome arg → arg))
|
||||
with
|
||||
with
|
||||
| ENone _ → raise NoValueProvided
|
||||
| ESome arg → arg
|
||||
[RESULT]
|
||||
f2 = λ (x: integer) →
|
||||
match
|
||||
(handle_default_opt
|
||||
[ ]
|
||||
[]
|
||||
(λ (_: unit) → true)
|
||||
(λ (_: unit) →
|
||||
ESome
|
||||
let x1 : integer = x + 1 in
|
||||
match
|
||||
(handle_default_opt
|
||||
[ ]
|
||||
[]
|
||||
(λ (_1: unit) → true)
|
||||
(λ (_1: unit) → ESome (x1 + 1)))
|
||||
with
|
||||
with
|
||||
| ENone _1 → raise NoValueProvided
|
||||
| ESome arg → arg))
|
||||
with
|
||||
with
|
||||
| ENone _ → raise NoValueProvided
|
||||
| ESome arg → arg
|
||||
```
|
||||
|
@ -14,8 +14,10 @@ let scope Foo (Foo_in: Foo_in): Foo {bar: integer} =
|
||||
let set bar : integer =
|
||||
try
|
||||
handle_default
|
||||
[ λ (_: unit) →
|
||||
handle_default [ ] (λ (_1: unit) → true) (λ (_1: unit) → 0) ]
|
||||
[
|
||||
λ (_: unit) →
|
||||
handle_default [] (λ (_1: unit) → true) (λ (_1: unit) → 0)
|
||||
]
|
||||
(λ (_: unit) → false)
|
||||
(λ (_: unit) → raise EmptyError)
|
||||
with EmptyError -> raise NoValueProvided
|
||||
|
Loading…
Reference in New Issue
Block a user