117 lines
2.2 KiB
Markdown
117 lines
2.2 KiB
Markdown
# Frontend Emission Demos
|
|
|
|
These examples show the layer between source-level View annotations and the
|
|
portable View Contract checker.
|
|
|
|
Each `*.source.txt` file is pseudo-source: it is not parsed by `tricu`. It shows
|
|
the information a frontend has after parsing/elaboration.
|
|
|
|
Each matching `*.emitted.tri` file shows the lowered typed-program metadata that
|
|
a frontend can emit today. A successful check returns checked-exec; these demos
|
|
focus on structural Views, so they report `"ok"` as soon as metadata checking
|
|
succeeds. Guarded programs should run the returned checked-exec with
|
|
`runChecked`, as shown in `demos/viewContracts.tri` and by `tricu check`.
|
|
|
|
## Successful map use
|
|
|
|
Pseudo-source:
|
|
|
|
```text
|
|
map : Fn [Fn [Bool] String, List Bool] (List String)
|
|
f : Fn [Bool] String
|
|
xs : List Bool
|
|
|
|
partial = map f
|
|
out = partial xs
|
|
|
|
require out : List String
|
|
```
|
|
|
|
Run the emitted artifact:
|
|
|
|
```bash
|
|
tricu eval demos/viewContracts/frontendEmission/map-success.emitted.tri -f decode
|
|
```
|
|
|
|
Expected output:
|
|
|
|
```text
|
|
"ok"
|
|
```
|
|
|
|
## Wrong list argument
|
|
|
|
Pseudo-source:
|
|
|
|
```text
|
|
map : Fn [Fn [Bool] String, List Bool] (List String)
|
|
f : Fn [Bool] String
|
|
xs : List String
|
|
|
|
partial = map f
|
|
out = partial xs
|
|
```
|
|
|
|
Run:
|
|
|
|
```bash
|
|
tricu eval demos/viewContracts/frontendEmission/map-wrong-list.emitted.tri -f decode
|
|
```
|
|
|
|
Expected output:
|
|
|
|
```text
|
|
"symbol 162 expected List Bool but got List String"
|
|
```
|
|
|
|
## Wrong filter predicate
|
|
|
|
Pseudo-source:
|
|
|
|
```text
|
|
filter : Fn [Fn [Bool] Bool, List Bool] (List Bool)
|
|
pred : Fn [Bool] String
|
|
xs : List Bool
|
|
|
|
partial = filter pred
|
|
out = partial xs
|
|
```
|
|
|
|
Run:
|
|
|
|
```bash
|
|
tricu eval demos/viewContracts/frontendEmission/filter-wrong-predicate.emitted.tri -f decode
|
|
```
|
|
|
|
Expected output:
|
|
|
|
```text
|
|
"symbol 181 expected Fn [Bool] Bool but got Fn [Bool] String"
|
|
```
|
|
|
|
## Lowering shape
|
|
|
|
A frontend does not need to expose `tricu` syntax internally. It only needs to
|
|
emit portable typed-program nodes:
|
|
|
|
```text
|
|
typedValue symbol view term
|
|
typedApply out callee arg term
|
|
typedRequire symbol view term
|
|
```
|
|
|
|
The source-level flow:
|
|
|
|
```text
|
|
out = map f xs
|
|
```
|
|
|
|
lowers to curried Tree Calculus application nodes:
|
|
|
|
```text
|
|
typedApply partial map f partialTerm
|
|
typedApply out partial xs outTerm
|
|
```
|
|
|
|
Function Views drive argument checking and result inference.
|