Comment by iamevn

1 day ago

I'm in the same boat, recursion tends to be easier for me to reason about because I'm expressing the problem in terms of some base case that incoming parameters are being reduced to rather than some condition that an iterative approach is working towards.

I prefer recursion over loops. But even more I prefer abstracting away the recursion into combinators.

One of my favourite combinators is matrix multiplication. You define what 'addition' and 'multiplication' mean in your case, and all of a sudden you get an algorithm that computes shortest paths in a graph or does regex matching. See https://news.ycombinator.com/item?id=9751987

But for more bread and butter cases, there's 'map' over various data structures, and 'reduce' and traversals of trees etc.

  • I'm forbidden from those links :(

    • Oh, that's a shame. However, if you do a websearch for 'fun with semirings' you can find the relevant publication. Or you can use the wayback machine or so?