tag:blogger.com,1999:blog-8643857899806162280.post1482094554216608622..comments2024-02-25T06:15:55.318-03:00Comments on Bug squash: Refactoring to monadic C# - applicative functorsMauricio Schefferhttp://www.blogger.com/profile/15247972578064164206noreply@blogger.comBlogger6125tag:blogger.com,1999:blog-8643857899806162280.post-71439608217102815202012-06-14T08:45:36.384-03:002012-06-14T08:45:36.384-03:00@Gauthier, @Mauritio: About Func[M[Func[A,B]],M[A]...@Gauthier, @Mauritio: About Func[M[Func[A,B]],M[A],M[B]] being hard to imagine - you are right, and it is hard to do without a subtle hint from the original paper.<br /><br />Let's consider M[Func[A,B]]. What is the sense of this? Since most often we have a Func[A,B], and want to use that on M[A]. Why can't we just pass Func[A,B] to an applicative functor?<br /><br />The need arises when wanting to apply a multi-arg function, Func[A, B, C] to args M[A] and M[B].<br /><br />Curry Func[A,B,C] to Func[A, Func[B, C]], then what we would naively do is first apply M[A] for Func[A, Func[B, C]] (possibly through lifting the function with pure), yielding M[Func[B, C]]. Observe that this is exactly what we can do with a (normal) Functor!<br /><br />But now we have a M[Func[B, C]]. With a Functor, we would be stuck here. But with an Applicative, we can continue applying M[B] to this function, to finally get M[C].<br /><br />Bottom line: When you <b>use</b> an Applicative, you probably have a Func[A, B, ... C] and M[A], M[B] ... ars. But for the Applicative to <b>work</b> you need the apply signature to be as it is.Robinhttps://www.blogger.com/profile/08240995047820390813noreply@blogger.comtag:blogger.com,1999:blog-8643857899806162280.post-50129471413330112592011-08-19T23:05:03.000-03:002011-08-19T23:05:03.000-03:00Yeah, my day job keeps me out of hands-on engineer...Yeah, my day job keeps me out of hands-on engineering now, but I am definitely excited by FP. It just looks to me like FP is easier to follow and learn from in native languages like F#, rather than C#. Although LINQ does provide a helper asset within C#.jackfoxyhttps://www.blogger.com/profile/04700282308838786815noreply@blogger.comtag:blogger.com,1999:blog-8643857899806162280.post-59740867507758707882011-08-19T18:32:46.497-03:002011-08-19T18:32:46.497-03:00@jackfoxy no need to apologize... I used to think ...@jackfoxy no need to apologize... I used to think the same way until I started seeing the benefits of FP only a couple of years ago :)<br />This is just my two cents to help people realize that FP really is useful for everyday programming tasks.Mauricio Schefferhttps://www.blogger.com/profile/15247972578064164206noreply@blogger.comtag:blogger.com,1999:blog-8643857899806162280.post-91911732228045616102011-08-19T12:17:39.378-03:002011-08-19T12:17:39.378-03:00Sorry about the choice of "academic" in ...Sorry about the choice of "academic" in a previous question. It only made my question obtuse. I always look forward to your new posts.jackfoxyhttps://www.blogger.com/profile/04700282308838786815noreply@blogger.comtag:blogger.com,1999:blog-8643857899806162280.post-22015863436998803672011-08-18T16:33:13.667-03:002011-08-18T16:33:13.667-03:00@Gauthier: thanks for your comments. With this ser...@Gauthier: thanks for your comments. With this series of posts I intentionally wanted to show things with real-world examples first, and explaining as little as possible. So yeah, there will be holes. But I think most people see functional programming as an academic curiosity that only math and financial people use but has no application beyond that. And that's what I intend to disprove :)<br />The "wrap into nullable integer" analogy is accurate. <br />As for the signature of <i>apply</i>... well, function signatures don't really look very intuitive in C#. They're much more readable in ML languages like F#. But I'll post more resources to learn about applicative functors in the next post.Mauricio Schefferhttps://www.blogger.com/profile/15247972578064164206noreply@blogger.comtag:blogger.com,1999:blog-8643857899806162280.post-67190722417286319462011-08-18T11:26:51.175-03:002011-08-18T11:26:51.175-03:00Thanks, with this serie I start to grasp few thing...Thanks, with this serie I start to grasp few things better.<br /><br />The definitions you give about applicative functors sound important, but it goes beyond understanding without examples.<br /><br />Func[T, M[T]] I grasp it could be "wrap an integer into a nullable integer" kind of thing, but Func[M[Func[A,B]],M[A],M[B]] goes away from my current abilities to grasp what's the concept there.<br /><br />"on 1 equals 1" I happen to use that (rarely) in sql, I don't like from clause with , (comma) in it.Gauthier Segaynoreply@blogger.com