Hacker News new | past | comments | ask | show | jobs | submit login

To understand loop you just need to know in which order to execute its parts. And you see how it reduces, maps an filters your data. You don't need to keep stack in your head. To understand how functional constructs work you have to know a lot more because they are specialised and it's not that easy to track what they exactly do because of recursion. You have to know them and trust them. With loop all internal logic is linear and in plain sight.



Its certainly true that to understand a fold at the abstraction level that C uses you have to know more, but that isn't the same as you having to know it in order to program effectively. The point of abstraction is that you don't need to know the fine details of whats happening under the hood. You might talk about how, in a C program you can watch what happens to your loop variable as you execute, but really "variables" are just abstractions over what the machine is really doing. If you were to look at the assembly spit out by your compiler that loop variable might be in a register or on the stack or in some combination thereof, and if your compiler does loop unrolling it might have different values at the same time even in the assembly. And once you get into the reorder buffer or a modern CPU I guarantee you that what actually happens will bear very little resemblance to what you would naively think if you just looked at the C code.

So you can execute a loop C-token by C-token and you can execute a fold Haskel-token by Haskel-token, but both are abstractions high above whats happening at the machine level and I don't see why we should prefer one over the other.




Consider applying for YC's W25 batch! Applications are open till Nov 12.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: