4 ms·
There is actually a third way to spot conflicts like this. The author is even aware of it - his first example is captured by the type system. Is it possible tha
by yummyfajitas 15y ago
There is actually a third way to spot conflicts like this. The author is even aware of it - his first example is captured by the type system. Is it possible that a stronger type system can solve more of these problems?
Let's imagine I'm looking at that calculateBill method and realize that as well as calculating the bill, it also sends off accounting entries to the accounting system. I don't like the side effect, so I pull it out into a separate notifyAccounting method.
Before:
calculateBill: BillEntries -> Writer (AccountingSystem) Bill
...Jed's code:...
produceBillEntries >>= calculateBill >>= billProcessor
After:
calculateBill: BillEntries -> Bill
notifyAccounting: BillEntries -> (Writer AccountingSystem) ()
...Jed's code:...
produceBillEntries >>= calculateBill >>= billProcessor
This yields a type error. calculateBill needs to have type a -> M b, instead it has type a -> b. If your type system can express concepts like "removed side effects" then the compiler will catch mistakes like "forgot to put the side effect back".