tag:blogger.com,1999:blog-178174920347765771.post1560748452919590443..comments2023-10-30T09:20:21.742-07:00Comments on One Div Zero: Monads are Elephants Part 3James Iryhttp://www.blogger.com/profile/02835376424060382389noreply@blogger.comBlogger19125tag:blogger.com,1999:blog-178174920347765771.post-24127053505011630182013-08-05T03:16:00.536-07:002013-08-05T03:16:00.536-07:00After 7 years these 4 posts are still remarkably u...After 7 years these 4 posts are still remarkably useful. If you still feel like maintaining them, I have two observations:<br /><br />1) the definition of M3b should contain an "b <- g(a)" and not "b < g(a)"<br />2) as corollary of the second monad law, you showed that "unit map f = unit f", but not that "unit map g map f = unit f g". On step 5 in theMuziettonoreply@blogger.comtag:blogger.com,1999:blog-178174920347765771.post-16164970521128329282013-03-24T00:30:58.553-07:002013-03-24T00:30:58.553-07:00Great explanation, loving the entire series. Just ...Great explanation, loving the entire series. Just wanted to add that if someone got confused (like me) over the second monad law<br /><br />unit(x) flatMap f = f(x) <br /><br />just remember that f is a monadic function returning M[A] which is why the law holds more at SO<br /><br />http://stackoverflow.com/questions/10949328/second-monad-lawunitBasavaraj Kallolinoreply@blogger.comtag:blogger.com,1999:blog-178174920347765771.post-12578323846064069392011-10-10T19:08:09.463-07:002011-10-10T19:08:09.463-07:00In your cheat sheet you have "plus" but ...In your cheat sheet you have "plus" but there isn't a general translation "mplus" in Scala, or is there? Option has orElse, List has ++.Eric Pedersonhttp://twitter.com/ericacmnoreply@blogger.comtag:blogger.com,1999:blog-178174920347765771.post-61624136684011297082011-09-23T03:40:23.429-07:002011-09-23T03:40:23.429-07:00First: thank you for putting together these articl...First: thank you for putting together these articles. I'm still working my way through them, but they've been very helpful so far. <br /><br />I think I'm misunderstanding something basic or that my process of reasoning about types is faulty, but I'm confused by the statement "flattening m is the same as flatMapping m with the identity function" and the reasoning anonymousnoreply@blogger.comtag:blogger.com,1999:blog-178174920347765771.post-79637702976962410102011-06-15T13:29:20.310-07:002011-06-15T13:29:20.310-07:00Nope. That would make the types wrong. The unit ...Nope. That would make the types wrong. The unit for Option is Some<br /><br />scala> def f(x : Int) : Option[String] = Some(x + "a")<br />f: (x: Int)Option[String]scala> Some(1) flatMap fres0: Option[java.lang.String] = Some(1a)scala> f(1)res1: Option[java.lang.String] = Some(1a)<br /><br />Compare with your alternative<br /><br />scala> Some(f(1))res2: Some[Option[James Iryhttp://james-iry.blogspot.comnoreply@blogger.comtag:blogger.com,1999:blog-178174920347765771.post-14260802343365187912011-06-15T12:19:40.388-07:002011-06-15T12:19:40.388-07:00You say unit(x) flatMap f ≡ f(x), but surely unit(...You say unit(x) flatMap f ≡ f(x), but surely unit(x) flatMap f === unit(f(x))Ben Jacksonhttp://ben.com/noreply@blogger.comtag:blogger.com,1999:blog-178174920347765771.post-87471061527328052672010-10-26T18:13:50.326-07:002010-10-26T18:13:50.326-07:00Actually, a mathematician would use the "trip...Actually, a mathematician would use the "triple equals" for the same purposes as you are.Bennoreply@blogger.comtag:blogger.com,1999:blog-178174920347765771.post-1550720466635277942010-09-23T13:52:14.159-07:002010-09-23T13:52:14.159-07:00I can't believe that because I was reading som...I can't believe that because I was reading some passages about a man called <a href="http://www.citratesildenafil.com/" rel="nofollow">Sildenafil</a> according to that he was a blind man and he could interpret that, so I don't really sure about that, Could you help me?Carlonoreply@blogger.comtag:blogger.com,1999:blog-178174920347765771.post-80683137420065682882008-02-19T11:22:00.000-08:002008-02-19T11:22:00.000-08:00James, Thanks! I've been trying to implement a May...James, <BR/><BR/>Thanks! I've been trying to implement a <A HREF="http://blog.pretheory.com/arch/2008/02/the_maybe_monad_in_ruby.php" REL="nofollow">Maybe monad in Ruby</A> and I've been struggling to understand the flatMap function (which I call pass). Your post (and your answer to my question) finally cleared it all up for me. Thanks a bunch.<BR/><BR/>BenAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-178174920347765771.post-40661473407907470662008-02-18T12:38:00.000-08:002008-02-18T12:38:00.000-08:00In Scala, as with other statically typed functiona...In Scala, as with other statically typed functional languages, functions have types. Both f and g must be functions of the right type for flatMap. If you have an instance of a monad with type M[A] then g must be of type A -> M[B]. In other words, it must take a value of type A as an argument and return a value of type M[B] as a return. Similarly, f must be of type B -> M[C].James Iryhttps://www.blogger.com/profile/02835376424060382389noreply@blogger.comtag:blogger.com,1999:blog-178174920347765771.post-71159280970431795782008-02-18T09:44:00.000-08:002008-02-18T09:44:00.000-08:00James,Great series of posts, but I'm still struggl...James,<BR/><BR/>Great series of posts, but I'm still struggling on understanding the third monad law. Specifically, if g(x) is any function (and therefore could return a non-monadic value), how can you call flatMap on it? <BR/><BR/>Or does g(x) have to return a monad itself? <BR/><BR/>Any help would be appreciated. Thanks!<BR/><BR/>BenAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-178174920347765771.post-27926345621111778492008-02-01T21:29:00.000-08:002008-02-01T21:29:00.000-08:00Good question. You certainly could create some re...Good question. You certainly could create some reusable tests that are parameterized with functions to be used in map or flatMap. You might also need to parameterize the function to use for equality, since it might not coincide with the definition of ==.James Iryhttps://www.blogger.com/profile/02835376424060382389noreply@blogger.comtag:blogger.com,1999:blog-178174920347765771.post-23548511417716719112008-02-01T05:28:00.000-08:002008-02-01T05:28:00.000-08:00Hey, thanks for the series. It appears that I'm fi...Hey, thanks for the series. It appears that I'm finally getting closer to having a clue about monads :b<BR/>By the way, is there some standard unit test to check whether a given class complies with all monad rules?Germánhttps://www.blogger.com/profile/07765922715981210093noreply@blogger.comtag:blogger.com,1999:blog-178174920347765771.post-28439478480814596382007-10-21T11:09:00.000-07:002007-10-21T11:09:00.000-07:00That's a damn spiffy idea! It's quite a challenge...That's a damn spiffy idea! It's quite a challenge though. Finite sets and mappings between them are pretty easy to do pictorially. To do the monad laws justice I need monads, functions, function composition, types, etc. I don't think it's impossible, though, so I might just give it a whirl at some point.James Iryhttps://www.blogger.com/profile/02835376424060382389noreply@blogger.comtag:blogger.com,1999:blog-178174920347765771.post-59856945765883920112007-10-20T15:51:00.000-07:002007-10-20T15:51:00.000-07:00Screw code samples. I want picuters! ;)It would be...Screw code samples. I want picuters! ;)<BR/><BR/>It would be great if you could come up with a way to illustrate how the different laws relate to eachother useing some kind of picures.<BR/><BR/>Something along the lines of this:<BR/>http://en.wikipedia.org/wiki/Bijection%2C_injection_and_surjectionAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-178174920347765771.post-62851854221122413262007-10-20T05:33:00.000-07:002007-10-20T05:33:00.000-07:00James: Okay, I'll hold on for the next episode and...James: Okay, I'll hold on for the next episode and we'll see if the bits fall into place :)Viktor Klanghttps://www.blogger.com/profile/03102746463606533061noreply@blogger.comtag:blogger.com,1999:blog-178174920347765771.post-23925709130163121512007-10-19T07:51:00.000-07:002007-10-19T07:51:00.000-07:00falcon, Thanks for the compliment. There are a bu...falcon, <BR/><BR/>Thanks for the compliment. There are a bunch of intros to Haskell monads out there. I think mine would get swallowed up :-)<BR/><BR/>viktor,<BR/><BR/>I really struggled with this one. I wanted code samples, but code samples based on Option and List would just reinforce the wrong take on monads. More interesting monads deserve articles of their own. So in the end I James Iryhttps://www.blogger.com/profile/02835376424060382389noreply@blogger.comtag:blogger.com,1999:blog-178174920347765771.post-20295379483833278862007-10-19T03:54:00.000-07:002007-10-19T03:54:00.000-07:00Sorry man, this third episode felt much lacking of...Sorry man, this third episode felt much lacking of actual examples of code.<BR/><BR/>I might be retarded, but I think that'd help me understand what to use it for....Viktor Klanghttps://www.blogger.com/profile/03102746463606533061noreply@blogger.comtag:blogger.com,1999:blog-178174920347765771.post-10384154457613143872007-10-18T22:30:00.000-07:002007-10-18T22:30:00.000-07:00Very nice series! If someone translates these art...Very nice series! If someone translates these articles into Haskell syntax, it will be even better :)falconhttps://www.blogger.com/profile/12277230403055479892noreply@blogger.com