Live data from Hacker News

JavaScript Promises Discussion: Make Them Monadic? (2013)

github.com

61–70 of 79 posts

Re: JavaScript Promises Discussion: Make Them Monadic? (2013)

#61
post #51
post #49

Earlier quoted context omitted.

whats a better term here?

Contextual functions maybe? For orthagonal, it's often used to mean "unrelated". Immutable could be "fixed", "constant" or any number of other more pedestrian terms.

Just use the word that means the thing that you're talking about, as clearly as you can. What "clear" means depends on the context and audience.

It sounds like you probably already know this, but "fixed" and "constant" usually refer to concepts very distinct from "immutable". And "contextual function" would confuse everyone. (A monad isn't a function, and certainly not one influenced by some outer context). Similarly, "orthogonal" and "unrelated" aren't synonyms. (X and Y axes are orthogonal, but they're often related. That's why we plot things).

In every field, there will be people who over-use technical terms for status signaling. But those terms usually exist for a reason beyond that, and avoiding them as a sort of counter-signaling doesn't help anyone. It's just playing the other side of that game.

Usually the common term means the same things as a lot of things…that's both why they're common, and why they're less useful in a technical context.

Some other examples that come to mind are "electricity" (current, voltage, power…?); "size" (area, volume, mass…?). Just because an engineer or physicist might talk about volume doesn't mean you have to be a physicist to talk about it too. It also doesn't mean that, not being a physicist, the familiar word "size" means the same thing they're talking about.

Re: JavaScript Promises Discussion: Make Them Monadic? (2013)

#62
post #61
post #51

Earlier quoted context omitted.

Contextual functions maybe? For orthagonal, it's often used to mean "unrelated". Immutable could be "fixed", "constant" or any number of other more pedestrian terms.

Just use the word that means the thing that you're talking about, as clearly as you can. What "clear" means depends on the context and audience. It sounds like you probably already know this, but "fixed" and "constant" usually refer to concepts very distinct from "immutable". And "contextual function" would confuse everyone. (A monad isn't a function, and certainly not one influenced by some outer context). Similarly…

That's fair, but these terms are leaking out to business analysts, project managers, product managers, and customers. They have no idea what we're talking about. My weak attempts at synonyms might be attackable, buy we're coming across as elite bullshitters. I'd love something that was more consumable for the common person.

Re: JavaScript Promises Discussion: Make Them Monadic? (2013)

#63
post #26
post #22

I'm confused, and am not very knowledgeable about FP (though I am very interested in it). Can anyone explain how the 3 bullet points in the issue aren't already in Promises? > Promise.of(a) will turn anything into promise. This just looks like `Promise.resolve(a)` > Promise#then(f) should take one function, not two. That's applicable, but you could try limiting yourself to only using one argument. > Promise#onRejecte…

The issue with `of` is that it special cases when `a` is already a Promise. Promises try hard to not be nested (a promise of a promise) but that nesting is critical for algebraic properties. The then issue is multifarious. On one side, splitting the two uses makes the algebraic justification for then more clear, but it's not a big deal. The real issue is that `then(f)` does different things when `f` returns a Promise…

That just raises more questions. Can anyone here give a concrete example of a real world problem that is more cleanly solved with these changes to the Promise spec?

There's a lot of talk about FP and type theory here, and none about actual work. To me, all this stuff is still in the "cool to play around with at home" category. But until it affects day to day dev work, there's a whole set of people that aren't going to give the slightest fuck.

Re: JavaScript Promises Discussion: Make Them Monadic? (2013)

#64
post #60
post #59

Earlier quoted context omitted.

You're just inventing your own terms no one else uses. There's a page called "Monad (functional programming)" on Wikipedia https://en.wikipedia.org/wiki/Monad_(functional_programming) suggesting that the term "moand" or "moandic" is widely used and understood. There's no page called "contextual function." There's a page called "Orthogonality (programming)" on Wikipedia https://en.wikipedia.org/wiki/Orthogonality_(pro…

I do respect your viewpoint. But immutable and orthagonal are just weird jargon to my project managers, product managers, analysts, customers, etc. For me, it's somewhat equivalent to odd terminology that probably irritates you from the business like "synergy" or "paradigm", or "incentivise" From the tech side, we parody those terms. Rest assured, business folks parody us for our monads, immutables, etc. It makes us…

> Basically, I want to stop alienating project managers, product managers, and customers with weird jargon.

