Live data from Hacker News

Haskell, Reverse Polish Notation, and Parsing

mattwills.bearblog.dev

11–14 of 14 posts

Re: Haskell, Reverse Polish Notation, and Parsing

#12
post #4
post #3

Agreed that RPN (and stack machines) are beautiful and underappreciated. Unfortunately, it's for a relevant reason that I have to push back against the author's newfound love of recursion. Like everyone else I had the same brain-exploding moment when I realized that recursion was possible and how if forced me to re-think what functions were capable of, but now that I'm old and ornery I'm of the Hot Take that recursio…

If I have to traverse a tree, then recursion is more natural to me. With a loop you’ll have to manually use a stack (it’s fine, but more error prone). For lists, I rarely write loops or recursion. It’s mostly folds and maps.

For sure. Data structures and call graphs like to converge, so when designing a data model, you are actually designing the (most natural) program flow too.

Re: Haskell, Reverse Polish Notation, and Parsing

#13

I've always felt like RPN is a really powerful lesson in how subtly redefining the semantics of a problem can make it suddenly much easier to solve. My personal struggle with functional programming is how difficult I find it to be iterative. I've very frequently backed myself into a corner and ended up having to rewrite everything, whereas in C, even when I miss badly on the architecture, I'm still usually able to re…

I found writing in Lisp was liberating, as everything can be reused into a bigger program.

And Lisp is a functional programming language. It is also a programmable programming language, so you can even extend its syntax.

I am interested in your struggle. I want to know what is really difficult about functional programming for a learner.

Re: Haskell, Reverse Polish Notation, and Parsing

#14
post #4
post #3

Agreed that RPN (and stack machines) are beautiful and underappreciated. Unfortunately, it's for a relevant reason that I have to push back against the author's newfound love of recursion. Like everyone else I had the same brain-exploding moment when I realized that recursion was possible and how if forced me to re-think what functions were capable of, but now that I'm old and ornery I'm of the Hot Take that recursio…

If I have to traverse a tree, then recursion is more natural to me. With a loop you’ll have to manually use a stack (it’s fine, but more error prone). For lists, I rarely write loops or recursion. It’s mostly folds and maps.

I feel like this is a common enough pattern with well-known translations from one form to the others, that a compiler might optimize it one way or the other. Or is it still too high-level for even modern awesome compilers/interpreters?
Post reply on HN