|
|
|
|
|
by seles
1569 days ago
|
|
This kind of feels like using continuations, here is a Haskell demo of the concept: myMap = myMapHelper id
myMapHelper cont f [] = cont []
myMapHelper cont f (x:xs) = myMapHelper (cont . (f x :)) f xs
Of course this actually makes things slower in Haskell, either due to the growing continuation or existing optimizations in Haskell |
|
For added fun, that continuation can then be defunctionalized [1] back into a data structure. It can be argued that TRMC as implemented in the linked post is simply a special case of this more general transformation.
[1] https://www.pathsensitive.com/2019/07/the-best-refactoring-y...