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

It’s nothing to do with the language being functional or not. It’s because JS supports optional arguments. Haskell doesn’t support optional arguments which is why this is impossible in Haskell, but that is a huge trade off since optional arguments make it easy to evolve an API over time without causing breakage.

It’s a known good practice in JS to always wrap callbacks with a lambda in this situation. Even if you don’t, usually the type checking will catch it, this bug only works because the second argument is a number to both functions.



> optional arguments make it easy to evolve an API over time without causing breakage

Defining functions with new names also make it easy to evolve an API over time without causing breakage.


It does tend to make code less readable however if you end up with several functions that do the same thing except that they were defined at different times with different numbers of arguments. It’s not always clear from the perspective of the API user whether the difference is just the number of arguments or if there are other differences too. Optional arguments communicate that intention more explicitly.

Looking at, e.g. the Python standard library a large number of functions have arguments that were added after the function was first defined. If Python didn’t have optional/keyword arguments then the number of API calls would be substantially larger.


> It’s not always clear from the perspective of the API user whether the difference is just the number of arguments or if there are other differences too. Optional arguments communicate that intention more explicitly.

They do, but potentially falsely.

> Looking at, e.g. the Python standard library a large number of functions have arguments that were added after the function was first defined. If Python didn’t have optional/keyword arguments then the number of API calls would be substantially larger.

The inability of Haskell not to have optional arguments isn't too bad, but all in all, I have to concede that you have a fair point. I personally don't miss optional arguments but I can see how they're beneficial (and I would really like named arguments).




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

Search: