News for hackers. Stuff that matters.
Re:Why I Prefer Functional Programming by spekcular on Saturday October 31, 2020 @02:53PM (#24954182)
> There's a saying in mathematics that when any field matures it turns into algebra. Life crossed a threshold from chemistry to biology on Earth, and developed exponentially from there. Order in mathematics crosses a similar threshold, as it becomes sufficiently structured to support algebraic reasoning. The subjective experience is like ice melting into a churning liquid, or a land-locked creature learning to fly. Once one has this experience, one cannot imagine thinking any other way.

Hi, this seems wrong to me.

First, as far as I can tell, such a saying does not exist. I've never heard it, despite having a fair amount of experience with mathematics (though not as much as you), and I can't find it through Googling.

Second, and more substantively, it is not the case that mathematical fields inevitably turn into algebra. One only has to look at PDE, probability, and analytic number theory to see this is the case (to give just a few examples). All are highly mature fields and essentially non-algebraic. This is not to say that ideas from algebra are not occasionally useful, just that it should be obvious to anyone who opens an introductory graduate text in PDE that the subject has not "turn[ed] into algebra."

> The killer app for Haskell is parallelism. To this day it has the best implementation of parallelism; one can achieve a 7x speedup on 8 cores by adding a handful of lines to a program. This ease is a consequence of the functional model, and of considerable effort by Haskell's developers.

I don't think this statement is entirely wrong, but I don't think it's entirely right either. There are plenty of languages where one can get parallelism with just a few extra lines of code; Julia comes to mind immediately. Easy parallelism is hardly a Haskell-specific, or even FP-specific, feature. I would of course agree that designing things without mutable state makes writing parallel code easier, but this can be done in many high-level languages these days.

But that is a nitpick. A more substantive objection is that the sole purpose of parallelism is performance, and idiomatic Haskell is generally speaking slower, sometimes a lot slower, than the same algorithm written in C++ or similar languages. (The adjective idiomatic is important here – I'm aware that one can with enough contortions write C-like code in Haskell, but this response undercuts of the point of highlighting Haskell-specific features like immutability, laziness, etc.) In particular, a few years ago it seemed like the people implementing parallel Haskell features didn't understand or care about fundamental things like cache locality. Maybe this has changed?

There is also an amusing story about the "ease" of writing parallel quicksort in Haskell [1].

> The real point of lazy evaluation is that it best supports this algebraic reasoning, as carbon best supports life.

It's worth noting that Simon Peyton Jones is on record as saying that any "Haskell 2" should not be lazy [2].

[1] https://sudonull.com/post/75314-Parallel-quick-sort-on-Haske...

[2] https://news.ycombinator.com/item?id=1924061

Re:Why I Prefer Functional Programming by the__alchemist on Saturday October 31, 2020 @05:30PM (#24955345)
Good point... The realization that chaotic systems are ubiquitous, and that many physical phenomena (motion of the planets, how chemical interactions work at the electron level etc) can't be modeled analytically (so far as we know) was a big upset to mathematics and science, and still isn't addressed well in school curriculum.

To expand on your main point: A loose, but appropriate analogy is that FP appeals to programmers in the way analytic solutions appeal to mathematicians and scientists: Neat, ideal, beautiful... but a poor fit for many practical problems.

Re:Why I Prefer Functional Programming by adwn on Saturday October 31, 2020 @04:16PM (#24954849)
> In particular, a few years ago it seemed like the people implementing parallel Haskell features didn't understand or care about fundamental things like cache locality.

That's the main issue which FP-for-parallel-execution proponents don't seem to get: Identifying independent (and therefore parallelisable) computations isn't the hard part, but planning the data layout and partitioning so that all your parallelism isn't eaten up by synchronization and data movement between cores.

Re:Why I Prefer Functional Programming by kenjackson on Saturday October 31, 2020 @06:04PM (#24955576)
I think it may be more accurate to say they are both hard problems. It is still open if P=NC.
Re:Why I Prefer Functional Programming by adwn on Sunday November 01, 2020 @01:52AM (#24957670)
That is misleading. Although you're technically correct [1], the computational models on which computational complexity classes are based are so abstract and idealized, that they offer almost no information whether your program could make efficient use of an actual, physical 8-core CPU.

The NC complexity class assumes a PRAM machine, in which all processors can access all locations of a central memory in constant time. That's not how a multi-core CPU works in practice: If your parallel algorithm doesn't make proper use of cache-locality, you've already lost.

[1] (the best kind of correct)

Re:Why I Prefer Functional Programming by Twisol on Saturday October 31, 2020 @07:13PM (#24956001)
> Second, and more substantively, it is not the case that mathematical fields inevitably turn into algebra.

Not to fully justify the OP (though it rings both true and not quite true to me), but I think topology is a good positive example. It's impressive how much of continuity can be captured purely algebraically. For example, topologies are a kind of lattice, which cross both algebra and order theory. And then you get literal algebraic topology, which captures useful and interesting properties of individual topological spaces effectively.

> A more substantive objection is that the sole purpose of parallelism is performance.

I disagree a lot more strongly here, though I will twist your words a little bit. Yes, parallelizing a program is about making it run faster; but parallelism is also a base fact of many problem domains, where you have multiple agents (up to and including humans) collaborating and interacting simultaneously.

Abstracting over the speed-up aspects of parallelism gets you to concurrency -- the independence of knowledge held by distinct agents that is not directly knowable by others -- which is far more fundamental than simply making programs run faster. In my experience, most properties of modular systems can be stated in terms of concurrency. Parallelism is an exploitation of that concurrency structure to schedule things efficiently, but it is by no means the only application.

The fact that "one can achieve a 7x speedup on 8 cores by adding a handful of lines to a program" tells me that Haskell is extremely good at letting you expose the concurrent structures of your problem domain.

Re:Why I Prefer Functional Programming by lptk on Sunday November 01, 2020 @01:16PM (#24961315)
> but parallelism is also a base fact of many problem domains, where you have multiple agents (up to and including humans) collaborating and interacting simultaneously.

I don't think parallelism is the word for that. More like concurrency

Parallel computing is closely related to concurrent computing—they are frequently used together, and often conflated, though the two are distinct: it is possible to have parallelism without concurrency (such as bit-level parallelism), and concurrency without parallelism (such as multitasking by time-sharing on a single-core CPU).[5][6] In parallel computing, a computational task is typically broken down into several, often many, very similar sub-tasks that can be processed independently and whose results are combined afterwards, upon completion. In contrast, in concurrent computing, the various processes often do not address related tasks; when they do, as is typical in distributed computing, the separate tasks may have a varied nature and often require some inter-process communication during execution.

https://en.wikipedia.org/wiki/Parallel_computing

What you're describing sounds like it would be solved by primitives such as the actor model, not by Haskell-style FP.

Re:Why I Prefer Functional Programming by spekcular on Saturday October 31, 2020 @09:55PM (#24956700)
Certainly, algebraic topology is a huge win for algebraization!

> Yes, parallelizing a program is about making it run faster; but parallelism is also a base fact of many problem domains, where you have multiple agents (up to and including humans) collaborating and interacting simultaneously.

Maybe I should say what I meant more clearly. The claim "one can achieve a 7x speedup on 8 cores by adding a handful of lines to a program" implicitly has a "and this is good because being fast is good" at the end. Why care about a speedup if you don't care about speed in the first place?

It follows that when evaluating a language's ability to gain speed through parallelization, we should also evaluate how fast that language is in the first place. If you can get a 7x speedup on 8 cores from a few lines of code, but the original algorithm is, say, 10x slower than a similar implementation in C/Rust/Go on one core, then who cares? The ultimate criterion is always absolute speed, not relative improvement.

I agree that being able to deal with concurrency is important, but as the Go people always remind me, concurrency and parallelism are distinct concepts.

Re:Why I Prefer Functional Programming by marcosdumay on Saturday October 31, 2020 @03:48PM (#24954607)
Probability has surely morphed into an algebra, and what you study in modern introductory books is the conversion of the algebra into "everyday language" so that students don't get scared. It has very little similarity to what probability looked like when it was being developed.

Also, you seem to be overstating the maturity of PDE (people are pretty much still trying to turn it into algebra, but it may not be possible) and number theory (that's an active research area).

I have never seen that saying either, but it seems quite correct, with the exception of the areas where an algebra is impossible, so the field matures without becoming one.

Re:Why I Prefer Functional Programming by spekcular on Saturday October 31, 2020 @06:21PM (#24955690)
On what basis do you say that probability has "morphed into an algebra"? Consider all of the popular research topics today: the KPZ equation, Schramm-Loewner evolution, spin glasses, percolation and critical phenomena, rigorous statistical mechanics in general [1], random matrix theory, large deviations, stochastic analysis and (P)SDEs.

Obviously, I'm forgetting some, but none of these are primarily algebraic. Some algebraic methods are used (orthogonal polynomials in random matrix theory, and determinants and a whole host of other things to study integrable models in the KPZ universality class, etc.), but clearly groups/rings/fields are not playing a major role.

For a more systematic approach you could look at recent issues of Annals of Probability, Annals of Applied Probability, and similar journals. There's not going to be a lot of "modern algebra" (of the flavor you see in algebraic geometry) there.

The same comments apply to PDE and analytic number theory. Both are obviously mature fields (worked on for a long time by many people, with a lot of great discoveries), but again algebra does not play a central role in either. In particular I am not aware of any PDE specialists whose research agenda consists of "trying to turn it into algebra."

[1]: https://www.unige.ch/math/folks/velenik/smbook/

Re:Why I Prefer Functional Programming by bitdizzy on Sunday November 01, 2020 @12:04AM (#24957151)
I know vaguely from a few friends that there is some cross pollination between algebraic geometry and PDE's but both fields are so huge that this doesn't characterize either field. I think the gist of it is that the moduli space of PDE solutions are frequently interesting as varieties.

There's this rare unclosed survey-like mathoverflow question that highlights some of these points: https://mathoverflow.net/questions/66046/which-nonlinear-pde...

Re:Why I Prefer Functional Programming by pessimizer on Saturday October 31, 2020 @04:04PM (#24954737)
> There are plenty of languages where one can get parallelism with just a few extra lines of code; Julia comes to mind immediately.

Julia is a multi-paradigm language, but it is heavily Erlang inspired (another multi-paradigm language, but primarily functional.)