unison/unison-src/transcripts/fix3265.output.md

91 lines
2.0 KiB
Markdown
Raw Permalink Normal View History

2022-11-02 17:39:35 +03:00
Tests cases that produced bad decompilation output previously. There
are three cases that need to be 'fixed up.'
1. lambda expressions with free variables need to be beta reduced
2. let defined functions need to have arguments removed and
occurrences rewritten.
3. let-rec defined functions need to have arguments removed, but
it is a more complicated process.
``` unison
2022-11-02 17:39:35 +03:00
> Any (w x -> let
f0 y = match y with
0 -> x
n -> 1 + f1 (drop y 1)
f1 y = match y with
0 -> w + x
n -> 1 + f0 (drop y 1)
f2 x = f2 x
f3 y = 1 + y + f2 x
g h = h 1 + x
g (z -> x + f0 z))
2022-11-02 17:39:35 +03:00
```
``` ucm
2022-11-02 17:39:35 +03:00
Loading changes detected in scratch.u.
2022-11-02 17:39:35 +03:00
scratch.u changed.
Now evaluating any watch expressions (lines starting with
`>`)... Ctrl+C cancels.
1 | > Any (w x -> let
Any
(w x ->
2023-03-04 05:03:40 +03:00
let
use Nat + drop
2023-07-21 09:12:22 +03:00
f1 y = match y with
0 -> w + x
n -> 1 + f0 (drop y 1)
f0 y = match y with
0 -> x
n -> 1 + f1 (drop y 1)
2023-03-04 05:03:40 +03:00
f2 x = f2 x
f3 x y = 1 + y + f2 x
g h = h 1 + x
g (z -> x + f0 z))
```
Also check for some possible corner cases.
`f` should not have its `x` argument eliminated, because it doesn't
always occur with `x` as the first argument, but if we aren't careful,
we might do that, because we find the first occurrence of `f`, and
discard its arguments, where `f` also occurs.
``` unison
> Any (x -> let
f x y = match y with
0 -> 0
_ -> f x (f y (drop y 1))
f x 20)
```
``` ucm
Loading changes detected in scratch.u.
scratch.u changed.
Now evaluating any watch expressions (lines starting with
`>`)... Ctrl+C cancels.
1 | > Any (x -> let
Any
(x ->
2023-03-04 05:03:40 +03:00
let
2023-07-21 09:12:22 +03:00
f x y = match y with
0 -> 0
_ -> f x (f y (Nat.drop y 1))
2023-03-04 05:03:40 +03:00
f x 20)
2022-11-02 17:39:35 +03:00
```