The things you might need jargon for are things that they shouldn't have to concern themselves with. If you use more familiar words but arrange them in unfamiliar ways, you'll cause the same confusion as by using jargon, except someone might believe they understood when they really didn't.

If you feel like you need to refer to programming concepts when talking to non-technical people, you're doing it wrong. Instead of talking about "immutable"/"constant"/"fixed", say that you made changes to prevent data from being altered accidentally. That's something they care about, not how exactly you did it.

Re: JavaScript Promises Discussion: Make Them Monadic? (2013)

#65
post #64
post #60

Earlier quoted context omitted.

I do respect your viewpoint. But immutable and orthagonal are just weird jargon to my project managers, product managers, analysts, customers, etc. For me, it's somewhat equivalent to odd terminology that probably irritates you from the business like "synergy" or "paradigm", or "incentivise" From the tech side, we parody those terms. Rest assured, business folks parody us for our monads, immutables, etc. It makes us…

> Basically, I want to stop alienating project managers, product managers, and customers with weird jargon. The things you might need jargon for are things that they shouldn't have to concern themselves with. If you use more familiar words but arrange them in unfamiliar ways, you'll cause the same confusion as by using jargon, except someone might believe they understood when they really didn't. If you feel like you…

>The things you might need jargon for are things that they shouldn't have to concern themselves with.

Sure, but they become terms in titles of change requests, features, bug fixes, etc. It leaks out whether I want it to or not. And customers ask "what does this mean?" Or sometimes, forgivable but less polite equivalents.

Re: JavaScript Promises Discussion: Make Them Monadic? (2013)

#66
post #10

