Hacker News new | ask | show | jobs
by whyonearth 2740 days ago
> The cornerstone of JavaScript is the function.

JavaScript is specified in terms of objects, has richer facilities for dealing with objects than functions, functions are objects but not vice-versa. So, objects are the cornerstone. Callers are free to ignore a function's arity even.

1 comments

Yup, everything is nicer in Javascript if you're working with objects.

There's no type checking or syntactic sugar for dealing with first-class functions, so complex functional programming leads to brutal stack traces and if you ask a debugger what any part of this "pyramid" is, it tells you, "well, it's a function."

If I'm using a parser combinator in Haskell, for instance, I can just say:

   liftA2 (+) parseInteger parseInteger
It's pretty clear (if you're familiar with functors) that I'm parsing two integers and adding the result. And it has to typecheck, so 90% of my stupid mistakes are caught by the compiler.

But, also, if I go into ghci, I can see what it is:

     :t liftA2
     Applicative f => (a -> b -> c) -> f a -> f b -> f c
So I can see the first argument (a -> b -> c) is a function with two arguments, and the second, f a, and third, f b, are boxed in the Applicative, and the result, f c, is boxed in the Applicative. That's how you can understanding that it's combining two parsers using + and then the result is itself a parser.

Javascript, even though it supposedly has all its type information at runtime, really doesn't know any of this because a function is a function and that's all it knows. You could replicate liftA2 in Javascript, but it would be entirely mysterious what's going on.