So. In my last post about this compiler project, I wrote out the following trait definition, explaining that it’s what I was using to do type-safe AST transformations:
I called it a “specialized Functor” because I didn’t quite understand what exactly a Functor was, but I knew that, at the very least, what I had was a little different.
Upon reading this, Prophet of welltypedwit.ch, who actually knows what she’s talking about when it comes to functional programming, pointed me towards a Haskell package called uniplate, noting that what I was doing sounded like its transformBi operation.
What is this saying? Even if you understand Haskell, it can sometimes still be tricky to get what certain operations mean. In this case, I think about it like:
Given a type From, which is a container type like the root of an AST, and a type To, which is like an inner node of an AST, transform From by applying an operation each time we encounter a node of type To in the tree.