← Back to context

Comment by anon291

20 days ago

There is an implied order of operations in Haskell. Haskell always reduces to weak head normal form. This implies an ordering.

Monads have nothing to do with order (they follow the same ordering as Haskell's normalization guarantees).

> JavaScript decided to standardize on a Monad-shaped "thenable" specification for representing asynchronous processes,

Its impossible for something to be monad shaped. All asynchronous interfaces form a monad whether you decide to follow the Haskell monad type class or decide to do something else. They're all isomorphic and form a monad. Any model of computation forms a monad.

Assembly language quite literally forms a category over the monoid of endo functors.

Jacquard loom programming also forms a category over the monoid of endo functors because all processes that sequence things with state form such a thing, whether you know that or not.

It's like claiming the Indians invented numbers to fit the addition algorithm. Putting the cart before the horse, because all formations of the natural numbers form a natural group/ring with addition and multiplication formed the standard way (they also all form separate groups and rings, that we barely ever use).

> All asynchronous interfaces form a monad whether you decide to follow the Haskell monad type class or decide to do something els

JS's then is categorically not a monad because it doesn't follow the monad laws.

fn1 : a -> Promise<b>

fn2 : b -> c

fn3 : b -> Promise<c>

With JavaScript, composing fn1 and fn2 with then gives you a -> Promise<c>. So then is isomorphic to map.

With JavaScript, composing fn1 and fn3 with then gives you a -> Promise<c>. So then is isomorphic to flatmap.

Therefore, with JavaScript, map is isomorphic to flatmap. Which obviously violates monad laws.

There's a rather famous Github issue where someone points this out in the issue tracker for `then` development, and one of the devs in charge of then...leaves responses for posterity.

  • I mean, JavaScript is weakly typed and then always lifts its argument. Speaking of isomorphism doesn't make sense unless you're talking about a typed portion of the language.