Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

So much work to implement the monad type class


I don’t think this implements anything monad shaped


Async is monad shaped. Not-async is monad-shaped, for a degenerate monad. Writing a function that works in both async and not-async contexts just means writing a function that works for any monad.


Not really; the problem is that languages with IO monads often provide a runtime that can schedule IO-ful things concurrently (or, in Haskell's case, lazily) based on the type. Python has no such scheduler; users have to run their own in the form of an async-capable event loop or a sequential (threadpool/processpool) executor for blocking code.

Because of that missing runtime for scheduling and evaluating IO-ful things, tools like superfunctions are necessary.

In other words: IO monads are only as useful as the thing that evaluates them; Python doesn't have a built-in way to do that, so people have to make code that looks "upward" to determine what kind of IO behavior (blocking/nonblocking/concurrent/lazy/etc.) is needed.


If you want a function to be usable in both an async and a non-async environment, the monads in question are ones for async and identity, not IO. The choice between a true concurrent runtime and a single threaded cooperative coroutine runtime is up to you in GHC Haskell.

Monad-agnostic functions are exactly looking upwards to allow the calling context to determine behaviour.


Nothing to do with that or the IO monad. 'Async' contexts are continuation transformers over generic underlying monads that satisfy certain constraints. Don't get confused between the two.


You frame that as if python doesn’t have a choice, but it chose to have explicit syntax.

There’s no reason a python-like language couldn’t have deeper semantics for async, and language level implementation.


Well, there aren't reasons why Python couldn't have that, but there certainly are good reasons why the Python maintainers decided that type of runtime was not appropriate for that specific language--not least among them that maintaining a scheduling/pre-empting runtime (which is the only approach I'm aware of that works here without basically making Python into an entirely unrelated language) is very labor intensive! There's a reason there aren't usable alternative implementations of ERTS/BEAM, and a reason why gccgo is maintained in fits and starts, and why the Python GIL has been around for so long. Getting that type of system right is very, very hard.


> maintaining a scheduling/pre-empting runtime (which is the only approach I'm aware of that works here without basically making Python into an entirely unrelated language) is very labor intensive! There's a reason there aren't usable alternative implementations of ERTS/BEAM […]

You seem to know a lot about PL. Could you elaborate on that reason and on the maintenance burden of a preemptive runtime?




Consider applying for YC's Winter 2027 batch! Applications are open till November 2.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: