▲ | solomonb a day ago | |
Given an algebraic data type such as:
You can define its recursion principle by building a higher-order function that receives an element of your type and, for each constructor, receives a function that takes all the parameters of that constructor (with any recursive parameters replaced by `r`) and returns `r`.For `List` this becomes:
The eliminator for `Nil` can be simplified to `r` as `() -> r` is isomorphic to `r`:
For `Bool`:
We get:
Which is precisely an If statement as a function!:D |