Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

You are missing the point, which is that if you can blindly follow the type hints of the compiler and still get a non-stupid function when you're joking around like the author is, then in real-life coding situations the type hints will be all the more relevant and reliable.

By the way, this is literally the most common foldr implementation in functional languages, so I have no idea why you would want to do a code review of it, or talk about performances in such a trivial setting, or pretend that you're confused by it so much that you have to refer to a library...



> then in real-life coding situations the type hints will be all the more relevant and reliable

That was exactly my point about the foldr example: in real-world code, you may need a function that perfectly matches foldr's type signature. But following the author's methodology, you'll write out a new implementation of foldr, when what you should actually be doing is calling foldr in that type hole.

This ties back in to my comment about code review. Think about how a patch from someone who applied the author's method would look like: it would contain a lot of in-place implementations that they sort of stumbled into, when in fact they should have reused well-known functions. Someone should then try to review that code to see if some implementation is not actually a well-known function.

Even ghc suggested at some point that he should use maxBound or minBound instead of writing his own thing.

Edit: I should also add that there is no reason to think that foldr is the right implementation of zoop without more context. For example, zoop could be a function just like foldr but that works on the reversed list of `as`. Or one that skips every second element of `as`. If we're just guessing based on type, and don't know what the code is supposed to do, it's easy to mess up.




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

Search: