We will start with a brief description of how we form our DSLs with the help of free monads/tf constraints and what the general rules to form such structures are. Then we will jump to the concrete example that shows nested structuring of the languages with one-way dependence.
We describe our DSL as a bunch of constructors having polymorphic parameter and lifted with Free.liftF
method to free monad.
General rules for forming those constructors are the following:
0. Add type parameter to your algebra making it functorial.
- If the step of computation expects a value from the interpreter context then it should be shaped as a function from expected value to the continuation of the Monad
A
:
ReadLine[A](line: String => A) extends Console[A]