translate converts a Free[F, A] program into Free[G, A] by supplying a polymorphic instruction conversion from F[x] to G[x]. Unlike runFree, it keeps the result inside Free rather than interpreting it into a final effect. section 13.10 section 13.4.2
The operation follows a small sequence:
- Accept a natural transformation-like function, [x] => F[x] => G[x], so every instruction type is translated without changing its result type. section 13.4.2
- Use runFree with Free[G, x] as the target effect and suspend each translated G[x] instruction. section 13.10
- Interpret the resulting Free[G, A] later with an interpreter appropriate to G. section 13.10
Translating console effects
A Free[Console, A] program can translate each Console[x] instruction to a Function0[x] thunk, producing Free[Function0, A]. Calling runTrampoline then executes the translated program. The same Console program can instead translate to Par[x] for a different execution strategy.
