News for hackers. Stuff that matters.
Re:Programming Languages Going Above and Beyond by zoogeny on Thursday June 29, 2023 @12:07PM (#36522347)
I like that things like this exist even if I recognize that they are not for me. For some class of system I am sure these languages will shine. It reminds me of Julia - every time I come across it I love the idea of it but I have no personal use for it. I'm always interested in reading articles on dependent type languages like Coq and Idris but I haven't even tried to write a "Hello, World!" in them.

I may just be jaded with promises of sufficiently smart compilers. I actually hold out more hope for AI code assistance than I do for easy-to-use formal verification.

It is a bit like Esperanto or something like that. Maybe I am just brain damaged from growing up in a world with English and other messy spoken languages but my intuition suggests that perfectly structured languages are possibly the wrong approach.

Even though at the time I wanted xhtml to win the battle of structured formats for the web, in hindsight I now believe messy html 5 was the way to go.

> We still get buffer overflows and integer overflows. The compiler still cannot tell when our loops will terminate (yes, this is possible). Aliasing is still a complete unbridled mess.

As strange as it sounds, I've learned to love the flaws. I don't see my job in life is to remove every possible source of error. There seems to be a balance point where the cure is worse than the disease and I wish to find that balance point rather than some theoretical perfect.

So I do hate those things listed. But so far, the balance point for me is with languages that sacrifice perfectly solving those problems.

Re:Programming Languages Going Above and Beyond by nine_k on Thursday June 29, 2023 @01:30PM (#36523664)
Highly regular natural languages exist and thrive. I'd say that Japanese is a way, way more regularly structured language than English.

Loving flaws like buffer overflows looks more like a Stockholm syndrome to me: when the reality is terrible, people learn to find lovable bits in it, just to avoid insanity. C has its place, but its place is very, very close to hardware. (And I hope Zig will push it from there, too, eventually.)

I don't think that better static guarantees are going to come from direct adoption of languages like Haskell, or some tools like Coq or Agda. They will continue coming the same way Rust and Typescript gone mainstream: by integrating them into practical (not research) languages, and allowing escape hatches, prominently marked. Advanced features need adaptation to be ergonomic, after that they feel natural. This happens to every scientific achievement that has a large practical value: compare a laser on an optical workbench in a lab to a laser in a DVD drive, or a laser pointer.

I would likely laugh if someone told me in 1995 that pure FP approaches will conquer GUI development. Nevertheless, this happened twice: first with XSLT in 2000s, then with React in 2010s.

Re:Programming Languages Going Above and Beyond by valenterry on Thursday June 29, 2023 @02:55PM (#36525072)
react is not an example for a library that is supposed to be or even possible to be used in a pure functional programming way.
Re:Programming Languages Going Above and Beyond by adamwk on Thursday June 29, 2023 @03:18PM (#36525400)
Right, there's definitely functional-inspired bones (e.g., a view is a function of state); but every hook is a side effect, even the redux ones.

And I don't think it would even be improved by being pure; Elm has much more boilerplate to do similar things.

Re:Programming Languages Going Above and Beyond by valenterry on Thursday June 29, 2023 @03:26PM (#36525506)
haha, Adam from SM, is it you?
Re:Programming Languages Going Above and Beyond by WorldMaker on Thursday June 29, 2023 @03:49PM (#36525782)
React can still be viewed as functional programming if you assume Hooks operate in/on/with an unnamed/untyped monad. ("Pure" of course depends on your take of monadic programming from there.) It might be nice if that monad were better typed and/or at least parametric (reflected in input or output parameters), but it all exists in an untyped language to begin with, so it is mostly fine how it works right now. Mostly.
Re:Programming Languages Going Above and Beyond by valenterry on Friday June 30, 2023 @04:42AM (#36532126)
I don't know. I haven't used hooks much, but while you might consider it pure-functional in a way within a component that uses (a single) hook, I think using multiple hooks and having everything integrated is certainly not pure-functional.

It's easy to test right? Can you replace calls/expressions with their result-value? If no, it's not pure-functional.

Re:Programming Languages Going Above and Beyond by WorldMaker on Friday June 30, 2023 @10:34AM (#36535625)
Like I said, I don't think it counts as "pure" functional because it is heavily monadic. Many Haskell users still think non-monadic code is "more pure" than say anything that uses the IO Monad and Hooks are "worse" than the IO Monad. (Especially some of the "Suspense" project Hooks which combine IO and Futures and State and more from a Haskell standpoint into one super weird monad.)

You can certainly replace most hooks with static return values. Many hooks are heavily memoizable and in turn heavily memoized which is how they find their performance in practice.

Multi-hook interactions generally follow a lot of the laws of monadic binding and a lot of the "hooks rules" aren't that strange in terms of monads: monadic binds have sequencing that matters (and dependencies you might track). The order of hooks matter in the same way that the order of IO binds or the order of Futures/Promises awaits.

Again, it is certainly hard to call it "pure" functional in most ways, it has a lot of impurity, but it is certainly "deeply" functional. There's not really a better paradigm to call what is React is doing with Hooks than "functional programming". The language of monads is somewhat helpful in reasoning about how Hooks work and where they sit in the paradigm. They definitely make everything a bit more "impure", especially from the strict mathematical sense of "pure functions are entirely dependent on their parameters". Especially with Hooks not being represented parametrically (which I did mention I think can be something of a problem and I wish wasn't the case).

Re:Programming Languages Going Above and Beyond by valenterry on Friday June 30, 2023 @12:15PM (#36537645)
> You can certainly replace most hooks with static return values.

"most" is not good enough. The idea of PFP is precisely that there is no exception, otherwise all guarantees are void. If I cannot rely on an expression to be referential transparent, then it means I have to look into to find out - and with that, the advantage of PFP goes through the window.

> The order of hooks matter in the same way that the order of IO binds or the order of Futures/Promises awaits.

The difference is that if you create an effect in a PFP style (like in Haskell), the effect itself doesn't do anything. You can now combine that effect with another effect in some way, e.g. by sequencing, which means first effect A and then afterwards effect B is executed. Yes. But what you get back is, again, an effect that doesn't do anything. So what you need to do is to build a datastructure of effects.

Do you do that with hooks? I don't think so. With hooks, you call one, then call another, and yeah, the result depends on the order just like with an effect monad like IO. But the difference is that once the line of code that calls the hook is executed, something happens and the world has changed. This is not true when you can the line of code that builds the datastructure for the effect execution.

You would have handle hooks like promises for this to work in a PFP way. But maybe I misunderstand and you can clarify it with a code example?

Otherwise, I just think it's about terminology. I agree that there is a relation between the two things, but we shouldn't give it the same name, because it is still not the same concept.

Re:Programming Languages Going Above and Beyond by WorldMaker on Friday June 30, 2023 @12:57PM (#36538362)
Hooks definitely build a complex data structure. They don't actually run immediately/imperatively. Even `useEffect(callback, undefined)` (no defined dependencies) which gives the illusion that it runs "immediately" on every render is still an illusion of sorts and there's a complex scheduler apparatus feeding on the data structures under the hood that useEffect builds.

The data structures that Hooks build in React gets built in a strangely bound, somewhat liminal `this` space so it effectively "disappears" in JS. That's certainly not how I would have built it. You are right that I probably would have used something more like JS Promises, given the choice. But I didn't build React's Hook systems, I'm just an outside critic. I'm very happy to agree that use of `this` bound things is about as impure functionally as you get in JS. (That said, it is a very JS solution that predates React and gets to old debates of whether or not JS is truly "OO". Prototypical OO is a gray space between OO and functional paradigms.)

Hooks are never imperative, even in the most complex multi-hook components. They use and build data structures. Those data structures are mostly hidden from view and hard to inspect, but they exist.

Re:Programming Languages Going Above and Beyond by valenterry on Friday June 30, 2023 @01:23PM (#36538784)
> Hooks definitely build a complex data structure

But you don't. It is react that builds the datastructure in the background, not you that builds and controls it. Hooks might be declarative, but this is actually orthogonal to being pfp or not.

All of that is totally fine btw., there is no need for everything to follow a pfp style. It's a tradeoff. But we shouldn't call something pfp that isn't, even if it is closely related.

Re:Programming Languages Going Above and Beyond by nine_k on Thursday June 29, 2023 @04:16PM (#36526100)
Look, you have a large stream of pure functions that exchange immutable data. There is a place where you can thread in the effects, and it's not entirely like using >>=, but after it, it's immutable data and pure functions again.

It's very different from jQuery and the callback hell, or from any two-way bindings all the way to Visual Basic.

It teaches you to value immutability and purity, to crave it (then comes Ramda, etc).

Also, Promises are not entirely monadic, and `async` is not entirely the do-notation, but you can use a lot of monadic approaches, and reap some of the benefits.

Re:Programming Languages Going Above and Beyond by valenterry on Thursday June 29, 2023 @04:21PM (#36526157)
> and it's not entirely like using >>=

Exactly, and that's why it is not pf. It's really as simple as that.

It's also not as if it would be theoretical distinction that has no meaning for praxis. It does. For instance, since I cannot control the execution of React's cycle (including rendering) it becomes hard(er) to do certain kind of page animations that should happen between renders.

> It's very different from jQuery and the callback hell

Yes, it is nicer to use. But it is not pfp-style.

Re:Programming Languages Going Above and Beyond by nine_k on Thursday June 29, 2023 @05:13PM (#36526792)
What would you suggest as a pure enough example of FP GUI? Anything besides Elm, I mean? :)
Re:Programming Languages Going Above and Beyond by valenterry on Thursday June 29, 2023 @05:51PM (#36527260)
I have never worked with one professionally (I rarely do frontend work anyways) and for my own projects I used react, dirty and productive as it is. ;)
Re:Programming Languages Going Above and Beyond by c_crank on Thursday June 29, 2023 @03:00PM (#36525161)
JavaScript has never been and probably never will achieve any sort of purity due to the design decisions made in its debut. Frameworks can only paper over that so much.
Re:Programming Languages Going Above and Beyond by valenterry on Thursday June 29, 2023 @03:25PM (#36525500)
I mean, there are fp-ts and ts-effect. Sure, internally they do nasty things, but at least as a user I think it's possible to write pf or at least mostly pf code. (without commenting on whether that is a good idea or not)
Re:Programming Languages Going Above and Beyond by eyelidlessness on Thursday June 29, 2023 @11:34PM (#36530221)
You can actually type JS to be incredibly more strict than TS does if you have the motivation. It still won’t be impossible to reach runtime errors, but it can be very close to “you really have to try and mean it”.
Re:Programming Languages Going Above and Beyond by rirze on Thursday June 29, 2023 @03:41PM (#36525695)
Funny enough, Japanese is incredibly fun and enjoyable when you use dialects and break the syntax to be "artsy"
Re:Programming Languages Going Above and Beyond by nine_k on Thursday June 29, 2023 @04:10PM (#36526029)
But even that does not increase the number of irregular verbs past two and a half (くる, する, ありえる). I don't know enough Japanese to say if one can invent forms like "swole" or "boxen" in it, so that they would remain recognizable.
Re:Programming Languages Going Above and Beyond by labster on Thursday June 29, 2023 @08:21PM (#36528772)
Archaisms, slang, and alternate pronunciations definitely exist in Japanese. And dialects, of course.
Re:Programming Languages Going Above and Beyond by astrange on Thursday June 29, 2023 @09:50PM (#36529548)
You can invent a lot of things in written Japanese using textspeak and other alphabets.

Spoken Japanese you can't break the rules because everyone else instantly becomes unable to understand you. They barely use local accents/dialects in media because of this.

Re:Programming Languages Going Above and Beyond by manquer on Thursday June 29, 2023 @07:59PM (#36528582)
> Loving flaws like buffer overflows looks more like a Stockholm syndrome to me:

Only if you are the developer (victim ) it is fun to work with buffer overflows if you are the security researcher (law enforcement) or a hacker (kidnapper )

Re:Programming Languages Going Above and Beyond by eindiran on Friday June 30, 2023 @01:24PM (#36538790)
It's funny that you picked the language with the single worst and most fundamentally broken orthographic system in the world as your example.
Re:Programming Languages Going Above and Beyond by dunham on Thursday June 29, 2023 @01:30PM (#36523670)
The dependent languages are interesting. But the theorem proving is not easy, and probably overkill for a lot of applications. Even for stuff like boundary conditions for binary search, which could be checked with Hoare logic, I usually handle by stealing the implementation from the Go standard library (so I don't have to think about it).

Last year I did advent of code in Lean4. I had written a heap implementation that I didn't end up using. As an exercise, I went back and added proofs for my indicies and a termination proof. I got the termination proof down to `0 < 0` and realized that I had an off by one error (I'd used the math for a 1-based array with a 0-based array).

My take-away was that this stuff can catch real bugs, but also that people are not going to do this stuff day-to-day. Maybe some equality saturation thing will make it possible for the compiler to sort out the proof in most cases. If the compiler can hit 80%, you could use it as a linter. (If you want something stricter, you can do totality checking but have escape hatches like Idris' assert_total / assert_smaller.)

> Even though at the time I wanted xhtml to win the battle of structured formats for the web, in hindsight I now believe messy html 5 was the way to go.

The structured vs unstructured thing is also interesting. I came to a similar conclusion years ago. I'd written some heuristics to pull recipes out of web pages, and also use embedded microdata on some pages. I found I got better results with my heuristics because of bad encoding of the structured data. E.g. a web site was missing entire ingredient blocks in their encoding because their process / data model didn't accommodate recipes with multiple ingredient blocks.

Re:Programming Languages Going Above and Beyond by PsylentKnight on Thursday June 29, 2023 @02:45PM (#36524913)
> It is a bit like Esperanto or something like that. Maybe I am just brain damaged from growing up in a world with English and other messy spoken languages but my intuition suggests that perfectly structured languages are possibly the wrong approach.

You seem to be implying Esperanto's lack of popularity is related to its regularity, but I don't think it has anything to do with that - it comes down to network effects. It's not an official language in any country. There are very, very few native speakers of Esperanto. Of those blessed few, they obviously have at least one other native language, otherwise they'd be completely cut off from society.

And by the same token, English is popular as a second language due to network effects and the benefits learning it can confer (read: better economic opportunities) and little to do with its regularity. A lot of people have had the experience of learning a bit of Spanish and realizing that English's spelling system is atrociously irregular and we gain nothing by having so many spelling rules that have so many exceptions they can hardly be considered "rules". In fact, English's spelling used to be much more regular, it's just that our pronunciations have shifted a lot over time while the spelling has remained relatively static.

This is all tangential to your larger point, I just like talking about this kind of thing.

Re:Programming Languages Going Above and Beyond by thr_ddv on Thursday June 29, 2023 @03:49PM (#36525779)
>The compiler still cannot tell when our loops will terminate (yes, this is possible).

    while(n < busy_bever(10))
        n++
Tell me when my loop terminates.
Re:Programming Languages Going Above and Beyond by jcranmer on Thursday June 29, 2023 @04:33PM (#36526304)
Assuming you meant 'busy_bever' to implement the busy beaver function, said function is in fact not a computable function, which means you can't write it down in a programming language.
Re:Programming Languages Going Above and Beyond by Smaug123 on Thursday June 29, 2023 @05:40PM (#36527137)
This is true but somewhat misleading. The nth busy beaver numbers are known for n <= 4. It's within the bounds of possibility that we will some day learn the nth busy beaver numbers for n <= 10. (What we can say is that the parent's loop will never terminate for any known definition of "ever" that pertains to the physical universe.)
Re:Programming Languages Going Above and Beyond by jjnoakes on Thursday June 29, 2023 @04:30PM (#36526261)
> Tell me when my loop terminates.

I think the point is that even though one can't determine loop termination for all loops (easily provable), there are a huge number of useful loops that do useful work and for which you can prove properties like termination (and other static properties).

Re:Programming Languages Going Above and Beyond by redjamjar on Thursday June 29, 2023 @05:06PM (#36526695)
> there are a huge number of useful loops that do useful work and for which you can prove properties like termination

Exactly! If the loop doesn't terminate, then you obviously cannot show it. But if it does, then you should be able to (even if that requires some changes to help the tool)

Re:Programming Languages Going Above and Beyond by jjnoakes on Thursday June 29, 2023 @06:26PM (#36527681)
> If the loop doesn't terminate, then you obviously cannot show it.

I don't think this is true for all loops either - some can be proven to never terminate, just like some can be proven to terminate. And some can't be proven either way.

Re:Programming Languages Going Above and Beyond by redjamjar on Thursday June 29, 2023 @06:33PM (#36527759)
Yeah, ok that’s fair enough!!
Re:Programming Languages Going Above and Beyond by rockstar-guy-23 on Thursday June 29, 2023 @03:57PM (#36525863)

    while(calculate_pi_stream(10 /* substring length */) != 0987654321);
Re:Programming Languages Going Above and Beyond by redjamjar on Thursday June 29, 2023 @05:07PM (#36526714)
Haha, yeah ... this one you would have a very hard time with :)

Hopefully, though, termination of your program does not depend on this ... otherwise could be a long wait!

Re:Programming Languages Going Above and Beyond by nine_k on Thursday June 29, 2023 @05:22PM (#36526908)
I remember there was a theorem that one can find an arbitrary substring in a long enough output of infinite (stationary) random process. I also suppose that a decimal representation of pi may count as one, then your function provably terminates.

But this is of a theoretic interest. In practice the verifier says: "I can't prove that this function will terminate within (some reasonable window), program rejected". And this is what's actually needed: a program that provably has certain properties, where an automatic proof is tractable.

Re:Programming Languages Going Above and Beyond by xigoi on Thursday June 29, 2023 @06:32PM (#36527748)
It is currently not known whether π is a normal number (that is, its representation in any base contains any finite sequence of digits with the same density as in a uniformly random string of digits).
Re:Programming Languages Going Above and Beyond by littlestymaar on Thursday June 29, 2023 @03:54PM (#36525828)
That's not a very good exemple because with BB we know the code terminates, by definition. The canonical tong-in-cheek argument is to use the Collatz conjoncture instead (but even that isn't a good example in practice: https://news.ycombinator.com/item?id=21440306)
Re:Programming Languages Going Above and Beyond by thr_ddv on Thursday June 29, 2023 @03:56PM (#36525853)
I'm not asking if it terminates, I'm asking when it does. After all it's not much use if the number overflows the universe.
Re:Programming Languages Going Above and Beyond by littlestymaar on Thursday June 29, 2023 @04:37PM (#36526364)
But that's not something these kinds of tools are supposed do, even with trivial functions… These tools have no idea about the run-time (and there's no way they coule, since it depends on the load you put on the hardware in parallel of running your program)
Re:Programming Languages Going Above and Beyond by redjamjar on Thursday June 29, 2023 @05:10PM (#36526748)
I agree. There are tools though which are specifically for determining worst-case execution time for e.g. embedded systems which can actually give accurate timing information (upto a point).
Re:Programming Languages Going Above and Beyond by redjamjar on Thursday June 29, 2023 @05:09PM (#36526730)
Yeah, so these tools will not tell you how long it will take to terminate --- only that it will eventually. In the vast majority of cases, that is what you want to know.
Re:Programming Languages Going Above and Beyond by nine_k on Thursday June 29, 2023 @05:25PM (#36526948)
For practical reasons, it's enough to prove that it takes longer than some upper bound, say, 10 ms. The rest is not important.