fantasyland / fantasy-land

Specification for interoperability of common algebraic structures in JavaScript
MIT License
10.13k stars 376 forks source link

Feedback from the outside #51

Closed jasonkuhrt closed 10 years ago

jasonkuhrt commented 11 years ago

I feel like I am entering the depths of a seldom visited rocky recess. Hello.

I have been diving into functional paradigms, increasingly, for at least a year. I am interested in and actively trying to author my javascript-based work with a functional hand.

Given this, I felt quite lucky to fall upon this [Fantasy Land] project given it appears to be helping translate ideas from purer languages into javascript.

Language-wise I have focused my functional learning efforts to date on Haskell, because it/its community appears to tackle the matter rigorously and have pioneered certain or many functional programming breakthroughs.

I was surprised to find however that fantasy-land terminology differs from haskell's insofar as option instead of maybe, and moands wherein I know they require a return (sometimes called unit) and bind method but I've only seen of and chain mentioned in Fantasy Land (Still not sure but I'm assuming of === return and chain === bind?).

Is this spec going against conventional functional naming or is it Haskell that deviates?

jasonkuhrt commented 11 years ago

Certainly appears that its Fantasy Land deviating in terminology: http://en.wikipedia.org/wiki/Monad_(functional_programming)

Twisol commented 11 years ago

I believe the Fantasy Land terminology is meant to be more approachable to the lay programmer, and adapt it to a more natural style in Javascript. of and chain are more suggestive than return and bind, especially considering those words are already used for separate concepts.

Option and Maybe is more of a toss-up. Both are in use elsewhere though; for example, Scala uses Option.

jasonkuhrt commented 11 years ago

Option and Maybe is more of a toss-up. Both are in use elsewhere though; for example, Scala uses Option.

Yeah, I see. But still, Maybe is the term I've seen used more at least in the javascript community.

I believe the Fantasy Land terminology is meant to be more approachable to the lay programmer, and adapt it to a more natural style in Javascript.

The of/chain "naturalizations" are for a non-audience, and are to the the detriment of your actual potential community, this I have no doubt.

Firstly what is a "lay programmer" insofar as what concepts fall in and out of that umbrella? Second, this spec covers topics that are far from the the lay programmer of the javascript community wherein by that I mean examining the code in packages across npm and bower and component etc surely demonstrate that the entire foundation of Fantasy Land is far-and-away different than the typical JavaScript programming. Thus, I find it odd to say the least that of and chain is where the "naturalization" starts.

Further, its actually counter-intuitive. JavaScript programmers that are actually taking the time to study functional paradigms, and maybe its mathematical foundations (Category theory in particular), etc. are just going to be confused and turned off by this spec if of and chain are any indication.

http://www.youtube.com/watch?v=dkZFtimgAcM http://modernjavascript.blogspot.ca/2013/06/monads-in-plain-javascript.html http://functionaljavascript.blogspot.ca/2013/03/implementing-monads-in-javascript.html http://stackoverflow.com/questions/8656172/monads-in-javascript http://igstan.ro/posts/2011-05-02-understanding-monads-with-javascript.html which is referenced by @fogus, the author of http://blog.fogus.me/2013/03/20/fun-js/ etc

If there is concern over the fact that JavaScript has already labeled bind in the Function.prototype.bind I think its an acceptable tragedy. It seems to me that Function.prototype.bind is only useful for assigning this context which shouldn't matter when working functionally as this simply stands to make life harder in every way for functional style. Once you remove this as a feature (Lint it away, etc) Function.prototype.bind can cease to exist and we can move on with functional life.

Twisol commented 11 years ago

Well, I may have thrown out the "lay programmer" label a bit casually. I apologize for that - let me try to explain myself better.

Personally, I like the Fantasy Land naming because it aligns more naturally with how I've internalized Monads. I believe that "chaining" is a fairly intuitive action, and can be readily comprehended without much fanfare. of is likewise a glorified constructor. Of course monads have a wealth of mathematical structure to them, but at times when I'm using them in a practical setting, I think of them in terms of what they can do for me. I suspect many programmers act similarly. So I find it a big plus to have the terminology and intuition align.

Yeah, I see. But still, Maybe is the term I've seen used much more, including in the javascript community.

I prefer Maybe in this instance, but I think the ship may have sailed on that one.

jasonkuhrt commented 11 years ago

I think we're having two separate conversations. You're talking about what works for you personally, in isolation, and I'm trying to talk about what works in the context of most anyone else who is learning and using functional programming. Had Fantasy Land invented Monad's they would be free to codify the terminology, but that is not the case.

jasonkuhrt commented 11 years ago

Anyhow bind and unit are intuitive too. unit for instance is about bringing values into the fold, .e.g:

cm.unit(5) -> 5cm
SimonRichardson commented 11 years ago

Yeah, I see. But still, Maybe is the term I've seen used much more, including in the javascript community.

I prefer Maybe in this instance, but I think the ship may have sailed on that one.

I do wonder about the collision of HTMLOptionElement via the Option shortcut in the browser side in terms of code & conceptually for javascript programmers. Although it becomes moot point when you use modules and you can do this (but this ends up with a mix of both Maybe and Option), but is this worse...?

var Maybe = require('fantasy-options');
Maybe.Some(1);

I personally don't mind renaming Option to Maybe including the constructors, but like @Twisol pointed out, the ship might have sailed?

puffnfresh commented 11 years ago

A monad has been known as:

The of transformation has been known as:

The chain transformation has been known as:

Anyway, names:

'Tis but thy name that is my enemy; Thou art thyself, though not a Montague. What's Montague? it is nor hand, nor foot, Nor arm, nor face, nor any other part Belonging to a man. O, be some other name! What's in a name? that which we call a rose By any other name would smell as sweet; So Romeo would, were he not Romeo call'd, Retain that dear perfection which he owes Without that title. Romeo, doff thy name, And for that name which is no part of thee Take all myself.

alexanderkjeldaas commented 10 years ago

Bikeshedding a bit. If only the documentation clearly states that of == return and chain == bind, then Haskellers should have no problem. I think this needs to go into the documentation to avoid confusion.

Another thing is that for example lodash is using "redirects" in their documentation to make it easy for people who are used to different names.

Overloading bind in javascript seems like an extremely bad idea.

SimonRichardson commented 10 years ago

We accept pull requests ;-)

SimonRichardson commented 10 years ago

Closing this, as it's seems to be resolved. Provide feedback otherwise :-)

jasonkuhrt commented 10 years ago

Cheers