Live data from Hacker News

What color is your function? (2015)

journal.stuffwithstuff.com

11–20 of 63 posts

Re: What color is your function? (2015)

#11

In previous threads I haven't seen an in-depth discussion of algebraic effects as a solution to this problem, i.e. composing arbitrarily-many 'red' functions. Thoughts?

The danger is that declaring too much at the API boundary makes the problem worse. Declared effects result in more ways that API’s can be incompatible and fewer ways that an implementation can change without breaking compatibility.

Re: What color is your function? (2015)

#13
There can be very specific exceptions. In C# Winforms code I wrote, I have data loading code which I made async, called from UI code that was not. You need a running messageloop which was provided by a modal progress bar. Users could cancel the async code from the dialog. In the real world it is a quite a typical example where you want to call async code from non-async.

Re: What color is your function? (2015)

#15
post #14

Two years after this article was written, async-await was introduced in Javascript as a solution to this problem. As far as I understand.

Nope, async-await isn’t a solution to the problem, its just a slightly less annoying syntax sugar for defining and calling “red” functions, to which everything in the article applies.

Re: What color is your function? (2015)

#16

In previous threads I haven't seen an in-depth discussion of algebraic effects as a solution to this problem, i.e. composing arbitrarily-many 'red' functions. Thoughts?

I’m thinking your reference to composing red functions doesn’t seem congruent with your desire to discuss algebraic effects. Composing arbitrarily many red functions, or blue functions, is a solved problem. (I won’t mention the lingo knowing many in the audience to be allergic.) Composing functions with heterogenous, or completely arbitrary, colors is much less so. That’s what the article is about, too, is it not - combining blue and red? But I might well be missing something deeper here, perhaps you’ll enlighten the reader :)

I would be really keen on seeing a mainstream-ish language that does algebraic effects or that can even implement them in a legitimate sense (discounting React’s implementation here, for instance). Purescript tried, but are doing something different these days. https://purescript-resources.readthedocs.io/en/latest/eff-to...

Re: What color is your function? (2015)

#17
I might be showing my inexperience here, but my understanding of async/await and promises in JS is that they create threads under the hood to solve the problem the author is talking about.

I'm afraid I just don't quite understand why async/await don't solve the problem and instead sweep it under the rug, could someone explain it?

Re: What color is your function? (2015)

#18
In Python at least, you can easily call an async function from a sync function:

    result = asyncio.run_until_complete(func)
Also, having explicit async/await are a wait to tell you: here are the point in your code that have something doing unreliable side effects down there.

You can then use this information to:

- move that code and group it, so you get the rest of the code sansIO style

- put that in a try/except, because this code WILL fail at some point

- think about the perfs of this part of your code, which is what you are doing async io the first place

I do wish that python coro would schedule themself automatically, like JS does, and return a future that you can await explicitly. But that ship as sailed.

Post reply on HN