Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

In Monad & Functor laws, what does "equals" mean? #4

Closed
kennknowles opened this issue Apr 12, 2013 · 7 comments
Closed

In Monad & Functor laws, what does "equals" mean? #4

kennknowles opened this issue Apr 12, 2013 · 7 comments
Labels

Comments

@kennknowles
Copy link
Contributor

This is one half JS joke and one half math joke.

But even so, I'm only half joking. Maybe it would be good to spell it out, since you probably mean a kind of extensional equality that Javascript is not powerful enough to express.

@puffnfresh
Copy link
Member

Yes. This is tricky.

@kennknowles
Copy link
Contributor Author

Importing discussion with @Twisol about equality and the event loop.

My understanding of what has been said:

  • Promises/A+ forbids the argument to then to be called synchronously.
  • Depending on the notion of equality, the monad laws may require the argument to then to be called synchronously.
  • @Twisol has experienced challenges that led to distinguishing Present and Future promises, in order to have predictable ordering of side effects.

My suggestion is to work out a notion of equality for promises that allows the laws to hold regardless of synchrony, and to order side effects with the usual concurrency control mechanisms. The notion of equality must not forbid such mechanisms from working - waiting on a mutex before delivering a value should be equivalent to delivering it immediately.

The implication for Fantasy Land is simply that equality should be defined by the monad/functor/values in question, and that side effects remain up to the programmer to sort out.

@Twisol
Copy link

Twisol commented Apr 12, 2013

Just to clarify, you advocate pushing the issue of side-effects downstream to the individual monad implementations?

@kennknowles
Copy link
Contributor Author

Exactly.

@Twisol
Copy link

Twisol commented Apr 12, 2013

Okay. I don't really have a problem with that, but I would hate to see a monad implementation that didn't adequately address it somehow.

@kennknowles
Copy link
Contributor Author

I agree with the concern. In the case of promises + concurrency side effects the two are clearly intimately related so worth discussion in the docs for any implementation of promises.

But I would expect most monad implementations to pass the buck downstream to users, especially data-oriented monads such as List, Maybe, Either, or the free monad. Wouldn't make much sense to talk about side effects in those cases; hopefully programmers know what they are getting into when they use side-effects in a list comprehension (I do this all the time via knockout + underscore).

But I want to emphasize that this issue is a necessary discussion in all cases, even the very simple ones, because [1, 2, 3] === [1, 2, 3] is false, as is {inLeft: 1} === {inLeft: 1}

@Twisol
Copy link

Twisol commented Apr 12, 2013

That's fair. I think we should have a section of the spec on things that must be addressed somehow downstream, even if we don't prescribe a particular approach. These things seem to come up because of the imperative domain, and they can't be naively ignored.

paldepind pushed a commit to paldepind/fantasy-land that referenced this issue Apr 30, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants