tag:blogger.com,1999:blog-22587889.post571668361559998629..comments2024-02-11T13:21:47.930+05:30Comments on Ruminations of a Programmer: Domain Modeling in Haskell - Applicative Functors for Expressive Business RulesAnonymoushttp://www.blogger.com/profile/01613713587074301135noreply@blogger.comBlogger6125tag:blogger.com,1999:blog-22587889.post-51030997507275467212011-06-26T15:23:00.025+05:302011-06-26T15:23:00.025+05:30@Christopher: I would advise against your approach...@Christopher: I would advise against your approach. It is useful to observe that the fmap instance for ((->) r) is (.). On the other hand, you have shown the opposite: redefining (.) as fmap is not the same at all, and highly confusing.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-22587889.post-56653081342309509402010-11-03T01:40:18.407+05:302010-11-03T01:40:18.407+05:30Instead of all those references to 'alist'...Instead of all those references to 'alist', you could have defined 'lookup x = lookup1 x alist' in a where clause inside mkTrade. That would make it cleaner IMHO.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-22587889.post-88654860600069560432010-11-03T00:50:57.373+05:302010-11-03T00:50:57.373+05:30I like that ((->) r) is also a Functor instance...I like that ((->) r) is also a Functor instance, so we can<br />re-define (.) to be fmap and get function composition for<br />free. In GHCi:<br /><br />λ> let f . g = fmap f g<br />λ> :t (.)<br />(.) :: (Functor f) => (a -> b) -> f a -> f b<br /><br />The following works fine:<br /><br />λ> ((*4) . (+4)) . [1..5]<br />[20,24,28,32,36]<br /><br />So instead of,<br /><br />λ> ((1.1*)<$>) <$> [Just 5,Just 2]<br />[Just 5.5,Just 2.2]<br /><br />you can write<br /><br />λ> ((1.1*).) . [Just 5,Just 2]<br />[Just 5.5,Just 2.2]<br /><br />Pretty nice.Christopher Donehttps://www.blogger.com/profile/11058249597696527532noreply@blogger.comtag:blogger.com,1999:blog-22587889.post-49291576488810094592010-11-02T20:49:28.103+05:302010-11-02T20:49:28.103+05:30@Anonymous ..
((1.1*) <$> ) <$> (filt...@Anonymous ..<br /><br />((1.1*) <$> ) <$> (filter(\(x, _) -> x == TradeTax) rates)Anonymoushttps://www.blogger.com/profile/01613713587074301135noreply@blogger.comtag:blogger.com,1999:blog-22587889.post-80767783958653975632010-11-02T18:13:06.446+05:302010-11-02T18:13:06.446+05:30I'm not familiar with Applicatives...
I was wo...I'm not familiar with Applicatives...<br />I was wondering how one would write a variation of your example of increasing all rates by 10%:<br /><b>((1.1*) <$>) <$> rates</b><br />that would increase tax by 10%.<br /><br />SergioAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-22587889.post-45398726573295801352010-11-02T02:57:34.933+05:302010-11-02T02:57:34.933+05:30You forget telling readers that <$> is the o...You forget telling readers that <$> is the operator for infix fmap before <$> shows up.Ricardo Herrmannhttps://www.blogger.com/profile/02120395714813400613noreply@blogger.com