You can model any problem like this. Build up a da...
# arrow
r
You can model any problem like this. Build up a data structure then fold it in its interpreter. All trees are foldable, the interpreter is the fold. This allow you to model your problem outside of framework and integration noise which gets pushed to an interpreter of the data structure you have built. You can have multiple interpreters and it’s 100% testable. As you add nodes to the operation you start discovering the structure and the kinds of operations you can apply on your nodes like
empty
,
plus
, etc which shows the presence of type classes like Monoid or Semigroup beside Foldable. Same concept applies to other ADTS for example a recursive GADT for List:
Copy code
sealed class List<out A> {
  data class Cons<out A>(val head: A, val tail: List<A>): List<A>()
  object Nil : List<Nothing>()
}

val list: List<A> = Cons(1, Cons(2, Cons(3, Nil)))