Live data from Hacker News

J Notation as a Tool of Thought

hillelwayne.com

41–50 of 60 posts

Re: J Notation as a Tool of Thought

#41
post #26

The article has the footnote > APL was the first language to use “monad” as a term. The popular FP meaning only appeared thirty years later. in its, to me odd, use of the word "monad". This is incorrect. The "popular FP meaning" arose because it's a very special case of the standard concept from mathematics [1]. The mathematical terminology harkens back to the 1950s, and thus predates APL. In Haskell, a monad is prec…

Yes,that footnote somehow is kind of one of those things one hear often but it is wrong, by monad in APL or J one should understand 'monadic'

Re: J Notation as a Tool of Thought

#42
post #40
post #26

The article has the footnote > APL was the first language to use “monad” as a term. The popular FP meaning only appeared thirty years later. in its, to me odd, use of the word "monad". This is incorrect. The "popular FP meaning" arose because it's a very special case of the standard concept from mathematics [1]. The mathematical terminology harkens back to the 1950s, and thus predates APL. In Haskell, a monad is prec…

> The mathematical terminology harkens back to the 1950 Does it? The earliest instances I can find are in Mac Lane's 1971 book or thereabouts; the older term was "triple". Wikipedia dates APL to 1966. "Monad" has also seen nebulous use in philosophy at least since Leibniz.

That's an interesting reference...

Re: J Notation as a Tool of Thought

#43
post #26

The article has the footnote > APL was the first language to use “monad” as a term. The popular FP meaning only appeared thirty years later. in its, to me odd, use of the word "monad". This is incorrect. The "popular FP meaning" arose because it's a very special case of the standard concept from mathematics [1]. The mathematical terminology harkens back to the 1950s, and thus predates APL. In Haskell, a monad is prec…

> The mathematical terminology harkens back to the 1950s, and thus predates APL.

History isn't particularly logical sometimes, so there could be two competing meanings - which didn't seem too competing at the time (as well as later).

Regarding the history of the word, Wikipedia says:

"A mathematical notation for manipulating arrays was developed by Kenneth E. Iverson, starting in 1957 at Harvard University."

"The mathematician Roger Godement was the first to formulate the concept of a monad (dubbing it a "standard construction") in the late 1950s"

Similarly, those terms seem to develop in parallel:

"In 1960, he began work for IBM where he developed this notation with Adin Falkoff and published it in his book A Programming Language in 1962."

"The form defined above using bind, however, was originally described in 1965 by mathematician Heinrich Kleisli in order to prove that any monad could be characterized as an adjunction between two (covariant) functors."

So monad term arguably wasn't an established one in another meaning when Iverson employed it for APL.

Let's check the etymology of words. Two meanings of "monad" (I'm omitting the one from linear algebra) stem from the idea of oneness - in APL it's "one argument", in category theory it's "one category", as the category is being mapped to itself (same as endofunctor, but monad also has extra requirements, so needs another term). So using the same word for similar properties seems logical - again, in the absence of established different meaning.

In practice, monads in APL and FP are sufficiently different so no confusion usually takes place. Similarly FP uses terms like "lens" and "optics", which are hardly confused with earlier introduced physical terms.

Re: J Notation as a Tool of Thought

#44

J and K remind me of the essay about the Lisp Curse[0], which mentions that the expressiveness of the language became a sort of Achilles heel in its culture. It talks about people writing their projects in Lisp and not expecting other people to adapt to their conventions or combine their efforts on one library, where every solution worked well enough initially - but only for one person, its author. In K the error mes…

It's about redundancy. Code in other languages has much more of it, and that is good for understandability, recognizability.

With less redundancy it is easier to make errors both in writing AND reading of code.

APL is like compressed code. The redundancy has been compressed out. Therefore reading a page of APL is like reading a book in other languages. Even though the text is shorter you still have to understand as much of program behavior.

Reading APL means reading something FAST and we know that it is easy to have errors whenever you try to do something fast, say like typing very fast.

Re: J Notation as a Tool of Thought

#45
post #40
post #26

The article has the footnote > APL was the first language to use “monad” as a term. The popular FP meaning only appeared thirty years later. in its, to me odd, use of the word "monad". This is incorrect. The "popular FP meaning" arose because it's a very special case of the standard concept from mathematics [1]. The mathematical terminology harkens back to the 1950s, and thus predates APL. In Haskell, a monad is prec…

> The mathematical terminology harkens back to the 1950 Does it? The earliest instances I can find are in Mac Lane's 1971 book or thereabouts; the older term was "triple". Wikipedia dates APL to 1966. "Monad" has also seen nebulous use in philosophy at least since Leibniz.

In fact since the Pythagoreans [1] where the monad comes first and after the dyad and after the numbers and so on. It also was the term for unicellular organism before this was coined.

Monadic was an adjective used in logic before the 20th century, using the noun dervied by the greek root monas which gave monad and monadic (and the same with dyad, dyadic).

If I take for right what is on the french [2] and english pages [3] of wikipedia about the terminology history of the monad words its usages seems to date to around the 70 when Saunders Mac Lane named it in reference to the philosophical term.