For those looking for monadic Promises, I’d suggest taking a look at Fluture ( https://github.com/fluture-js/Fluture ). It’s a wonderful library and with do-notation, ability to work with callbacks, nodebacks, and Promises, I haven’t looked back. It also has adheres to Fantasy Land, Static Land, and has defintions for santuary-def.

> It also has adheres to Fantasy Land, Static Land, and has defintions for santuary-def. I think I understood a couple words in that sentence, like "it" and "has". :P Looking up fantasy-land, I found https://github.com/fantasyland/fantasy-land . I would like to better understand these monads everyone is talking about. But, just to be super honest -- and possibly completely wrong -- the terminology is really off-putti…

First, going straight to "How do I understand Monads?" is not a good idea. I remeber when this article showed up on the web, and I remember wishing it had been written before I started learning Haskell:

https://byorgey.wordpress.com/2009/01/12/abstraction-intuiti...

If you want to understand monads, start hacking and watch for patterns.

> But, just to be super honest -- and possibly completely wrong -- the terminology is really off-putting. At a glance it just feels super complex, academic and completely divorced from practical coding. I get vibes of enterprise java class hierarchies looking at this stuff.

Yeah, and here's my take on why it looks like that:

First, the terminology is all borrowed from mathematics, hence the academic tone. People can debate on the merits of this; I think it makes more sense when you're making tools for folks who are already familiar with the usual notation, but e.g. if you're not dealing with people who are already accustomed to the way physisicts talk about things, "p" is probably not the best variable name for momentum, traditional as it may be.

The authors of that document seem to have gone even farther in that direction than the Haskell folks -- Setoid? really? It's just fing equals! even Haskell calls it Eq. At least they kept Ord.

Also, the design looks to be basically transliterated from Haskell. There's been no attempt to adapt it to either javascript's strengths or its weaknesses. For example: Conceptually a monoid is a special case of a category, but it's fiddly to abstract out the commonalities in Haskell because of the way the type system works. In javascript you could basically collapse the two, with id == empty and concat == compose. You might still want a blurb in there somewhere about the differences; not every category is a valid monoid, but there's no reason to have a whole separate hierarchy with different method names. * The whole TypeRep thing they talk about is a complication that is unnecessary in Haskell; having methods that aren't attached to an extant value is just a non-issue, because the compiler can figure out which one you mean based on the types.

The libraries were designed around Haskell, and they lose something in translation. One of the things that kept in that thread was why not build some experience using these patterns before writing a spec? I tend to agree.

The other thing is that it is a big pile of abstractions. Even when working in Haskell, though I am more or less familiar with all of the type classes on that chart, I've only really had call to use 9 of them. Including Eq(Setoid) and Ord. The abstractions can definitely get to be a bit much.

There is some real use for this stuff; here's one I find kindof shiny:

https://apfelmus.nfshost.com/articles/monoid-fingertree.html

...but I would say these abstractions are as applicable to day to day programming as the rest of computer science -- no more and no less.

I'm with you on the complexity allergy thing. Lately I've been doing some stuff in elm[1], and the simplicity has been a wonderful breath of fresh air coming from Haskell. I might recommend it if you're curious about functional programming. Some of the same ideas are sprinkled throughout the libraries; every time you see a function called "andThen," there's a monad lurking there, but because elm doesn't have type classes, you won't find anything called Monad. The flip side is you end up writing more boilerplate than you would in a language that can abstract these things away.

[1]: http://elm-lang.org/

Re: JavaScript Promises Discussion: Make Them Monadic? (2013)

#67
post #23
post #10

Earlier quoted context omitted.

> It also has adheres to Fantasy Land, Static Land, and has defintions for santuary-def. I think I understood a couple words in that sentence, like "it" and "has". :P Looking up fantasy-land, I found https://github.com/fantasyland/fantasy-land . I would like to better understand these monads everyone is talking about. But, just to be super honest -- and possibly completely wrong -- the terminology is really off-putti…

"Once you understand monads, you immediately become incapable of explaining them to anyone else” Lady Monadgreen’s curse ~ Gilad Bracha" If you'd like to go down a rabbit hole of category theory look up the phrase "A monad is just a monoid in the category of endofunctors, what's the problem?" - a fun quote that a lot of monad explanatory tutorials will quip. Not that it will help - because anyone writing a monad expl…

rmrfrmrf made an allusion to this below (which I also linked to in another nearby comment):

https://byorgey.wordpress.com/2009/01/12/abstraction-intuiti...

The short version is: don't stare at explanations trying to grok it. Start hacking and keep an eye out for patterns.

Re: JavaScript Promises Discussion: Make Them Monadic? (2013)

#68
post #63
post #26

Earlier quoted context omitted.

The issue with `of` is that it special cases when `a` is already a Promise. Promises try hard to not be nested (a promise of a promise) but that nesting is critical for algebraic properties. The then issue is multifarious. On one side, splitting the two uses makes the algebraic justification for then more clear, but it's not a big deal. The real issue is that `then(f)` does different things when `f` returns a Promise…

That just raises more questions. Can anyone here give a concrete example of a real world problem that is more cleanly solved with these changes to the Promise spec? There's a lot of talk about FP and type theory here, and none about actual work. To me, all this stuff is still in the "cool to play around with at home" category. But until it affects day to day dev work, there's a whole set of people that aren't going t…

> But until it affects day to day dev work, there's a whole set of people that aren't going to give the slightest fuck.

That's a seriously toxic attitude to have.

People are using monads and other FP concepts daily to simplify "day to day dev work" (here's an example [0].) The fact that it's more or less mainstream to write off a concept because it sounds "academic" is worryingly anti-intellectual in a profession that is allegedly based in analytical thinking.

> Can anyone here give a concrete example of a real world problem that is more cleanly solved with these changes to the Promise spec?

There are some in the linked github thread (which had to be reposted repeatedly until people actually stopped and read them, btw.) It's about being able to write DRY code that abstracts over not only promises, but anything else that forms a monad, like arrays, optional values, and so on.

[0] https://github.com/facebook/Haxl

Re: JavaScript Promises Discussion: Make Them Monadic? (2013)

#69
post #38

Earlier quoted context omitted.

As already mentioned, they're a lot better than callbacks (well, for certain cases. There are still places where callbacks are better). The problem is that this is a field that has been heavily studied, and there are great solutions to this problem that also solve countless other problems, and interop well with each other. The way promises work, they solve that ONE problem but throw away the rest. If you have the cho…

> There are still places where callbacks are better) Like? I am genuinely interested in knowing the drawbacks of promises and places where a callback like structure is more favourable. By the way, I am not contradicting you, just trying to learn.

foo.map(x => x * 2);

Not sure I'd want to use a promise there :)

Re: JavaScript Promises Discussion: Make Them Monadic? (2013)

#70
post #38

Earlier quoted context omitted.

As already mentioned, they're a lot better than callbacks (well, for certain cases. There are still places where callbacks are better). The problem is that this is a field that has been heavily studied, and there are great solutions to this problem that also solve countless other problems, and interop well with each other. The way promises work, they solve that ONE problem but throw away the rest. If you have the cho…

> There are still places where callbacks are better) Like? I am genuinely interested in knowing the drawbacks of promises and places where a callback like structure is more favourable. By the way, I am not contradicting you, just trying to learn.

A promise can only be activated once. You still have to use callbacks for buttons and other things that can be activated more than once.
Post reply on HN