ivan (2) [Avatar] Offline
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 (2) [Avatar] Offline

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

lbs being a list of Balances

That is.

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

Debasish Ghosh (111) [Avatar] Offline
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