I feels some times people tend to forget how interconnected is and was mathematics and philosophy and how term from philosophy were used in a mathematical context based on their philosophical definition.

[1] https://en.wikipedia.org/wiki/Monad_(philosophy)

[2] https://fr.wikipedia.org/wiki/Monade_(th%C3%A9orie_des_cat%C...

[3] https://en.wikipedia.org/wiki/Monad_(category_theory)#Termin...

Re: J Notation as a Tool of Thought

#46

J and K remind me of the essay about the Lisp Curse[0], which mentions that the expressiveness of the language became a sort of Achilles heel in its culture. It talks about people writing their projects in Lisp and not expecting other people to adapt to their conventions or combine their efforts on one library, where every solution worked well enough initially - but only for one person, its author. In K the error mes…

That is fine. Most people simply cannot drive a Formula-1 car, but it would be stupid to conclude that a F-1 is a cursed car and nobody should want to drive one. Similarly, a few languages can only be used by highly trained people who understand well how it works. Lisp, Forth, and J are in that category of tools that require highly trained people. In their hand, one of these languages can do fantastic things, in the…

That is actually a nice analogy! No one, not even the pro formula-1 drivers will want to drive a f1 car in regular traffic. Much the same with these languages (apls, lisps, forth, etc); they have their place and role, but is better not used in regular open source or commercial codes.

Re: J Notation as a Tool of Thought

#47
post #29
post #28

Earlier quoted context omitted.

It is not about "cannot be done". Most high-level languages are Turing complete, hence every program in one can be written as some program in another. The real clincher is expressiveness: shorter code is better, modular code is better, and languages which avoid unnecessary repetitiveness of boiler plate code is better. Different languages provide advantages along one or more of these parameters.

So can you give an example of something that can be expressed simply in APL/J/K that can't be expressed simply with numpy? And to be clear I don't think "less characters" makes the expression more simple. Maybe "less statements" or "less operators"

Here's Conway's Game of Life by Arthur Whitney (creator of K):

  life:{3=a-x*4=a:2{+(0+':x)+1_x,0}/x}
I'm guessing a numpy implementation would be between one and two orders of magnitude more verbose, even if you're just comparing the number of operations.

Re: J Notation as a Tool of Thought

#48

J and K remind me of the essay about the Lisp Curse[0], which mentions that the expressiveness of the language became a sort of Achilles heel in its culture. It talks about people writing their projects in Lisp and not expecting other people to adapt to their conventions or combine their efforts on one library, where every solution worked well enough initially - but only for one person, its author. In K the error mes…

Actually, it's somewhat the opposite. The lisp curse refers to the ways in which lisp can easily be extended with nonstandard or bespoke features. Apl relies much more heavily on primitives; they are so expressive and general that you often don't even need to add functions. This gives the code more universality (assuming you know the language, which I expect should be a given).

Re: J Notation as a Tool of Thought

#49

This seems very interesting for numerical computation, but at first glance few of these operations seem to apply directly to general computation (I'm sure that there are isomorphisms that can be used to apply them indirectly). The example with sorting was the oddest from this point of view. The author praised the idea of the permutation vector as being a relatively direct mathematical specification of sorting (return…

> there is no word on the algorithm - ' how is the array sorted' is the question that computer science is designed to solve, as opposed to 'what are the fixed points of a sorted array' ' [H]ow is the array sorted' is one question that computer science can be used to solve. However, assuming it has been solved (which, for many cases, it has), a much more interesting question is 'what can we do with a sorted array'; or…

My point was that general programming usually looks more like writing the sorting algorithm than simply calling it. Thus, I would be more interested in seeing real examples of how the properties of J allow you to write algorithms more concisely or otherwise better.

The article showed how J solves some mathematical problems with built in functions or their built-in modifiers. But in general programming, you won't find a function that does exactly what you wanted, maybe with a little adverb. You'll usually have to write that function yourself, to describe how it works in terms of some of those pre-existing functions.

Note that your second example could be expressed as something like

    x.OrderBy(y => y[1])
In C#, assuming x is int[N][M]. I understand that J's version can work with many other shapes of X, but that is hard to appreciate without seeing example of how that comes in handy when writing some other (hopefully well known) algorithm.

Re: J Notation as a Tool of Thought

#50
post #38
post #8

Earlier quoted context omitted.

Can you give an example of something that can be done in J that can't be done easily in numpy?

I have only passing experience with numpy, but I suspect the following "shift a matrix in all 8 directions", used in the famous APL/J game of life solution [0][1], would require multiple statements as well as being more verbose in numpy (I'm guessing you'd need to use "roll" multiple times?): (>,{;~i:1) |. i.4 4 Try it online: https://tio.run/##y/r/PzU5I19Bw06n2rou08pQU6FGTyFTz0TB5P9/AA [0] https://www.youtube.com/wa…

This 100 character version is probably the cleanest.

    M = np.reshape(np.arange(16),(4,4))
    np.array([np.roll(M,(i,j),(0,1)) 
              for i in [1,0,-1]
              for j in [1,0,-1]])
Post reply on HN