mirror of
https://github.com/CatalaLang/catala.git
synced 2024-09-20 00:41:05 +03:00
112 lines
2.9 KiB
Plaintext
112 lines
2.9 KiB
Plaintext
|
## Testing monomorphisation on context variables
|
||
|
|
||
|
```catala
|
||
|
declaration scope TestXor:
|
||
|
context output t content boolean
|
||
|
|
||
|
scope TestXor:
|
||
|
definition t equals true
|
||
|
```
|
||
|
|
||
|
```catala-test-inline
|
||
|
$ catala lcalc --monomorphize-types
|
||
|
type option_1 = | None_1 of unit | Some_1 of bool
|
||
|
|
||
|
type TestXor_in = { t_in: unit → option_1[None_1: unit | Some_1: bool]; }
|
||
|
type TestXor = { t: bool; }
|
||
|
type array_1 = {
|
||
|
content: list of option_1[None_1: unit | Some_1: bool];
|
||
|
length: integer;
|
||
|
}
|
||
|
|
||
|
let scope TestXor
|
||
|
(TestXor_in:
|
||
|
TestXor_in {t_in: unit → option_1[None_1: unit | Some_1: bool]})
|
||
|
: TestXor {t: bool}
|
||
|
=
|
||
|
let get t : unit → option_1[None_1: unit | Some_1: bool] =
|
||
|
TestXor_in.t_in
|
||
|
in
|
||
|
let set t : bool =
|
||
|
match
|
||
|
(match
|
||
|
(handle_exceptions { array_1 content = [t ()]; length = 1; })
|
||
|
with
|
||
|
| None_1 →
|
||
|
if true then
|
||
|
Some_1
|
||
|
(match
|
||
|
(match
|
||
|
(handle_exceptions
|
||
|
{ array_1
|
||
|
content =
|
||
|
[
|
||
|
match
|
||
|
(handle_exceptions
|
||
|
{ array_1 content = []; length = 0; })
|
||
|
with
|
||
|
| None_1 →
|
||
|
if true then Some_1 true else None_1 ()
|
||
|
| Some_1 x → Some_1 x
|
||
|
];
|
||
|
length = 1;
|
||
|
})
|
||
|
with
|
||
|
| None_1 → if false then None_1 () else None_1 ()
|
||
|
| Some_1 x → Some_1 x)
|
||
|
with
|
||
|
| None_1 → error NoValue
|
||
|
| Some_1 arg → arg)
|
||
|
else None_1 ()
|
||
|
| Some_1 x → Some_1 x)
|
||
|
with
|
||
|
| None_1 → error NoValue
|
||
|
| Some_1 arg → arg
|
||
|
in
|
||
|
return { TestXor t = t; }
|
||
|
|
||
|
```
|
||
|
|
||
|
```catala
|
||
|
declaration scope TestXor2:
|
||
|
t scope TestXor
|
||
|
output o content boolean
|
||
|
|
||
|
scope TestXor2:
|
||
|
definition o equals t.t
|
||
|
```
|
||
|
|
||
|
```catala-test-inline
|
||
|
$ catala lcalc --monomorphize-types -s TestXor2
|
||
|
let scope TestXor2 (TestXor2_in: TestXor2_in): TestXor2 {o: bool} =
|
||
|
let set t : TestXor {t: bool} =
|
||
|
let result : TestXor = TestXor { TestXor_in t_in = λ () → None_1 (); } in
|
||
|
let result1 : TestXor = { TestXor t = result.t; } in
|
||
|
if true then result1 else result1
|
||
|
in
|
||
|
let set o : bool =
|
||
|
match
|
||
|
(match
|
||
|
(handle_exceptions
|
||
|
{ array_1
|
||
|
content =
|
||
|
[
|
||
|
match
|
||
|
(handle_exceptions { array_1 content = []; length = 0; })
|
||
|
with
|
||
|
| None_1 → if true then Some_1 t.t else None_1 ()
|
||
|
| Some_1 x → Some_1 x
|
||
|
];
|
||
|
length = 1;
|
||
|
})
|
||
|
with
|
||
|
| None_1 → if false then None_1 () else None_1 ()
|
||
|
| Some_1 x → Some_1 x)
|
||
|
with
|
||
|
| None_1 → error NoValue
|
||
|
| Some_1 arg → arg
|
||
|
in
|
||
|
return { TestXor2 o = o; }
|
||
|
```
|
||
|
|