tag:blogger.com,1999:blog-9210025386133363283.post5338897819959493424..comments2017-07-21T02:19:52.099-07:00Comments on Modern JavaScript: Monads in plain JavaScriptRhys Brett-Bowennoreply@blogger.comBlogger13125tag:blogger.com,1999:blog-9210025386133363283.post-39204551801930108572016-08-10T04:21:51.714-07:002016-08-10T04:21:51.714-07:00Regardless of some of the criticism regarding the ...Regardless of some of the criticism regarding the details of your examples in the comments here, you communicated the general concepts quite clearly and I for one greatly appreciate this well-thought post!Franklinhttp://www.blogger.com/profile/12125367865221040103noreply@blogger.comtag:blogger.com,1999:blog-9210025386133363283.post-6932837432249588992016-03-14T01:46:59.705-07:002016-03-14T01:46:59.705-07:00Great and Useful Article.
Javascript Training in ...Great and Useful Article.<br /><br /><a href="http://wisentechnologies.com/it-courses/html-css-javascript-jquery-training.aspx" title="Javascript Training in Chennai" rel="nofollow">Javascript Training in Chennai</a> | <a href="http://wisentechnologies.com/it-courses/html-css-javascript-jquery-training.aspx" title="Javascript Online Training" rel="nofollow">Javascript Online Training</a><br /><a href="http://javascripttrainingcourses.com" title="JavaScript Training Courses" rel="nofollow">JavaScript Training Courses</a> | <a href="http://javascripttrainingcourses.com" title="Javascript Online Training India" rel="nofollow">Javascript Online Training India</a> | <a href="http://javascripttrainingcourses.com" title="Javascript Online Training" rel="nofollow">Javascript Online Training</a>Annahttp://www.blogger.com/profile/00832987513799080883noreply@blogger.comtag:blogger.com,1999:blog-9210025386133363283.post-83226547273706630872014-08-29T11:19:04.493-07:002014-08-29T11:19:04.493-07:00Nice try, but no monad :-) You may want to check o...Nice try, but no monad :-) You may want to check out the gist proposed in the second comment.faustinellihttp://faustinelli.wordpress.com/noreply@blogger.comtag:blogger.com,1999:blog-9210025386133363283.post-53031709749102864852014-08-29T11:09:41.065-07:002014-08-29T11:09:41.065-07:00"A monad is just a container."
"M..."A monad is just a container." <br /><br />"Monads are something called a "functor" which basically is a "functional object"". <br /><br />"...a lifted bind". (a WHAT?!?!?)<br /><br />I am afraid your grasp on this subject cannot be sound, as long as you come out with such flawed assertions.<br /><br />Unsurprisingly, one sees at a glance that your implementations of return and bind are simply, plainly ...wrong.<br /><br />I say that the code you present in this page won't pass any of the monad laws proofs and that the only value that a reader can take away from this page is what derives from understanding its fallacies.<br /><br />Allegedly you've spent some time on Crockfords code. I suggest you get back there and give it a good study again. To convince yourself of the value of my suggestion, you may want to start by comparing the results of basic Maybe computations produced by his code and yours. Cheers.faustinellihttp://faustinelli.wordpress.com/noreply@blogger.comtag:blogger.com,1999:blog-9210025386133363283.post-44978162678576106472013-11-04T07:17:16.550-08:002013-11-04T07:17:16.550-08:00At the risk of making myself look stupid, here'...At the risk of making myself look stupid, here's one of my recent attempts at something similar to the Maybe monad. I've written the code in CoffeeScript for ease of writing. For this exercise I focussed on a use case - retrieving an object's property value that may, or may not, exist.<br /><br />Anyway, here's the link to the repo: https://github.com/KarlPurk/maybe<br /><br />I would love to hear feedback, even if it's simply stating how this implementation is not a Maybe Monad :)Karlhttp://karlpurk.com/noreply@blogger.comtag:blogger.com,1999:blog-9210025386133363283.post-19250117857958661122013-06-09T23:47:56.194-07:002013-06-09T23:47:56.194-07:00A CoffeeScript version of your code:
https://gist....A CoffeeScript version of your code:<br />https://gist.github.com/jiyinyiyong/5746958题叶http://www.blogger.com/profile/08163086302778535633noreply@blogger.comtag:blogger.com,1999:blog-9210025386133363283.post-47758848608187681222013-06-09T16:35:32.529-07:002013-06-09T16:35:32.529-07:00I am bit confused, was the intention of your post ...I am bit confused, was the intention of your post to explain what a Monad is or to show how to do it in JS? I have not used Monads, so I got lost when you started talking about lift. The paragraphs about lift could be clearer and provide more context. Thanks for the post anyway.Sebastianhttp://www.blogger.com/profile/04353296665849180905noreply@blogger.comtag:blogger.com,1999:blog-9210025386133363283.post-1797959198787938272013-06-08T10:50:11.977-07:002013-06-08T10:50:11.977-07:00Unfortunately, this is not a correct implementatio...Unfortunately, this is not a correct implementation of a monad. Think about the signatures of the two functions (in Haskell):<br /><br />> :t (>>=)<br />(>>=) :: Monad m => m a -> (a -> m b) -> m b<br />> :t (return)<br />(return) :: Monad m => a -> m a<br /><br />I'm not sure if you understand Haskell code, but the main point is that both `bind` and `ret` should return a Monad again. In your case, both of them return the type of `this.value`, except when you call `fn`, in which case they return whatever `fn` returns, which *must* be a monad according to the types.<br /><br />Here's my take on it: https://gist.github.com/igstan/5735974<br /><br />The null-checking logic resides in two places:<br /><br /> 1. the Option function<br /> 2. the dynamic dispatch mechanism, which will chose the approapriate<br /> implementation of `bind` or `unit` at runtime.<br /><br /><br />Also, Monad "inherits" (or at least, it should) from Functor. A functor is just a data type which can be mapped over, i.e. it provides a `map` method. That's all.<br /><br />> :t fmap<br />fmap :: Functor f => (a -> b) -> f a -> f b<br /><br />Hope it helps! And maybe you should try to implement the List monad now that you know the type constraints.<br />Ionuț G. Stanhttp://www.blogger.com/profile/10325171641002588574noreply@blogger.comtag:blogger.com,1999:blog-9210025386133363283.post-76681781035162345922013-06-06T01:04:12.800-07:002013-06-06T01:04:12.800-07:00Can be accomplished by having value being a protec...Can be accomplished by having value being a protected property. All Methods must then use <br />privileged method Monad#ret instead of accessing Monad#value directly<br />Juri Leinohttp://www.blogger.com/profile/13667274295555682333noreply@blogger.comtag:blogger.com,1999:blog-9210025386133363283.post-85387932484758278512013-06-05T07:29:06.873-07:002013-06-05T07:29:06.873-07:00such is JavaScript. The aim of this is not to be p...such is JavaScript. The aim of this is not to be perfect but provide enough for a basic understanding. I'm aiming for usefulness rather than purity in this definition.Rhys Brett-Bowenhttp://www.blogger.com/profile/05642824819846878549noreply@blogger.comtag:blogger.com,1999:blog-9210025386133363283.post-34158362255968652002013-06-05T06:39:41.103-07:002013-06-05T06:39:41.103-07:00The errors are solved but the "monads" s...The errors are solved but the "monads" still don't work as expected. "m1.value = 5;" shouldn't be possible with a monad.Steven Devijverhttp://www.blogger.com/profile/00266604388885615546noreply@blogger.comtag:blogger.com,1999:blog-9210025386133363283.post-55742552193428928862013-06-05T06:07:26.990-07:002013-06-05T06:07:26.990-07:00Thankyou - I guess I should test my code before pu...Thankyou - I guess I should test my code before putting it up online. I needed to put the "new Maybe" down a line, it should work as intended nowRhys Brett-Bowenhttp://www.blogger.com/profile/05642824819846878549noreply@blogger.comtag:blogger.com,1999:blog-9210025386133363283.post-73920689335617273612013-06-05T02:43:51.341-07:002013-06-05T02:43:51.341-07:00In snippet 4 you open two curly brackets but close...In snippet 4 you open two curly brackets but close only one. In snippet 7, line 7 there's a closing parentheses missing. Snippet 8 line 8 doesn't work. "liftM2Add(m1,m2)" results in an error. "liftM2Add.value(m1, m2)" works.Steven Devijverhttp://www.blogger.com/profile/00266604388885615546noreply@blogger.com