3 ms·
The proposed hiding is basically making the caller generic over (and inherit) the effectfulness of the callee. There are probably some FP languages that do this
by anonymoushn 5y ago
The proposed hiding is basically making the caller generic over (and inherit) the effectfulness of the callee. There are probably some FP languages that do this in the general case. Zig can do this for async and for error sets, but you can explicitly opt out of both kinds of hiding if you want to by writing an event loop that uses `resume` but does not use `await` (or uses `nosuspend` when it uses `await`) or specifying your exact error set + handling errors. Lua does this for suspending (and you can opt out with e.g. coroutine.wrap) and errors (and you can opt out using pcall). JavaScript does this for exceptions (and you can opt out by catching them) but not for async.
> you don't need annotation to call an async function, you only need it if you choose to use async syntax in the calling function.
The proposed thing is "I want to get a function, and call it, and use the result, and if it is effectful in a way then I am effectful in that way, and if it is not then I am not" where "the result" is defined (among other things) as the value of the expression that appears in a return statement in the body of the function. Redefining "the result" to be some object representing a continuation or whatever is missing the point.
The lack of async-hiding in JavaScript is why the original "What Color is Your Function?" blog post exists.