Earlier quoted context omitted.
I’m not going to defend single letter names (although shortness does have some virtue compared to some monstrous naming conventions), but... Most math texts have a fair amount of documentation when formulas are introduced. Perhaps substantially more than the table in this article.
Math papers on the other hand assume that the reader has recursively traversed and read all of the citations and knows most of the notation.
Common combinators in JavaScript
51–55 of 55 posts
Re: Common combinators in JavaScript
#52This site embodies everything I dislike about functional programming: an attitude that shorter and less specific is better. What use is a line like const S = f => g => x => f(x)(g(x)); for anyone except someone who already groks what the S combinator does and is for? Why do these combinators have single-letter names anyway? Does that help anyone? Even Haskell, heaven on earth for single-letter guess-what-i-mean coder…
This is an implementation of combinatory logic and nothing to do with functional programming. https://en.wikipedia.org/wiki/Combinatory_logic
Re: Common combinators in JavaScript
#53Earlier quoted context omitted.
It's intentionally to get across the idea that you don't, and shouldn't, know anything about these arguments within this scope beyond "this is a function" and "this is an argument". These functions just define how to combine things; if you knew any more about the arguments, it would be breaking the abstraction. The only better names you could really give are ones like func1, func2, arg1, arg2, which don't add any inf…
That makes sense for the arguments to the outermost function but not to the function it self. Why call it A instead of apply and the then have a big cheat sheet where you put that A means apply and T means applyTo ?
- K is "const" and C is "flip"; they're generally used to for arguments to a higher order function: "map (const 5) myList", "foldl (flip f) 0 myList"
- Psi is "on", since it's regularly used to construct a new function "h = f `on` g"
- S is a specific type of application, called infix as "f `ap` x", but also has an operator to intentionally make it look more like just line noise: "f x". (Had to add spaces to this operator so HN wouldn't interpret it as italics)
The operators might seem opaque, but the idea is to make it more visually apparent that it's a pattern, not some application-specific business logic. There are lots of concepts of "apply" - there's pure application ($), Applicative application (), Monadic application (=<<), etc. - writing them out would distracting to read. Using operators makes it easier to skim and get the general idea of how the code works without worrying about the underlying structural details, while still being precise about them.
Re: Common combinators in JavaScript
#54Earlier quoted context omitted.
Same reason we use + instead of Math.addTwoIntegers(). Pure snobbery.
However, we don't combine + with other operators to form an illegible mess. Even ++ is frowned upon for being unreadable/easily missed and/or placed in the wrong spot.