ivan (2) [Avatar] Offline
#1
First of all let me congratulate Debasish for this needed book.

I'm trying to understand the so-called explicit dictionary passing technique commented in listing 4.3 for passing appropiate Monoid[Money] instances to maxDebitOnDay and sumBalances but I can't figure out the magic.

I see that we implement a MoneyAdditionMonoid and a MoneyCompareMonoid in Monoid object but I don't understand how each call to maxDebitOnDay or sumBalances will get the correct one being the case that both monoids are in scope and implicit. The fact is that, once tested in the REPL, it works and I don't believe in black magic smilie

It would be nice if someone could elaborate more on this or just point to some resources in the web. The latter will be great also for the book, inside the "Scala Tip" paragraph.

Thank you very much in advance.
Ivan.
ivan (2) [Avatar] Offline
#2
Hello,

I came across a great paper from Mr. Odersky and Mr. Moors on Type Classes (http://ropas.snu.ac.kr/~bruno/papers/TypeClasses.pdf) that made me realize I was completely mistaken on this issue.

With both monoids implementation on scope, it seems that the REPL interpreter is choosing MoneyAdditionMoney for both maxDebitOnDay and sumBalances. So I understand that I need to pass explicitly the implicit argument so:

ltx being a list of Transactions
maxDebitOnday(ltx)(Monoid.MoneyCompareMonoid)

lbs being a list of Balances
sumBalances(lbs)(Monoid.MoneyAdditionMonoid)

That is.

Also it would be great to link the aforementioned paper into the "Scala tip" paragraph explaining listing 4.3

Best,
Ivan.
Debasish Ghosh (113) [Avatar] Offline
#3
Thanks for all the kind words. You are correct - it was an oversight, the monoids need to be passed explicitly. I will make the change and also include the Scala Tip as you suggested.

Thanks again for the correction ..
- Debasish