!import "prelude" !Local !import "io" !Local !import "view" !Local -- View Contracts + IO interaction trees -- Run with: -- -- tricu eval demos/viewContracts/io.tri --io -f decode -- -- The IO runtime expects the top-level value to be an interaction tree wrapped -- by the `io` sentinel: -- -- pair "tricuIO" (pair version action) -- -- View Contracts can validate that boundary before the IO driver starts. The IO -- value is still just an interaction tree; this demo only checks how it was -- exposed. ioSentinel? = (value : and? (equal? (fst value) "tricuIO") (equal? (fst (snd value)) 1)) requireIO = (value : lazyBool (_ : guardOk value) (_ : guardFail) (ioSentinel? value)) -- A first useful IO View is intentionally shallow: -- -- viewAny -- accept any payload structurally -- requireIO sentinel -- require the top-level IO wrapper at runtime -- -- This does not prove every future continuation step is well-formed. It proves -- the checked program exposes an IO interaction tree to the host driver. viewIO = viewGuarded viewAny requireIO checkedIO = (action : matchResult (diag env : io (pure (renderDiagnostic diag))) (exec env : matchResult (runtimeDiag runtimeEnv : io (pure (renderDiagnostic runtimeDiag))) (value runtimeEnv : value) (runChecked exec)) (checkTypedProgramWith policyStrict (typedProgram 0 [(typedValue 0 viewIO action)]))) main = checkedIO (io (pure "checked interaction tree"))